motion-markdown-it-plugins 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +18 -0
- data/lib/motion-markdown-it-plugins.rb +24 -0
- data/lib/motion-markdown-it-plugins/abbr/abbr.rb +130 -0
- data/lib/motion-markdown-it-plugins/checkbox_replace/checkbox_replace.rb +103 -0
- data/lib/motion-markdown-it-plugins/container/container.rb +154 -0
- data/lib/motion-markdown-it-plugins/deflist/deflist.rb +185 -0
- data/lib/motion-markdown-it-plugins/ins/ins.rb +136 -0
- data/lib/motion-markdown-it-plugins/mark/mark.rb +136 -0
- data/lib/motion-markdown-it-plugins/sub/sub.rb +70 -0
- data/lib/motion-markdown-it-plugins/sup/sup.rb +71 -0
- data/lib/motion-markdown-it-plugins/version.rb +5 -0
- data/spec/abbr/abbr_spec.rb +8 -0
- data/spec/checkbox_replace/checkbox_replace_spec.rb +64 -0
- data/spec/container/api_spec.rb +76 -0
- data/spec/container/default_spec.rb +8 -0
- data/spec/container/misc_spec.rb +17 -0
- data/spec/deflist/deflist_spec.rb +9 -0
- data/spec/ins/ins_spec.rb +9 -0
- data/spec/mark/mark_spec.rb +9 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/sub/sub_spec.rb +9 -0
- data/spec/sup/sup_spec.rb +9 -0
- data/spec/testgen_helper.rb +80 -0
- metadata +92 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
#------------------------------------------------------------------------------
|
2
|
+
describe 'api' do
|
3
|
+
|
4
|
+
#------------------------------------------------------------------------------
|
5
|
+
it 'renderer' do
|
6
|
+
md = MarkdownIt::Parser.new
|
7
|
+
md.use(MotionMarkdownItPlugins::Container, 'spoiler',
|
8
|
+
{ render: lambda {|tokens, idx, _options, env, renderer|
|
9
|
+
tokens[idx].nesting == 1 ? "<details><summary>click me</summary>\n" : "</details>\n" }})
|
10
|
+
res = md.render("::: spoiler\n*content*\n:::\n")
|
11
|
+
expect(res).to eq "<details><summary>click me</summary>\n<p><em>content</em></p>\n</details>\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
#------------------------------------------------------------------------------
|
15
|
+
it '2 char marker' do
|
16
|
+
md = MarkdownIt::Parser.new
|
17
|
+
md.use(MotionMarkdownItPlugins::Container, 'spoiler', {marker: '->'})
|
18
|
+
res = md.render("->->-> spoiler\n*content*\n->->->\n")
|
19
|
+
expect(res).to eq "<div class=\"spoiler\">\n<p><em>content</em></p>\n</div>\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
#------------------------------------------------------------------------------
|
23
|
+
it 'marker should not collide with fence' do
|
24
|
+
md = MarkdownIt::Parser.new
|
25
|
+
md.use(MotionMarkdownItPlugins::Container, 'spoiler', {marker: '`'})
|
26
|
+
res = md.render("``` spoiler\n*content*\n```\n")
|
27
|
+
expect(res).to eq "<div class=\"spoiler\">\n<p><em>content</em></p>\n</div>\n"
|
28
|
+
end
|
29
|
+
|
30
|
+
#------------------------------------------------------------------------------
|
31
|
+
it 'marker should not collide with fence #2' do
|
32
|
+
md = MarkdownIt::Parser.new
|
33
|
+
md.use(MotionMarkdownItPlugins::Container, 'spoiler', {marker: '`'})
|
34
|
+
res = md.render("\n``` not spoiler\n*content*\n```\n")
|
35
|
+
expect(res).to eq "<pre><code class=\"language-not\">*content*\n</code></pre>\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
#------------------------------------------------------------------------------
|
39
|
+
describe 'validator' do
|
40
|
+
|
41
|
+
#------------------------------------------------------------------------------
|
42
|
+
it 'should skip rule if return value is falsy' do
|
43
|
+
md = MarkdownIt::Parser.new
|
44
|
+
md.use(MotionMarkdownItPlugins::Container, 'name', {validate: lambda {|params| false} })
|
45
|
+
res = md.render(":::foo\nbar\n:::\n")
|
46
|
+
expect(res).to eq "<p>:::foo\nbar\n:::</p>\n"
|
47
|
+
end
|
48
|
+
|
49
|
+
#------------------------------------------------------------------------------
|
50
|
+
it 'should accept rule if return value is true' do
|
51
|
+
md = MarkdownIt::Parser.new
|
52
|
+
md.use(MotionMarkdownItPlugins::Container, 'name', {validate: lambda {|params| true} })
|
53
|
+
res = md.render(":::foo\nbar\n:::\n")
|
54
|
+
expect(res).to eq "<div class=\"name\">\n<p>bar</p>\n</div>\n"
|
55
|
+
end
|
56
|
+
|
57
|
+
#------------------------------------------------------------------------------
|
58
|
+
it 'rule should call it' do
|
59
|
+
count = 0
|
60
|
+
|
61
|
+
md = MarkdownIt::Parser.new
|
62
|
+
md.use(MotionMarkdownItPlugins::Container, 'name', {validate: lambda {|params| count += 1} })
|
63
|
+
md.parse(":\n::\n:::\n::::\n:::::\n", {})
|
64
|
+
expect(count).to eq 3
|
65
|
+
end
|
66
|
+
|
67
|
+
#------------------------------------------------------------------------------
|
68
|
+
it 'should not trim params' do
|
69
|
+
md = MarkdownIt::Parser.new
|
70
|
+
md.use(MotionMarkdownItPlugins::Container, 'name',
|
71
|
+
{validate: lambda {|params| expect(params).to eq ' name '; return 1 } })
|
72
|
+
md.parse("::: \tname \ncontent\n:::\n", {})
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
fixture_dir = fixture_path('container/fixtures')
|
2
|
+
|
3
|
+
#------------------------------------------------------------------------------
|
4
|
+
describe 'default container' do
|
5
|
+
md = MarkdownIt::Parser.new
|
6
|
+
md.use(MotionMarkdownItPlugins::Container, 'name')
|
7
|
+
generate(File.join(fixture_dir, 'default.txt'), md)
|
8
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#------------------------------------------------------------------------------
|
2
|
+
describe 'coverage' do
|
3
|
+
|
4
|
+
#------------------------------------------------------------------------------
|
5
|
+
it 'marker coverage' do
|
6
|
+
md = MarkdownIt::Parser.new
|
7
|
+
md.use(MotionMarkdownItPlugins::Container, 'fox',
|
8
|
+
{ marker: 'foo',
|
9
|
+
validate: lambda {|params| expect(params).to eq 'fox'; return 1}
|
10
|
+
})
|
11
|
+
tok = md.parse("foofoofoofox\ncontent\nfoofoofoofoo\n", {})
|
12
|
+
|
13
|
+
expect(tok[0].markup).to eq 'foofoofoo'
|
14
|
+
expect(tok[0].info).to eq 'fox'
|
15
|
+
expect(tok[4].markup).to eq 'foofoofoofoo'
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
fixture_dir = fixture_path('deflist/fixtures')
|
2
|
+
|
3
|
+
#------------------------------------------------------------------------------
|
4
|
+
describe 'markdown-it-deflist' do
|
5
|
+
md = MarkdownIt::Parser.new
|
6
|
+
md.use(MotionMarkdownItPlugins::Deflist)
|
7
|
+
|
8
|
+
generate(File.join(fixture_dir, 'deflist.txt'), md)
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
fixture_dir = fixture_path('ins/fixtures')
|
2
|
+
|
3
|
+
#------------------------------------------------------------------------------
|
4
|
+
describe 'markdown-it-ins' do
|
5
|
+
md = MarkdownIt::Parser.new
|
6
|
+
md.use(MotionMarkdownItPlugins::Ins)
|
7
|
+
|
8
|
+
generate(File.join(fixture_dir, 'ins.txt'), md)
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
fixture_dir = fixture_path('mark/fixtures')
|
2
|
+
|
3
|
+
#------------------------------------------------------------------------------
|
4
|
+
describe 'markdown-it-mark' do
|
5
|
+
md = MarkdownIt::Parser.new
|
6
|
+
md.use(MotionMarkdownItPlugins::Mark)
|
7
|
+
|
8
|
+
generate(File.join(fixture_dir, 'mark.txt'), md)
|
9
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
fixture_dir = fixture_path('sub/fixtures')
|
2
|
+
|
3
|
+
#------------------------------------------------------------------------------
|
4
|
+
describe 'markdown-it-sub' do
|
5
|
+
md = MarkdownIt::Parser.new
|
6
|
+
md.use(MotionMarkdownItPlugins::Sub)
|
7
|
+
|
8
|
+
generate(File.join(fixture_dir, 'sub.txt'), md)
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
fixture_dir = fixture_path('sup/fixtures')
|
2
|
+
|
3
|
+
#------------------------------------------------------------------------------
|
4
|
+
describe 'markdown-it-sup' do
|
5
|
+
md = MarkdownIt::Parser.new
|
6
|
+
md.use(MotionMarkdownItPlugins::Sup)
|
7
|
+
|
8
|
+
generate(File.join(fixture_dir, 'sup.txt'), md)
|
9
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#------------------------------------------------------------------------------
|
2
|
+
def fixture_path(relative_path)
|
3
|
+
main_spec_dir = File.dirname(__FILE__)
|
4
|
+
fixture_dir = File.join(main_spec_dir, relative_path)
|
5
|
+
end
|
6
|
+
|
7
|
+
#------------------------------------------------------------------------------
|
8
|
+
def generate(datafile, parser)
|
9
|
+
tests = get_tests(datafile)
|
10
|
+
|
11
|
+
if ENV['example']
|
12
|
+
define_test(tests[ENV['example'].to_i - 1], parser, true)
|
13
|
+
else
|
14
|
+
tests.each do |t|
|
15
|
+
define_test(t, parser)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
#------------------------------------------------------------------------------
|
21
|
+
def get_tests(specfile)
|
22
|
+
line_number = 0
|
23
|
+
start_line = 0
|
24
|
+
end_line = 0
|
25
|
+
example_number = 0
|
26
|
+
markdown_lines = []
|
27
|
+
html_lines = []
|
28
|
+
state = 0 # 0 regular text, 1 markdown example, 2 html output
|
29
|
+
headertext = ''
|
30
|
+
tests = []
|
31
|
+
header_re = /#+ /
|
32
|
+
filename = File.basename(specfile)
|
33
|
+
|
34
|
+
File.open(specfile) do |specf|
|
35
|
+
specf.each_line do |line|
|
36
|
+
line_number += 1
|
37
|
+
if state == 0 && header_re =~ line
|
38
|
+
headertext = line.gsub(header_re, '').strip
|
39
|
+
end
|
40
|
+
if line.strip == "."
|
41
|
+
state = (state + 1) % 3
|
42
|
+
if state == 0
|
43
|
+
example_number += 1
|
44
|
+
end_line = line_number
|
45
|
+
tests << {
|
46
|
+
markdown: markdown_lines.join.gsub('→',"\t"),
|
47
|
+
html: html_lines.join,
|
48
|
+
example: example_number,
|
49
|
+
start_line: start_line,
|
50
|
+
end_line: end_line,
|
51
|
+
section: headertext,
|
52
|
+
filename: filename}
|
53
|
+
start_line = 0
|
54
|
+
markdown_lines = []
|
55
|
+
html_lines = []
|
56
|
+
end
|
57
|
+
elsif state == 1
|
58
|
+
if start_line == 0
|
59
|
+
start_line = line_number - 1
|
60
|
+
end
|
61
|
+
markdown_lines << line
|
62
|
+
elsif state == 2
|
63
|
+
html_lines << line
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
return tests
|
68
|
+
end
|
69
|
+
|
70
|
+
#------------------------------------------------------------------------------
|
71
|
+
def define_test(testcase, parser, debug_tokens = false)
|
72
|
+
|
73
|
+
it "#{testcase[:filename]} #{testcase[:section]} (#{testcase[:example].to_s}/#{testcase[:start_line]}-#{testcase[:end_line]}) with markdown:\n#{testcase[:markdown]}" do
|
74
|
+
if debug_tokens
|
75
|
+
parser.parse(testcase[:markdown], { references: {} }).each {|token| pp token.to_json}
|
76
|
+
end
|
77
|
+
expect(parser.render(testcase[:markdown])).to eq testcase[:html]
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-markdown-it-plugins
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brett Walker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: motion-markdown-it
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
description: Plugins for use with motion-markdown-it
|
28
|
+
email: github@digitalmoksha.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- README.md
|
34
|
+
- lib/motion-markdown-it-plugins.rb
|
35
|
+
- lib/motion-markdown-it-plugins/abbr/abbr.rb
|
36
|
+
- lib/motion-markdown-it-plugins/checkbox_replace/checkbox_replace.rb
|
37
|
+
- lib/motion-markdown-it-plugins/container/container.rb
|
38
|
+
- lib/motion-markdown-it-plugins/deflist/deflist.rb
|
39
|
+
- lib/motion-markdown-it-plugins/ins/ins.rb
|
40
|
+
- lib/motion-markdown-it-plugins/mark/mark.rb
|
41
|
+
- lib/motion-markdown-it-plugins/sub/sub.rb
|
42
|
+
- lib/motion-markdown-it-plugins/sup/sup.rb
|
43
|
+
- lib/motion-markdown-it-plugins/version.rb
|
44
|
+
- spec/abbr/abbr_spec.rb
|
45
|
+
- spec/checkbox_replace/checkbox_replace_spec.rb
|
46
|
+
- spec/container/api_spec.rb
|
47
|
+
- spec/container/default_spec.rb
|
48
|
+
- spec/container/misc_spec.rb
|
49
|
+
- spec/deflist/deflist_spec.rb
|
50
|
+
- spec/ins/ins_spec.rb
|
51
|
+
- spec/mark/mark_spec.rb
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
- spec/sub/sub_spec.rb
|
54
|
+
- spec/sup/sup_spec.rb
|
55
|
+
- spec/testgen_helper.rb
|
56
|
+
homepage: https://github.com/digitalmoksha/motion-markdown-it-plugins
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.4.5
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Plugins for motion-markdown-it
|
80
|
+
test_files:
|
81
|
+
- spec/abbr/abbr_spec.rb
|
82
|
+
- spec/checkbox_replace/checkbox_replace_spec.rb
|
83
|
+
- spec/container/api_spec.rb
|
84
|
+
- spec/container/default_spec.rb
|
85
|
+
- spec/container/misc_spec.rb
|
86
|
+
- spec/deflist/deflist_spec.rb
|
87
|
+
- spec/ins/ins_spec.rb
|
88
|
+
- spec/mark/mark_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- spec/sub/sub_spec.rb
|
91
|
+
- spec/sup/sup_spec.rb
|
92
|
+
- spec/testgen_helper.rb
|