motion-markdown-it 12.0.6 → 12.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/motion-markdown-it/index.rb +2 -2
- data/lib/motion-markdown-it/renderer.rb +3 -3
- data/lib/motion-markdown-it/rules_block/code.rb +1 -1
- data/lib/motion-markdown-it/rules_block/html_block.rb +1 -1
- data/lib/motion-markdown-it/rules_block/list.rb +6 -2
- data/lib/motion-markdown-it/rules_inline/balance_pairs.rb +35 -13
- data/lib/motion-markdown-it/rules_inline/emphasis.rb +4 -11
- data/lib/motion-markdown-it/rules_inline/newline.rb +7 -1
- data/lib/motion-markdown-it/rules_inline/strikethrough.rb +0 -1
- data/lib/motion-markdown-it/token.rb +1 -0
- data/lib/motion-markdown-it/version.rb +1 -1
- data/spec/motion-markdown-it/misc_spec.rb +39 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c31536746654ba78827fdf56f400de64e4b70bb1e459c7bbd610febaaf1074b3
|
4
|
+
data.tar.gz: 80e94ade9943fe02ce4c3b153ff002ddbaca3239d632f3cce74e4724182b7527
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f2566c0fcae8a7ee85f0c7be95440429c643dbc3e7d1d7b94b67bb5deeedbabb4553c81ba566db87087b5c058516420b0a9c45e29b85467baaa5875a7476fab
|
7
|
+
data.tar.gz: 89fe0c6e543efb1eb11f0186e346fbe31f2e714745ee8272ca75e953e1a6fb7796e19754d97fcc67d5b0d3e01fc8731a8a46a03ea8eaacb598e3e690a7720c27
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Ruby/RubyMotion version of Markdown-it (CommonMark compliant and extendable)
|
|
7
7
|
|
8
8
|
This gem is a port of the [markdown-it Javascript package](https://github.com/markdown-it/markdown-it) by Vitaly Puzrin and Alex Kocharin.
|
9
9
|
|
10
|
-
_Currently synced with markdown-it 12.
|
10
|
+
_Currently synced with markdown-it 12.3.2_
|
11
11
|
|
12
12
|
---
|
13
13
|
|
@@ -185,7 +185,7 @@ var md = require('markdown-it')({
|
|
185
185
|
highlight: function (str, lang) {
|
186
186
|
if (lang && hljs.getLanguage(lang)) {
|
187
187
|
try {
|
188
|
-
return hljs.highlight(
|
188
|
+
return hljs.highlight(str, { language: lang }).value;
|
189
189
|
} catch (__) {}
|
190
190
|
}
|
191
191
|
|
@@ -205,7 +205,7 @@ var md = require('markdown-it')({
|
|
205
205
|
if (lang && hljs.getLanguage(lang)) {
|
206
206
|
try {
|
207
207
|
return '<pre class="hljs"><code>' +
|
208
|
-
hljs.highlight(
|
208
|
+
hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
|
209
209
|
'</code></pre>';
|
210
210
|
} catch (__) {}
|
211
211
|
}
|
@@ -190,7 +190,7 @@ module MarkdownIt
|
|
190
190
|
# highlight: function (str, lang) {
|
191
191
|
# if (lang && hljs.getLanguage(lang)) {
|
192
192
|
# try {
|
193
|
-
# return hljs.highlight(
|
193
|
+
# return hljs.highlight(str, { language: lang, ignoreIllegals: true }).value;
|
194
194
|
# } catch (__) {}
|
195
195
|
# }
|
196
196
|
#
|
@@ -210,7 +210,7 @@ module MarkdownIt
|
|
210
210
|
# if (lang && hljs.getLanguage(lang)) {
|
211
211
|
# try {
|
212
212
|
# return '<pre class="hljs"><code>' +
|
213
|
-
# hljs.highlight(
|
213
|
+
# hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
|
214
214
|
# '</code></pre>';
|
215
215
|
# } catch (__) {}
|
216
216
|
# }
|
@@ -245,7 +245,7 @@ module MarkdownIt
|
|
245
245
|
|
246
246
|
|
247
247
|
# Renderer.renderInline(tokens, options, env) -> String
|
248
|
-
# - tokens (Array): list on block tokens to
|
248
|
+
# - tokens (Array): list on block tokens to render
|
249
249
|
# - options (Object): params of parser instance
|
250
250
|
# - env (Object): additional data from parsed input (references, for example)
|
251
251
|
#
|
@@ -271,7 +271,7 @@ module MarkdownIt
|
|
271
271
|
|
272
272
|
# internal
|
273
273
|
# Renderer.renderInlineAsText(tokens, options, env) -> String
|
274
|
-
# - tokens (Array): list on block tokens to
|
274
|
+
# - tokens (Array): list on block tokens to render
|
275
275
|
# - options (Object): params of parser instance
|
276
276
|
# - env (Object): additional data from parsed input (references, for example)
|
277
277
|
#
|
@@ -297,7 +297,7 @@ module MarkdownIt
|
|
297
297
|
|
298
298
|
|
299
299
|
# Renderer.render(tokens, options, env) -> String
|
300
|
-
# - tokens (Array): list on block tokens to
|
300
|
+
# - tokens (Array): list on block tokens to render
|
301
301
|
# - options (Object): params of parser instance
|
302
302
|
# - env (Object): additional data from parsed input (references, for example)
|
303
303
|
#
|
@@ -26,7 +26,7 @@ module MarkdownIt
|
|
26
26
|
state.line = last
|
27
27
|
|
28
28
|
token = state.push('code_block', 'code', 0)
|
29
|
-
token.content = state.getLines(startLine, last, 4 + state.blkIndent,
|
29
|
+
token.content = state.getLines(startLine, last, 4 + state.blkIndent, false) + "\n"
|
30
30
|
token.map = [ startLine, state.line ]
|
31
31
|
return true
|
32
32
|
end
|
@@ -11,7 +11,7 @@ module MarkdownIt
|
|
11
11
|
# last argument defines whether it can terminate a paragraph or not
|
12
12
|
#
|
13
13
|
HTML_SEQUENCES = [
|
14
|
-
[ /^<(script|pre|style)(?=(\s|>|$))/i, /<\/(script|pre|style)>/i, true ],
|
14
|
+
[ /^<(script|pre|style|textarea)(?=(\s|>|$))/i, /<\/(script|pre|style|textarea)>/i, true ],
|
15
15
|
[ /^<!--/, /-->/, true ],
|
16
16
|
[ /^<\?/, /\?>/, true ],
|
17
17
|
[ /^<![A-Z]/, />/, true ],
|
@@ -129,7 +129,7 @@ module MarkdownIt
|
|
129
129
|
# This code can fail if plugins use blkIndent as well as lists,
|
130
130
|
# but I hope the spec gets fixed long before that happens.
|
131
131
|
#
|
132
|
-
if state.
|
132
|
+
if state.sCount[startLine] >= state.blkIndent
|
133
133
|
isTerminatingParagraph = true
|
134
134
|
end
|
135
135
|
end
|
@@ -138,7 +138,7 @@ module MarkdownIt
|
|
138
138
|
if ((posAfterMarker = skipOrderedListMarker(state, startLine)) >= 0)
|
139
139
|
isOrdered = true
|
140
140
|
start = state.bMarks[startLine] + state.tShift[startLine]
|
141
|
-
markerValue = state.src[start, posAfterMarker -
|
141
|
+
markerValue = state.src[start, posAfterMarker - 1].to_i
|
142
142
|
|
143
143
|
# If we're starting a new ordered list right after
|
144
144
|
# a paragraph, it should start with 1.
|
@@ -231,6 +231,9 @@ module MarkdownIt
|
|
231
231
|
token = state.push('list_item_open', 'li', 1)
|
232
232
|
token.markup = markerCharCode.chr
|
233
233
|
token.map = itemLines = [ startLine, 0 ]
|
234
|
+
if (isOrdered)
|
235
|
+
token.info = state.src.slice(start...posAfterMarker - 1)
|
236
|
+
end
|
234
237
|
|
235
238
|
# change current state, then restore it after parser subcall
|
236
239
|
oldTight = state.tight
|
@@ -307,6 +310,7 @@ module MarkdownIt
|
|
307
310
|
if (isOrdered)
|
308
311
|
posAfterMarker = skipOrderedListMarker(state, nextLine)
|
309
312
|
break if (posAfterMarker < 0)
|
313
|
+
start = state.bMarks[nextLine] + state.tShift[nextLine]
|
310
314
|
else
|
311
315
|
posAfterMarker = skipBulletListMarker(state, nextLine)
|
312
316
|
break if (posAfterMarker < 0)
|
@@ -9,9 +9,28 @@ module MarkdownIt
|
|
9
9
|
openersBottom = {}
|
10
10
|
max = delimiters.length
|
11
11
|
|
12
|
+
return if (!max)
|
13
|
+
|
14
|
+
# headerIdx is the first delimiter of the current (where closer is) delimiter run
|
15
|
+
headerIdx = 0
|
16
|
+
lastTokenIdx = -2 # needs any value lower than -1
|
17
|
+
jumps = []
|
18
|
+
|
12
19
|
0.upto(max - 1) do |closerIdx|
|
13
20
|
closer = delimiters[closerIdx]
|
14
21
|
|
22
|
+
jumps.push(0)
|
23
|
+
|
24
|
+
# markers belong to same delimiter run if:
|
25
|
+
# - they have adjacent tokens
|
26
|
+
# - AND markers are the same
|
27
|
+
#
|
28
|
+
if (delimiters[headerIdx][:marker] != closer[:marker] || lastTokenIdx != closer[:token] - 1)
|
29
|
+
headerIdx = closerIdx
|
30
|
+
end
|
31
|
+
|
32
|
+
lastTokenIdx = closer[:token]
|
33
|
+
|
15
34
|
# Length is only used for emphasis-specific "rule of 3",
|
16
35
|
# if it's not defined (in strikethrough or 3rd party plugins),
|
17
36
|
# we can default it to 0 to disable those checks.
|
@@ -21,24 +40,23 @@ module MarkdownIt
|
|
21
40
|
next if (!closer[:close])
|
22
41
|
|
23
42
|
# Previously calculated lower bounds (previous fails)
|
24
|
-
# for each marker
|
43
|
+
# for each marker, each delimiter length modulo 3,
|
44
|
+
# and for whether this closer can be an opener;
|
45
|
+
# https://github.com/commonmark/cmark/commit/34250e12ccebdc6372b8b49c44fab57c72443460
|
25
46
|
unless openersBottom[closer[:marker]]
|
26
|
-
openersBottom[closer[:marker]] = [ -1, -1, -1 ]
|
47
|
+
openersBottom[closer[:marker]] = [ -1, -1, -1, -1, -1, -1 ]
|
27
48
|
end
|
28
49
|
|
29
|
-
minOpenerIdx = openersBottom[closer[:marker]][closer[:length] % 3]
|
50
|
+
minOpenerIdx = openersBottom[closer[:marker]][(closer[:open] ? 3 : 0) + (closer[:length] % 3)]
|
30
51
|
|
31
|
-
openerIdx =
|
32
|
-
|
33
|
-
# avoid crash if `closer.jump` is pointing outside of the array, see #742
|
34
|
-
openerIdx = -1 if (openerIdx < -1)
|
52
|
+
openerIdx = headerIdx - jumps[headerIdx] - 1
|
35
53
|
|
36
54
|
newMinOpenerIdx = openerIdx
|
37
55
|
|
38
56
|
while openerIdx > minOpenerIdx
|
39
57
|
opener = delimiters[openerIdx]
|
40
58
|
|
41
|
-
(openerIdx -=
|
59
|
+
(openerIdx -= jumps[openerIdx] + 1) && next if (opener[:marker] != closer[:marker])
|
42
60
|
|
43
61
|
if (opener[:open] && opener[:end] < 0)
|
44
62
|
|
@@ -65,19 +83,23 @@ module MarkdownIt
|
|
65
83
|
# sure algorithm has linear complexity (see *_*_*_*_*_... case).
|
66
84
|
#
|
67
85
|
lastJump = openerIdx > 0 && !delimiters[openerIdx - 1][:open] ?
|
68
|
-
|
86
|
+
jumps[openerIdx - 1] + 1 : 0
|
69
87
|
|
70
|
-
|
88
|
+
jumps[closerIdx] = closerIdx - openerIdx + lastJump
|
89
|
+
jumps[openerIdx] = lastJump
|
90
|
+
|
71
91
|
closer[:open] = false
|
72
92
|
opener[:end] = closerIdx
|
73
|
-
opener[:jump] = lastJump
|
74
93
|
opener[:close] = false
|
75
94
|
newMinOpenerIdx = -1
|
95
|
+
# treat next token as start of run,
|
96
|
+
# it optimizes skips in **<...>**a**<...>** pathological case
|
97
|
+
lastTokenIdx = -2
|
76
98
|
break
|
77
99
|
end
|
78
100
|
end
|
79
101
|
|
80
|
-
openerIdx -=
|
102
|
+
openerIdx -= jumps[openerIdx] + 1
|
81
103
|
end
|
82
104
|
|
83
105
|
if (newMinOpenerIdx != -1)
|
@@ -88,7 +110,7 @@ module MarkdownIt
|
|
88
110
|
# See details here:
|
89
111
|
# https://github.com/commonmark/cmark/issues/178#issuecomment-270417442
|
90
112
|
#
|
91
|
-
openersBottom[closer[:marker]][(closer[:length] || 0) % 3] = newMinOpenerIdx
|
113
|
+
openersBottom[closer[:marker]][(closer[:open] ? 3 : 0) + ((closer[:length] || 0) % 3)] = newMinOpenerIdx
|
92
114
|
end
|
93
115
|
end
|
94
116
|
end
|
@@ -30,15 +30,6 @@ module MarkdownIt
|
|
30
30
|
#
|
31
31
|
length: scanned[:length],
|
32
32
|
|
33
|
-
# An amount of characters before this one that's equivalent to
|
34
|
-
# current one. In plain English: if this delimiter does not open
|
35
|
-
# an emphasis, neither do previous `jump` characters.
|
36
|
-
#
|
37
|
-
# Used to skip sequences like "*****" in one step, for 1st asterisk
|
38
|
-
# value will be 0, for 2nd it's 1 and so on.
|
39
|
-
#
|
40
|
-
jump: i,
|
41
|
-
|
42
33
|
# A position of the token this delimiter corresponds to.
|
43
34
|
#
|
44
35
|
token: state.tokens.length - 1,
|
@@ -82,9 +73,11 @@ module MarkdownIt
|
|
82
73
|
#
|
83
74
|
isStrong = i > 0 &&
|
84
75
|
delimiters[i - 1][:end] == startDelim[:end] + 1 &&
|
76
|
+
# check that first two markers match and adjacent
|
77
|
+
delimiters[i - 1][:marker] == startDelim[:marker] &&
|
85
78
|
delimiters[i - 1][:token] == startDelim[:token] - 1 &&
|
86
|
-
|
87
|
-
delimiters[
|
79
|
+
# check that last two markers are adjacent (we can safely assume they match)
|
80
|
+
delimiters[startDelim[:end] + 1][:token] == endDelim[:token] + 1
|
88
81
|
|
89
82
|
ch = fromCodePoint(startDelim[:marker])
|
90
83
|
|
@@ -20,7 +20,13 @@ module MarkdownIt
|
|
20
20
|
if !silent
|
21
21
|
if pmax >= 0 && charCodeAt(state.pending, pmax) == 0x20
|
22
22
|
if pmax >= 1 && charCodeAt(state.pending, pmax - 1) == 0x20
|
23
|
-
|
23
|
+
# Find whitespaces tail of pending chars.
|
24
|
+
ws = pmax - 1
|
25
|
+
while (ws >= 1 && charCodeAt(state.pending, ws - 1) == 0x20)
|
26
|
+
ws -= 1
|
27
|
+
end
|
28
|
+
|
29
|
+
state.pending = state.pending.slice(0...ws)
|
24
30
|
state.push('hardbreak', 'br', 0)
|
25
31
|
else
|
26
32
|
state.pending = state.pending.slice(0...-1)
|
@@ -67,6 +67,7 @@ module MarkdownIt
|
|
67
67
|
# *
|
68
68
|
# * - Info string for "fence" tokens
|
69
69
|
# * - The value "auto" for autolink "link_open" and "link_close" tokens
|
70
|
+
# * - The string value of the item marker for ordered-list "list_item_open" tokens
|
70
71
|
@info = ''
|
71
72
|
|
72
73
|
# * Token#meta -> Object
|
@@ -195,6 +195,9 @@ describe 'Misc' do
|
|
195
195
|
|
196
196
|
expect(md.render('123')).to eq "<p>123</p>\n"
|
197
197
|
expect(md.render("123\n")).to eq "<p>123</p>\n"
|
198
|
+
|
199
|
+
expect(md.render(' codeblock')).to eq "<pre><code>codeblock\n</code></pre>\n"
|
200
|
+
expect(md.render(" codeblock\n")).to eq "<pre><code>codeblock\n</code></pre>\n"
|
198
201
|
end
|
199
202
|
|
200
203
|
#------------------------------------------------------------------------------
|
@@ -371,6 +374,42 @@ describe 'smartquotes' do
|
|
371
374
|
end
|
372
375
|
end
|
373
376
|
|
377
|
+
describe 'Ordered list info' do
|
378
|
+
md = MarkdownIt::Parser.new
|
379
|
+
|
380
|
+
def type_filter(tokens, type)
|
381
|
+
return tokens.select { |t| t.type === type }
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'Should mark ordered list item tokens with info' do
|
385
|
+
tokens = md.parse("1. Foo\n2. Bar\n20. Fuzz", {})
|
386
|
+
expect(type_filter(tokens, 'ordered_list_open').length).to eq 1
|
387
|
+
|
388
|
+
tokens = type_filter(tokens, 'list_item_open')
|
389
|
+
expect(tokens.length).to eq 3
|
390
|
+
expect(tokens[0].info).to eq '1'
|
391
|
+
expect(tokens[0].markup).to eq '.'
|
392
|
+
expect(tokens[1].info).to eq '2'
|
393
|
+
expect(tokens[1].markup).to eq '.'
|
394
|
+
expect(tokens[2].info).to eq '20'
|
395
|
+
expect(tokens[2].markup).to eq '.'
|
396
|
+
|
397
|
+
tokens = md.parse(" 1. Foo\n2. Bar\n 20. Fuzz\n 199. Flp", {})
|
398
|
+
expect(type_filter(tokens, 'ordered_list_open').length).to eq 1
|
399
|
+
|
400
|
+
tokens = type_filter(tokens, 'list_item_open')
|
401
|
+
expect(tokens.length).to eq 4
|
402
|
+
expect(tokens[0].info).to eq '1'
|
403
|
+
expect(tokens[0].markup).to eq '.'
|
404
|
+
expect(tokens[1].info).to eq '2'
|
405
|
+
expect(tokens[1].markup).to eq '.'
|
406
|
+
expect(tokens[2].info).to eq '20'
|
407
|
+
expect(tokens[2].markup).to eq '.'
|
408
|
+
expect(tokens[3].info).to eq '199'
|
409
|
+
expect(tokens[3].markup).to eq '.'
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
374
413
|
#------------------------------------------------------------------------------
|
375
414
|
describe 'Token attributes' do
|
376
415
|
|