motion-markdown-it 0.4.0.3.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 +243 -0
- data/lib/motion-markdown-it.rb +71 -0
- data/lib/motion-markdown-it/common/entities.rb +1084 -0
- data/lib/motion-markdown-it/common/html_blocks.rb +60 -0
- data/lib/motion-markdown-it/common/html_re.rb +28 -0
- data/lib/motion-markdown-it/common/string.rb +14 -0
- data/lib/motion-markdown-it/common/url_schemas.rb +173 -0
- data/lib/motion-markdown-it/common/utils.rb +216 -0
- data/lib/motion-markdown-it/helpers/parse_link_destination.rb +75 -0
- data/lib/motion-markdown-it/helpers/parse_link_label.rb +51 -0
- data/lib/motion-markdown-it/helpers/parse_link_title.rb +48 -0
- data/lib/motion-markdown-it/index.rb +507 -0
- data/lib/motion-markdown-it/parser_block.rb +113 -0
- data/lib/motion-markdown-it/parser_core.rb +46 -0
- data/lib/motion-markdown-it/parser_inline.rb +121 -0
- data/lib/motion-markdown-it/presets/commonmark.rb +76 -0
- data/lib/motion-markdown-it/presets/default.rb +42 -0
- data/lib/motion-markdown-it/presets/zero.rb +59 -0
- data/lib/motion-markdown-it/renderer.rb +286 -0
- data/lib/motion-markdown-it/ruler.rb +327 -0
- data/lib/motion-markdown-it/rules_block/blockquote.rb +138 -0
- data/lib/motion-markdown-it/rules_block/code.rb +35 -0
- data/lib/motion-markdown-it/rules_block/fence.rb +94 -0
- data/lib/motion-markdown-it/rules_block/heading.rb +56 -0
- data/lib/motion-markdown-it/rules_block/hr.rb +45 -0
- data/lib/motion-markdown-it/rules_block/html_block.rb +73 -0
- data/lib/motion-markdown-it/rules_block/lheading.rb +54 -0
- data/lib/motion-markdown-it/rules_block/list.rb +242 -0
- data/lib/motion-markdown-it/rules_block/paragraph.rb +51 -0
- data/lib/motion-markdown-it/rules_block/reference.rb +161 -0
- data/lib/motion-markdown-it/rules_block/state_block.rb +184 -0
- data/lib/motion-markdown-it/rules_block/table.rb +161 -0
- data/lib/motion-markdown-it/rules_core/block.rb +20 -0
- data/lib/motion-markdown-it/rules_core/inline.rb +20 -0
- data/lib/motion-markdown-it/rules_core/linkify.rb +138 -0
- data/lib/motion-markdown-it/rules_core/normalize.rb +44 -0
- data/lib/motion-markdown-it/rules_core/replacements.rb +90 -0
- data/lib/motion-markdown-it/rules_core/smartquotes.rb +158 -0
- data/lib/motion-markdown-it/rules_core/state_core.rb +20 -0
- data/lib/motion-markdown-it/rules_inline/autolink.rb +74 -0
- data/lib/motion-markdown-it/rules_inline/backticks.rb +51 -0
- data/lib/motion-markdown-it/rules_inline/emphasis.rb +172 -0
- data/lib/motion-markdown-it/rules_inline/entity.rb +51 -0
- data/lib/motion-markdown-it/rules_inline/escape.rb +55 -0
- data/lib/motion-markdown-it/rules_inline/html_inline.rb +49 -0
- data/lib/motion-markdown-it/rules_inline/image.rb +158 -0
- data/lib/motion-markdown-it/rules_inline/link.rb +153 -0
- data/lib/motion-markdown-it/rules_inline/newline.rb +47 -0
- data/lib/motion-markdown-it/rules_inline/state_inline.rb +57 -0
- data/lib/motion-markdown-it/rules_inline/strikethrough.rb +130 -0
- data/lib/motion-markdown-it/rules_inline/text.rb +94 -0
- data/lib/motion-markdown-it/token.rb +134 -0
- data/lib/motion-markdown-it/version.rb +5 -0
- data/spec/motion-markdown-it/bench_mark_spec.rb +44 -0
- data/spec/motion-markdown-it/commonmark_spec.rb +16 -0
- data/spec/motion-markdown-it/markdown_it_spec.rb +18 -0
- data/spec/motion-markdown-it/misc_spec.rb +277 -0
- data/spec/motion-markdown-it/ruler_spec.rb +153 -0
- data/spec/motion-markdown-it/testgen_helper.rb +68 -0
- data/spec/motion-markdown-it/token_spec.rb +17 -0
- data/spec/motion-markdown-it/utils_spec.rb +82 -0
- data/spec/spec_helper.rb +6 -0
- metadata +158 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
=begin
|
2
|
+
runs = 1 #50
|
3
|
+
files = ['mdsyntax.text', 'mdbasics.text']
|
4
|
+
benchmark_dir = File.join(File.dirname(__FILE__), '../../benchmark')
|
5
|
+
|
6
|
+
puts
|
7
|
+
puts "Running tests on #{Time.now.strftime("%Y-%m-%d")} under #{RUBY_DESCRIPTION}"
|
8
|
+
|
9
|
+
files.each do |file|
|
10
|
+
data = File.read(File.join(benchmark_dir, file))
|
11
|
+
puts
|
12
|
+
puts "==> Test using file #{file} and #{runs} runs"
|
13
|
+
|
14
|
+
# results = Benchmark.bmbm do |b|
|
15
|
+
results = Benchmark.bm do |b|
|
16
|
+
b.report("motion-markdown-it 0.1.0") do
|
17
|
+
parser = MarkdownIt::Parser.new(:commonmark, { html: false })
|
18
|
+
runs.times { parser.render(data) }
|
19
|
+
end
|
20
|
+
# b.report("kramdown #{Kramdown::VERSION}") { runs.times { Kramdown::Document.new(data).to_html } }
|
21
|
+
# b.report("markdown-it 4.0.1 JS") { runs.times { NSApplication.sharedApplication.delegate.markdown_it(data) } }
|
22
|
+
# b.report(" hoedown 3.0.1") do
|
23
|
+
# runs.times do
|
24
|
+
# document = HoedownDocument.new
|
25
|
+
# document.initWithHtmlRendererWithFlags(FLAGS)
|
26
|
+
# html = document.renderMarkdownString(data)
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
end
|
30
|
+
|
31
|
+
# puts
|
32
|
+
# puts "Real time of X divided by real time of kramdown"
|
33
|
+
# kd = results.shift.real
|
34
|
+
# %w[hoedown].each do |name|
|
35
|
+
# puts name.ljust(19) << (results.shift.real/kd).round(4).to_s
|
36
|
+
# end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "Benchmark Test" do
|
40
|
+
it "benchmarks with mdsyntax.text and mdbasics.text" do
|
41
|
+
expect(true).to eq true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
=end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#------------------------------------------------------------------------------
|
2
|
+
describe "CommonMark Specs" do
|
3
|
+
|
4
|
+
parser = MarkdownIt::Parser.new(:commonmark)
|
5
|
+
specfile = File.join(File.dirname(__FILE__), 'fixtures', 'commonmark', 'good.txt')
|
6
|
+
tests = get_tests(specfile)
|
7
|
+
|
8
|
+
if ENV['example']
|
9
|
+
define_test(tests[ENV['example'].to_i - 1], parser, true)
|
10
|
+
else
|
11
|
+
tests.each do |t|
|
12
|
+
define_test(t, parser)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#------------------------------------------------------------------------------
|
2
|
+
describe "markdown-it" do
|
3
|
+
|
4
|
+
parser = MarkdownIt::Parser.new({ html: true, langPrefix: '', typographer: true, linkify: true })
|
5
|
+
datadir = File.join(File.dirname(__FILE__), 'fixtures', 'markdown-it')
|
6
|
+
datafiles = (ENV['datafile'] ? [ File.join(datadir, ENV['datafile']) ] : Dir[File.join(datadir, '**/*')])
|
7
|
+
|
8
|
+
datafiles.each do |data_file|
|
9
|
+
tests = get_tests(data_file)
|
10
|
+
if ENV['example'] && !tests[ENV['example'].to_i - 1].nil?
|
11
|
+
define_test(tests[ENV['example'].to_i - 1], parser, true)
|
12
|
+
else
|
13
|
+
tests.each do |t|
|
14
|
+
define_test(t, parser)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,277 @@
|
|
1
|
+
describe 'API' do
|
2
|
+
|
3
|
+
#------------------------------------------------------------------------------
|
4
|
+
it 'constructor' do
|
5
|
+
expect {
|
6
|
+
MarkdownIt::Parser.new('bad preset')
|
7
|
+
}.to raise_error
|
8
|
+
|
9
|
+
# options should override preset
|
10
|
+
md = MarkdownIt::Parser.new(:commonmark, { html: false })
|
11
|
+
expect(md).not_to eq nil
|
12
|
+
expect(md.render('one')).to eq "<p>one</p>\n"
|
13
|
+
expect(md.render('<!-- -->')).to eq "<p><!-- --></p>\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
#------------------------------------------------------------------------------
|
17
|
+
it 'configure coverage' do
|
18
|
+
md = MarkdownIt::Parser.new
|
19
|
+
|
20
|
+
# conditions coverage
|
21
|
+
md.configure({})
|
22
|
+
expect(md.render('123')).to eq "<p>123</p>\n"
|
23
|
+
|
24
|
+
expect {
|
25
|
+
md.configure
|
26
|
+
}.to raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
# TODO #------------------------------------------------------------------------------
|
30
|
+
# it 'plugin' do
|
31
|
+
# plugin[0] = false
|
32
|
+
#
|
33
|
+
# plugin[1] = lambda {|plugin, opts| plugin[0] = true if (opts == 'bar') }
|
34
|
+
#
|
35
|
+
# md = MarkdownIt::Parser.new
|
36
|
+
#
|
37
|
+
# md.use(plugin, 'foo');
|
38
|
+
# expect(@succeeded).to eq false
|
39
|
+
# md.use(plugin, 'bar')
|
40
|
+
# expect(@succeeded).to eq true
|
41
|
+
# end
|
42
|
+
|
43
|
+
# it('highlight', function () {
|
44
|
+
# var md = markdownit({
|
45
|
+
# highlight: function (str) {
|
46
|
+
# return '==' + str + '==';
|
47
|
+
# }
|
48
|
+
# });
|
49
|
+
#
|
50
|
+
# assert.strictEqual(md.render("```\nhl\n```"), "<pre><code>==hl\n==</code></pre>\n");
|
51
|
+
# });
|
52
|
+
#
|
53
|
+
# it('highlight escape by default', function () {
|
54
|
+
# var md = markdownit({
|
55
|
+
# highlight: function () {
|
56
|
+
# return '';
|
57
|
+
# }
|
58
|
+
# });
|
59
|
+
#
|
60
|
+
# assert.strictEqual(md.render("```\n&\n```"), "<pre><code>&\n</code></pre>\n");
|
61
|
+
# });
|
62
|
+
|
63
|
+
it 'force hardbreaks' do
|
64
|
+
md = MarkdownIt::Parser.new({ breaks: false })
|
65
|
+
expect(md.render("a\nb")).to eq "<p>a\nb</p>\n"
|
66
|
+
|
67
|
+
md.set({ breaks: true })
|
68
|
+
expect(md.render("a\nb")).to eq "<p>a<br>\nb</p>\n"
|
69
|
+
md.set({ xhtmlOut: true })
|
70
|
+
expect(md.render("a\nb")).to eq "<p>a<br />\nb</p>\n"
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'xhtmlOut enabled' do
|
74
|
+
md = MarkdownIt::Parser.new({ xhtmlOut: true })
|
75
|
+
|
76
|
+
expect(md.render('---')).to eq "<hr />\n"
|
77
|
+
# TODO expect(md.render('![]()')).to eq "<p><img src=\"\" alt=\"\" /></p>\n"
|
78
|
+
expect(md.render("a \\\nb")).to eq "<p>a <br />\nb</p>\n"
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'xhtmlOut disabled' do
|
82
|
+
md = MarkdownIt::Parser.new
|
83
|
+
|
84
|
+
expect(md.render('---')).to eq "<hr>\n"
|
85
|
+
# TODO expect(md.render('![]()')).to eq "<p><img src=\"\" alt=\"\"></p>\n"
|
86
|
+
expect(md.render("a \\\nb")).to eq "<p>a <br>\nb</p>\n"
|
87
|
+
end
|
88
|
+
|
89
|
+
# it('bulk enable/disable rules in different chains', function () {
|
90
|
+
# var md = markdownit();
|
91
|
+
#
|
92
|
+
# var was = {
|
93
|
+
# core: md.core.ruler.getRules('').length,
|
94
|
+
# block: md.block.ruler.getRules('').length,
|
95
|
+
# inline: md.inline.ruler.getRules('').length
|
96
|
+
# };
|
97
|
+
#
|
98
|
+
# // Disable 2 rule in each chain & compare result
|
99
|
+
# md.disable([ 'block', 'inline', 'code', 'fence', 'emphasis', 'entity' ]);
|
100
|
+
#
|
101
|
+
# var now = {
|
102
|
+
# core: md.core.ruler.getRules('').length + 2,
|
103
|
+
# block: md.block.ruler.getRules('').length + 2,
|
104
|
+
# inline: md.inline.ruler.getRules('').length + 2
|
105
|
+
# };
|
106
|
+
#
|
107
|
+
# assert.deepEqual(was, now);
|
108
|
+
#
|
109
|
+
# // Enable the same rules back
|
110
|
+
# md.enable([ 'block', 'inline', 'code', 'fence', 'emphasis', 'entity' ]);
|
111
|
+
#
|
112
|
+
# var back = {
|
113
|
+
# core: md.core.ruler.getRules('').length,
|
114
|
+
# block: md.block.ruler.getRules('').length,
|
115
|
+
# inline: md.inline.ruler.getRules('').length
|
116
|
+
# };
|
117
|
+
#
|
118
|
+
# assert.deepEqual(was, back);
|
119
|
+
# });
|
120
|
+
#
|
121
|
+
# it('bulk enable/disable with errors control', function () {
|
122
|
+
# var md = markdownit();
|
123
|
+
#
|
124
|
+
# assert.throws(function () {
|
125
|
+
# md.enable([ 'link', 'code', 'invalid' ]);
|
126
|
+
# });
|
127
|
+
# assert.throws(function () {
|
128
|
+
# md.disable([ 'link', 'code', 'invalid' ]);
|
129
|
+
# });
|
130
|
+
# assert.doesNotThrow(function () {
|
131
|
+
# md.enable([ 'link', 'code' ]);
|
132
|
+
# });
|
133
|
+
# assert.doesNotThrow(function () {
|
134
|
+
# md.disable([ 'link', 'code' ]);
|
135
|
+
# });
|
136
|
+
# });
|
137
|
+
#
|
138
|
+
# it('bulk enable/disable should understand strings', function () {
|
139
|
+
# var md = markdownit();
|
140
|
+
#
|
141
|
+
# md.disable('emphasis');
|
142
|
+
# assert(md.renderInline('_foo_'), '_foo_');
|
143
|
+
#
|
144
|
+
# md.enable('emphasis');
|
145
|
+
# assert(md.renderInline('_foo_'), '<em>foo</em>');
|
146
|
+
# });
|
147
|
+
#
|
148
|
+
# });
|
149
|
+
#
|
150
|
+
#
|
151
|
+
# describe('Misc', function () {
|
152
|
+
#
|
153
|
+
# it('Should replace NULL characters', function () {
|
154
|
+
# var md = markdownit();
|
155
|
+
#
|
156
|
+
# assert.strictEqual(md.render('foo\u0000bar'), '<p>foo\uFFFDbar</p>\n');
|
157
|
+
# });
|
158
|
+
#
|
159
|
+
# it('Should correctly parse strings without tailing \\n', function () {
|
160
|
+
# var md = markdownit();
|
161
|
+
#
|
162
|
+
# assert.strictEqual(md.render('123'), '<p>123</p>\n');
|
163
|
+
# assert.strictEqual(md.render('123\n'), '<p>123</p>\n');
|
164
|
+
# });
|
165
|
+
#
|
166
|
+
# it('Should quickly exit on empty string', function () {
|
167
|
+
# var md = markdownit();
|
168
|
+
#
|
169
|
+
# assert.strictEqual(md.render(''), '');
|
170
|
+
# });
|
171
|
+
#
|
172
|
+
# it('Should parse inlines only', function () {
|
173
|
+
# var md = markdownit();
|
174
|
+
#
|
175
|
+
# assert.strictEqual(md.renderInline('a *b* c'), 'a <em>b</em> c');
|
176
|
+
# });
|
177
|
+
#
|
178
|
+
# it('Renderer should have pluggable inline and block rules', function () {
|
179
|
+
# var md = markdownit();
|
180
|
+
#
|
181
|
+
# md.renderer.rules.em_open = function () { return '<it>'; };
|
182
|
+
# md.renderer.rules.em_close = function () { return '</it>'; };
|
183
|
+
# md.renderer.rules.paragraph_open = function () { return '<par>'; };
|
184
|
+
# md.renderer.rules.paragraph_close = function () { return '</par>'; };
|
185
|
+
#
|
186
|
+
# assert.strictEqual(md.render('*b*'), '<par><it>b</it></par>');
|
187
|
+
# });
|
188
|
+
#
|
189
|
+
# it('Zero preset should disable everything', function () {
|
190
|
+
# var md = markdownit('zero');
|
191
|
+
#
|
192
|
+
# assert.strictEqual(md.render('___foo___'), '<p>___foo___</p>\n');
|
193
|
+
# assert.strictEqual(md.renderInline('___foo___'), '___foo___');
|
194
|
+
#
|
195
|
+
# md.enable('emphasis');
|
196
|
+
#
|
197
|
+
# assert.strictEqual(md.render('___foo___'), '<p><strong><em>foo</em></strong></p>\n');
|
198
|
+
# assert.strictEqual(md.renderInline('___foo___'), '<strong><em>foo</em></strong>');
|
199
|
+
# });
|
200
|
+
#
|
201
|
+
# it('Should correctly check block termination rules when those are disabled (#13)', function () {
|
202
|
+
# var md = markdownit('zero');
|
203
|
+
#
|
204
|
+
# assert.strictEqual(md.render('foo\nbar'), '<p>foo\nbar</p>\n');
|
205
|
+
# });
|
206
|
+
#
|
207
|
+
# it('Should render link target attr', function () {
|
208
|
+
# var md = markdownit()
|
209
|
+
# .use(require('markdown-it-for-inline'), 'target', 'link_open', function (tokens, idx) {
|
210
|
+
# tokens[idx].attrs.push([ 'target', '_blank' ]);
|
211
|
+
# });
|
212
|
+
#
|
213
|
+
# assert.strictEqual(md.render('[foo](bar)'), '<p><a href="bar" target="_blank">foo</a></p>\n');
|
214
|
+
# });
|
215
|
+
#
|
216
|
+
# });
|
217
|
+
#
|
218
|
+
#
|
219
|
+
# describe('Url normalization', function () {
|
220
|
+
#
|
221
|
+
# it('Should be overridable', function () {
|
222
|
+
# var md = markdownit({ linkify: true });
|
223
|
+
#
|
224
|
+
# md.normalizeLink = function (url) {
|
225
|
+
# assert(url.match(/example\.com/), 'wrong url passed');
|
226
|
+
# return 'LINK';
|
227
|
+
# };
|
228
|
+
# md.normalizeLinkText = function (url) {
|
229
|
+
# assert(url.match(/example\.com/), 'wrong url passed');
|
230
|
+
# return 'TEXT';
|
231
|
+
# };
|
232
|
+
#
|
233
|
+
# assert.strictEqual(md.render('foo@example.com'), '<p><a href="LINK">TEXT</a></p>\n');
|
234
|
+
# assert.strictEqual(md.render('http://example.com'), '<p><a href="LINK">TEXT</a></p>\n');
|
235
|
+
# assert.strictEqual(md.render('<foo@example.com>'), '<p><a href="LINK">TEXT</a></p>\n');
|
236
|
+
# assert.strictEqual(md.render('<http://example.com>'), '<p><a href="LINK">TEXT</a></p>\n');
|
237
|
+
# assert.strictEqual(md.render('[test](http://example.com)'), '<p><a href="LINK">test</a></p>\n');
|
238
|
+
# assert.strictEqual(md.render('![test](http://example.com)'), '<p><img src="LINK" alt="test"></p>\n');
|
239
|
+
# });
|
240
|
+
#
|
241
|
+
# });
|
242
|
+
#
|
243
|
+
#
|
244
|
+
# describe('Links validation', function () {
|
245
|
+
#
|
246
|
+
# it('Override validator, disable everything', function () {
|
247
|
+
# var md = markdownit({ linkify: true });
|
248
|
+
#
|
249
|
+
# md.validateLink = function () { return false; };
|
250
|
+
#
|
251
|
+
# assert.strictEqual(md.render('foo@example.com'), '<p>foo@example.com</p>\n');
|
252
|
+
# assert.strictEqual(md.render('http://example.com'), '<p>http://example.com</p>\n');
|
253
|
+
# assert.strictEqual(md.render('<foo@example.com>'), '<p><foo@example.com></p>\n');
|
254
|
+
# assert.strictEqual(md.render('<http://example.com>'), '<p><http://example.com></p>\n');
|
255
|
+
# assert.strictEqual(md.render('[test](http://example.com)'), '<p>[test](http://example.com)</p>\n');
|
256
|
+
# assert.strictEqual(md.render('![test](http://example.com)'), '<p>![test](http://example.com)</p>\n');
|
257
|
+
# });
|
258
|
+
#
|
259
|
+
# });
|
260
|
+
#
|
261
|
+
#
|
262
|
+
# describe('maxNesting', function () {
|
263
|
+
#
|
264
|
+
# it('Inline parser should not nest above limit', function () {
|
265
|
+
# var md = markdownit({ maxNesting: 2 });
|
266
|
+
# assert.strictEqual(md.render('*foo *bar *baz* bar* foo*'), '<p><em>foo <em>bar *baz* bar</em> foo</em></p>\n');
|
267
|
+
# });
|
268
|
+
#
|
269
|
+
# it('Block parser should not nest above limit', function () {
|
270
|
+
# var md = markdownit({ maxNesting: 2 });
|
271
|
+
# assert.strictEqual(
|
272
|
+
# md.render('>foo\n>>bar\n>>>baz'),
|
273
|
+
# '<blockquote>\n<p>foo</p>\n<blockquote></blockquote>\n</blockquote>\n'
|
274
|
+
# );
|
275
|
+
# });
|
276
|
+
|
277
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
describe 'Ruler' do
|
2
|
+
|
3
|
+
#------------------------------------------------------------------------------
|
4
|
+
it 'should replace rule (.at)' do
|
5
|
+
ruler = MarkdownIt::Ruler.new
|
6
|
+
res = 0
|
7
|
+
|
8
|
+
ruler.push('test', lambda { res = 1 })
|
9
|
+
ruler.at('test', lambda { res = 2 })
|
10
|
+
|
11
|
+
rules = ruler.getRules('')
|
12
|
+
|
13
|
+
expect(rules.length).to eq 1
|
14
|
+
rules[0].call
|
15
|
+
expect(res).to eq 2
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
#------------------------------------------------------------------------------
|
20
|
+
it 'should inject before/after rule' do
|
21
|
+
ruler = MarkdownIt::Ruler.new
|
22
|
+
res = 0
|
23
|
+
|
24
|
+
ruler.push('test', lambda { res = 1 })
|
25
|
+
ruler.before('test', 'before_test', lambda { res = -10; })
|
26
|
+
ruler.after('test', 'after_test', lambda { res = 10; })
|
27
|
+
|
28
|
+
rules = ruler.getRules('');
|
29
|
+
|
30
|
+
expect(rules.length).to eq 3
|
31
|
+
rules[0].call
|
32
|
+
expect(res).to eq -10
|
33
|
+
rules[1].call
|
34
|
+
expect(res).to eq 1
|
35
|
+
rules[2].call
|
36
|
+
expect(res).to eq 10
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
#------------------------------------------------------------------------------
|
41
|
+
it 'should enable/disable rule' do
|
42
|
+
ruler = MarkdownIt::Ruler.new
|
43
|
+
|
44
|
+
ruler.push('test', lambda {})
|
45
|
+
ruler.push('test2', lambda {})
|
46
|
+
|
47
|
+
rules = ruler.getRules('')
|
48
|
+
expect(rules.length).to eq 2
|
49
|
+
|
50
|
+
ruler.disable('test')
|
51
|
+
rules = ruler.getRules('')
|
52
|
+
expect(rules.length).to eq 1
|
53
|
+
ruler.disable('test2')
|
54
|
+
rules = ruler.getRules('')
|
55
|
+
expect(rules.length).to eq 0
|
56
|
+
|
57
|
+
ruler.enable('test')
|
58
|
+
rules = ruler.getRules('')
|
59
|
+
expect(rules.length).to eq 1
|
60
|
+
ruler.enable('test2')
|
61
|
+
rules = ruler.getRules('')
|
62
|
+
expect(rules.length).to eq 2
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
#------------------------------------------------------------------------------
|
67
|
+
it 'should enable/disable multiple rule' do
|
68
|
+
ruler = MarkdownIt::Ruler.new
|
69
|
+
|
70
|
+
ruler.push('test', lambda {})
|
71
|
+
ruler.push('test2', lambda {})
|
72
|
+
|
73
|
+
ruler.disable([ 'test', 'test2' ])
|
74
|
+
rules = ruler.getRules('')
|
75
|
+
expect(rules.length).to eq 0
|
76
|
+
ruler.enable([ 'test', 'test2' ])
|
77
|
+
rules = ruler.getRules('')
|
78
|
+
expect(rules.length).to eq 2
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
#------------------------------------------------------------------------------
|
83
|
+
it 'should enable rules by whitelist' do
|
84
|
+
ruler = MarkdownIt::Ruler.new
|
85
|
+
|
86
|
+
ruler.push('test', lambda {})
|
87
|
+
ruler.push('test2', lambda {})
|
88
|
+
|
89
|
+
ruler.enableOnly('test')
|
90
|
+
rules = ruler.getRules('')
|
91
|
+
expect(rules.length).to eq 1
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
#------------------------------------------------------------------------------
|
96
|
+
it 'should support multiple chains' do
|
97
|
+
ruler = MarkdownIt::Ruler.new
|
98
|
+
|
99
|
+
ruler.push('test', lambda {})
|
100
|
+
ruler.push('test2', lambda {}, { alt: [ 'alt1' ] })
|
101
|
+
ruler.push('test2', lambda {}, { alt: [ 'alt1', 'alt2' ] })
|
102
|
+
|
103
|
+
rules = ruler.getRules('')
|
104
|
+
expect(rules.length).to eq 3
|
105
|
+
rules = ruler.getRules('alt1')
|
106
|
+
expect(rules.length).to eq 2
|
107
|
+
rules = ruler.getRules('alt2');
|
108
|
+
expect(rules.length).to eq 1
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
#------------------------------------------------------------------------------
|
113
|
+
it 'should fail on invalid rule name' do
|
114
|
+
ruler = MarkdownIt::Ruler.new
|
115
|
+
|
116
|
+
ruler.push('test', lambda {})
|
117
|
+
|
118
|
+
expect {
|
119
|
+
ruler.at('invalid name', lambda {})
|
120
|
+
}.to raise_error(StandardError)
|
121
|
+
expect {
|
122
|
+
ruler.before('invalid name', lambda {})
|
123
|
+
}.to raise_error(StandardError)
|
124
|
+
expect {
|
125
|
+
ruler.after('invalid name', lambda {})
|
126
|
+
}.to raise_error(StandardError)
|
127
|
+
expect {
|
128
|
+
ruler.enable('invalid name')
|
129
|
+
}.to raise_error(StandardError)
|
130
|
+
expect {
|
131
|
+
ruler.disable('invalid name')
|
132
|
+
}.to raise_error(StandardError)
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
#------------------------------------------------------------------------------
|
137
|
+
it 'should not fail on invalid rule name in silent mode' do
|
138
|
+
ruler = MarkdownIt::Ruler.new
|
139
|
+
|
140
|
+
ruler.push('test', lambda {})
|
141
|
+
|
142
|
+
expect {
|
143
|
+
ruler.enable('invalid name', true)
|
144
|
+
}.not_to raise_error
|
145
|
+
expect {
|
146
|
+
ruler.enableOnly('invalid name', true)
|
147
|
+
}.not_to raise_error
|
148
|
+
expect {
|
149
|
+
ruler.disable('invalid name', true)
|
150
|
+
}.not_to raise_error
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|