@depup/markdown-it 14.1.1-depup.1 → 14.3.0-depup.13
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.
- package/README.md +7 -5
- package/changes.json +11 -3
- package/dist/index.cjs.js +3661 -5307
- package/dist/index.cjs.js.map +1 -0
- package/dist/markdown-it.js +1451 -4445
- package/dist/markdown-it.js.map +1 -0
- package/dist/markdown-it.min.js +3 -2
- package/dist/markdown-it.min.js.map +1 -0
- package/lib/common/html_re.mjs +9 -9
- package/lib/common/utils.mjs +32 -12
- package/lib/index.mjs +1 -1
- package/lib/parser_block.mjs +9 -9
- package/lib/parser_core.mjs +7 -7
- package/lib/parser_inline.mjs +16 -16
- package/lib/renderer.mjs +2 -2
- package/lib/rules_block/blockquote.mjs +6 -6
- package/lib/rules_block/code.mjs +2 -2
- package/lib/rules_block/fence.mjs +4 -4
- package/lib/rules_block/heading.mjs +8 -8
- package/lib/rules_block/hr.mjs +2 -2
- package/lib/rules_block/html_block.mjs +18 -7
- package/lib/rules_block/lheading.mjs +12 -9
- package/lib/rules_block/list.mjs +6 -6
- package/lib/rules_block/paragraph.mjs +8 -6
- package/lib/rules_block/reference.mjs +1 -1
- package/lib/rules_block/state_block.mjs +6 -6
- package/lib/rules_block/table.mjs +4 -4
- package/lib/rules_core/block.mjs +3 -3
- package/lib/rules_core/linkify.mjs +15 -15
- package/lib/rules_core/normalize.mjs +2 -2
- package/lib/rules_core/smartquotes.mjs +37 -21
- package/lib/rules_inline/autolink.mjs +17 -17
- package/lib/rules_inline/balance_pairs.mjs +2 -2
- package/lib/rules_inline/emphasis.mjs +8 -8
- package/lib/rules_inline/entity.mjs +9 -9
- package/lib/rules_inline/escape.mjs +15 -1
- package/lib/rules_inline/html_inline.mjs +1 -1
- package/lib/rules_inline/link.mjs +1 -1
- package/lib/rules_inline/state_inline.mjs +39 -8
- package/lib/rules_inline/strikethrough.mjs +10 -10
- package/lib/token.mjs +12 -12
- package/package.json +54 -42
|
@@ -93,36 +93,36 @@ export default function linkify (state) {
|
|
|
93
93
|
const pos = links[ln].index
|
|
94
94
|
|
|
95
95
|
if (pos > lastPos) {
|
|
96
|
-
const token
|
|
96
|
+
const token = new state.Token('text', '', 0)
|
|
97
97
|
token.content = text.slice(lastPos, pos)
|
|
98
|
-
token.level
|
|
98
|
+
token.level = level
|
|
99
99
|
nodes.push(token)
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
const token_o
|
|
103
|
-
token_o.attrs
|
|
104
|
-
token_o.level
|
|
105
|
-
token_o.markup
|
|
106
|
-
token_o.info
|
|
102
|
+
const token_o = new state.Token('link_open', 'a', 1)
|
|
103
|
+
token_o.attrs = [['href', fullUrl]]
|
|
104
|
+
token_o.level = level++
|
|
105
|
+
token_o.markup = 'linkify'
|
|
106
|
+
token_o.info = 'auto'
|
|
107
107
|
nodes.push(token_o)
|
|
108
108
|
|
|
109
|
-
const token_t
|
|
109
|
+
const token_t = new state.Token('text', '', 0)
|
|
110
110
|
token_t.content = urlText
|
|
111
|
-
token_t.level
|
|
111
|
+
token_t.level = level
|
|
112
112
|
nodes.push(token_t)
|
|
113
113
|
|
|
114
|
-
const token_c
|
|
115
|
-
token_c.level
|
|
116
|
-
token_c.markup
|
|
117
|
-
token_c.info
|
|
114
|
+
const token_c = new state.Token('link_close', 'a', -1)
|
|
115
|
+
token_c.level = --level
|
|
116
|
+
token_c.markup = 'linkify'
|
|
117
|
+
token_c.info = 'auto'
|
|
118
118
|
nodes.push(token_c)
|
|
119
119
|
|
|
120
120
|
lastPos = links[ln].lastIndex
|
|
121
121
|
}
|
|
122
122
|
if (lastPos < text.length) {
|
|
123
|
-
const token
|
|
123
|
+
const token = new state.Token('text', '', 0)
|
|
124
124
|
token.content = text.slice(lastPos)
|
|
125
|
-
token.level
|
|
125
|
+
token.level = level
|
|
126
126
|
nodes.push(token)
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
// Convert straight quotation marks to typographic ones
|
|
2
2
|
//
|
|
3
3
|
|
|
4
|
-
import { isWhiteSpace,
|
|
4
|
+
import { isWhiteSpace, isPunctCharCode, isMdAsciiPunct } from '../common/utils.mjs'
|
|
5
5
|
|
|
6
6
|
const QUOTE_TEST_RE = /['"]/
|
|
7
7
|
const QUOTE_RE = /['"]/g
|
|
8
8
|
const APOSTROPHE = '\u2019' /* ’ */
|
|
9
9
|
|
|
10
|
-
function
|
|
11
|
-
|
|
10
|
+
function addReplacement (replacements, tokenIdx, pos, ch) {
|
|
11
|
+
if (!replacements[tokenIdx]) {
|
|
12
|
+
replacements[tokenIdx] = []
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
replacements[tokenIdx].push({ pos, ch })
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function applyReplacements (str, replacements) {
|
|
19
|
+
let result = ''
|
|
20
|
+
let lastPos = 0
|
|
21
|
+
|
|
22
|
+
replacements.sort((a, b) => a.pos - b.pos)
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < replacements.length; i++) {
|
|
25
|
+
const replacement = replacements[i]
|
|
26
|
+
|
|
27
|
+
result += str.slice(lastPos, replacement.pos) + replacement.ch
|
|
28
|
+
lastPos = replacement.pos + 1
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return result + str.slice(lastPos)
|
|
12
32
|
}
|
|
13
33
|
|
|
14
34
|
function process_inlines (tokens, state) {
|
|
15
35
|
let j
|
|
16
36
|
|
|
17
37
|
const stack = []
|
|
38
|
+
// token index -> list of replacements in the original token content
|
|
39
|
+
const replacements = {}
|
|
18
40
|
|
|
19
41
|
for (let i = 0; i < tokens.length; i++) {
|
|
20
42
|
const token = tokens[i]
|
|
@@ -28,9 +50,9 @@ function process_inlines (tokens, state) {
|
|
|
28
50
|
|
|
29
51
|
if (token.type !== 'text') { continue }
|
|
30
52
|
|
|
31
|
-
|
|
53
|
+
const text = token.content
|
|
32
54
|
let pos = 0
|
|
33
|
-
|
|
55
|
+
const max = text.length
|
|
34
56
|
|
|
35
57
|
/* eslint no-labels:0,block-scoped-var:0 */
|
|
36
58
|
OUTER:
|
|
@@ -78,8 +100,8 @@ function process_inlines (tokens, state) {
|
|
|
78
100
|
}
|
|
79
101
|
}
|
|
80
102
|
|
|
81
|
-
const isLastPunctChar = isMdAsciiPunct(lastChar) ||
|
|
82
|
-
const isNextPunctChar = isMdAsciiPunct(nextChar) ||
|
|
103
|
+
const isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctCharCode(lastChar)
|
|
104
|
+
const isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctCharCode(nextChar)
|
|
83
105
|
|
|
84
106
|
const isLastWhiteSpace = isWhiteSpace(lastChar)
|
|
85
107
|
const isNextWhiteSpace = isWhiteSpace(nextChar)
|
|
@@ -122,7 +144,7 @@ function process_inlines (tokens, state) {
|
|
|
122
144
|
if (!canOpen && !canClose) {
|
|
123
145
|
// middle of word
|
|
124
146
|
if (isSingle) {
|
|
125
|
-
|
|
147
|
+
addReplacement(replacements, i, t.index, APOSTROPHE)
|
|
126
148
|
}
|
|
127
149
|
continue
|
|
128
150
|
}
|
|
@@ -145,18 +167,8 @@ function process_inlines (tokens, state) {
|
|
|
145
167
|
closeQuote = state.md.options.quotes[1]
|
|
146
168
|
}
|
|
147
169
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
// could mess up indices when quote length != 1
|
|
151
|
-
token.content = replaceAt(token.content, t.index, closeQuote)
|
|
152
|
-
tokens[item.token].content = replaceAt(
|
|
153
|
-
tokens[item.token].content, item.pos, openQuote)
|
|
154
|
-
|
|
155
|
-
pos += closeQuote.length - 1
|
|
156
|
-
if (item.token === i) { pos += openQuote.length - 1 }
|
|
157
|
-
|
|
158
|
-
text = token.content
|
|
159
|
-
max = text.length
|
|
170
|
+
addReplacement(replacements, i, t.index, closeQuote)
|
|
171
|
+
addReplacement(replacements, item.token, item.pos, openQuote)
|
|
160
172
|
|
|
161
173
|
stack.length = j
|
|
162
174
|
continue OUTER
|
|
@@ -172,10 +184,14 @@ function process_inlines (tokens, state) {
|
|
|
172
184
|
level: thisLevel
|
|
173
185
|
})
|
|
174
186
|
} else if (canClose && isSingle) {
|
|
175
|
-
|
|
187
|
+
addReplacement(replacements, i, t.index, APOSTROPHE)
|
|
176
188
|
}
|
|
177
189
|
}
|
|
178
190
|
}
|
|
191
|
+
|
|
192
|
+
Object.keys(replacements).forEach(function (tokenIdx) {
|
|
193
|
+
tokens[tokenIdx].content = applyReplacements(tokens[tokenIdx].content, replacements[tokenIdx])
|
|
194
|
+
})
|
|
179
195
|
}
|
|
180
196
|
|
|
181
197
|
export default function smartquotes (state) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Process autolinks '<protocol:...>'
|
|
2
2
|
|
|
3
3
|
/* eslint max-len:0 */
|
|
4
|
-
const EMAIL_RE
|
|
4
|
+
const EMAIL_RE = /^([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)$/
|
|
5
5
|
/* eslint-disable-next-line no-control-regex */
|
|
6
6
|
const AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.-]{1,31}):([^<>\x00-\x20]*)$/
|
|
7
7
|
|
|
@@ -29,17 +29,17 @@ export default function autolink (state, silent) {
|
|
|
29
29
|
if (!state.md.validateLink(fullUrl)) { return false }
|
|
30
30
|
|
|
31
31
|
if (!silent) {
|
|
32
|
-
const token_o
|
|
33
|
-
token_o.attrs
|
|
34
|
-
token_o.markup
|
|
35
|
-
token_o.info
|
|
32
|
+
const token_o = state.push('link_open', 'a', 1)
|
|
33
|
+
token_o.attrs = [['href', fullUrl]]
|
|
34
|
+
token_o.markup = 'autolink'
|
|
35
|
+
token_o.info = 'auto'
|
|
36
36
|
|
|
37
|
-
const token_t
|
|
37
|
+
const token_t = state.push('text', '', 0)
|
|
38
38
|
token_t.content = state.md.normalizeLinkText(url)
|
|
39
39
|
|
|
40
|
-
const token_c
|
|
41
|
-
token_c.markup
|
|
42
|
-
token_c.info
|
|
40
|
+
const token_c = state.push('link_close', 'a', -1)
|
|
41
|
+
token_c.markup = 'autolink'
|
|
42
|
+
token_c.info = 'auto'
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
state.pos += url.length + 2
|
|
@@ -51,17 +51,17 @@ export default function autolink (state, silent) {
|
|
|
51
51
|
if (!state.md.validateLink(fullUrl)) { return false }
|
|
52
52
|
|
|
53
53
|
if (!silent) {
|
|
54
|
-
const token_o
|
|
55
|
-
token_o.attrs
|
|
56
|
-
token_o.markup
|
|
57
|
-
token_o.info
|
|
54
|
+
const token_o = state.push('link_open', 'a', 1)
|
|
55
|
+
token_o.attrs = [['href', fullUrl]]
|
|
56
|
+
token_o.markup = 'autolink'
|
|
57
|
+
token_o.info = 'auto'
|
|
58
58
|
|
|
59
|
-
const token_t
|
|
59
|
+
const token_t = state.push('text', '', 0)
|
|
60
60
|
token_t.content = state.md.normalizeLinkText(url)
|
|
61
61
|
|
|
62
|
-
const token_c
|
|
63
|
-
token_c.markup
|
|
64
|
-
token_c.info
|
|
62
|
+
const token_c = state.push('link_close', 'a', -1)
|
|
63
|
+
token_c.markup = 'autolink'
|
|
64
|
+
token_c.info = 'auto'
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
state.pos += url.length + 2
|
|
@@ -85,8 +85,8 @@ function processDelimiters (delimiters) {
|
|
|
85
85
|
jumps[closerIdx] = closerIdx - openerIdx + lastJump
|
|
86
86
|
jumps[openerIdx] = lastJump
|
|
87
87
|
|
|
88
|
-
closer.open
|
|
89
|
-
opener.end
|
|
88
|
+
closer.open = false
|
|
89
|
+
opener.end = closerIdx
|
|
90
90
|
opener.close = false
|
|
91
91
|
newMinOpenerIdx = -1
|
|
92
92
|
// treat next token as start of run,
|
|
@@ -80,18 +80,18 @@ function postProcess (state, delimiters) {
|
|
|
80
80
|
|
|
81
81
|
const ch = String.fromCharCode(startDelim.marker)
|
|
82
82
|
|
|
83
|
-
const token_o
|
|
84
|
-
token_o.type
|
|
85
|
-
token_o.tag
|
|
83
|
+
const token_o = state.tokens[startDelim.token]
|
|
84
|
+
token_o.type = isStrong ? 'strong_open' : 'em_open'
|
|
85
|
+
token_o.tag = isStrong ? 'strong' : 'em'
|
|
86
86
|
token_o.nesting = 1
|
|
87
|
-
token_o.markup
|
|
87
|
+
token_o.markup = isStrong ? ch + ch : ch
|
|
88
88
|
token_o.content = ''
|
|
89
89
|
|
|
90
|
-
const token_c
|
|
91
|
-
token_c.type
|
|
92
|
-
token_c.tag
|
|
90
|
+
const token_c = state.tokens[endDelim.token]
|
|
91
|
+
token_c.type = isStrong ? 'strong_close' : 'em_close'
|
|
92
|
+
token_c.tag = isStrong ? 'strong' : 'em'
|
|
93
93
|
token_c.nesting = -1
|
|
94
|
-
token_c.markup
|
|
94
|
+
token_c.markup = isStrong ? ch + ch : ch
|
|
95
95
|
token_c.content = ''
|
|
96
96
|
|
|
97
97
|
if (isStrong) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Process html entity - {, ¯, ", ...
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { decodeHTMLStrict } from 'entities'
|
|
4
4
|
import { isValidEntityCode, fromCodePoint } from '../common/utils.mjs'
|
|
5
5
|
|
|
6
6
|
const DIGITAL_RE = /^&#((?:x[a-f0-9]{1,6}|[0-9]{1,7}));/i
|
|
7
|
-
const NAMED_RE
|
|
7
|
+
const NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i
|
|
8
8
|
|
|
9
9
|
export default function entity (state, silent) {
|
|
10
10
|
const pos = state.pos
|
|
@@ -22,10 +22,10 @@ export default function entity (state, silent) {
|
|
|
22
22
|
if (!silent) {
|
|
23
23
|
const code = match[1][0].toLowerCase() === 'x' ? parseInt(match[1].slice(1), 16) : parseInt(match[1], 10)
|
|
24
24
|
|
|
25
|
-
const token
|
|
25
|
+
const token = state.push('text_special', '', 0)
|
|
26
26
|
token.content = isValidEntityCode(code) ? fromCodePoint(code) : fromCodePoint(0xFFFD)
|
|
27
|
-
token.markup
|
|
28
|
-
token.info
|
|
27
|
+
token.markup = match[0]
|
|
28
|
+
token.info = 'entity'
|
|
29
29
|
}
|
|
30
30
|
state.pos += match[0].length
|
|
31
31
|
return true
|
|
@@ -33,13 +33,13 @@ export default function entity (state, silent) {
|
|
|
33
33
|
} else {
|
|
34
34
|
const match = state.src.slice(pos).match(NAMED_RE)
|
|
35
35
|
if (match) {
|
|
36
|
-
const decoded =
|
|
36
|
+
const decoded = decodeHTMLStrict(match[0])
|
|
37
37
|
if (decoded !== match[0]) {
|
|
38
38
|
if (!silent) {
|
|
39
|
-
const token
|
|
39
|
+
const token = state.push('text_special', '', 0)
|
|
40
40
|
token.content = decoded
|
|
41
|
-
token.markup
|
|
42
|
-
token.info
|
|
41
|
+
token.markup = match[0]
|
|
42
|
+
token.info = 'entity'
|
|
43
43
|
}
|
|
44
44
|
state.pos += match[0].length
|
|
45
45
|
return true
|
|
@@ -38,6 +38,20 @@ export default function escape (state, silent) {
|
|
|
38
38
|
return true
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
// '\' before a space is a literal backslash. Don't consume the space, so a
|
|
42
|
+
// trailing two-space hard line break is still detected by the newline rule.
|
|
43
|
+
if (ch1 === 0x20) {
|
|
44
|
+
if (!silent) {
|
|
45
|
+
const token = state.push('text_special', '', 0)
|
|
46
|
+
token.content = '\\'
|
|
47
|
+
token.markup = '\\'
|
|
48
|
+
token.info = 'escape'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
state.pos = pos
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
|
|
41
55
|
let escapedStr = state.src[pos]
|
|
42
56
|
|
|
43
57
|
if (ch1 >= 0xD800 && ch1 <= 0xDBFF && pos + 1 < max) {
|
|
@@ -61,7 +75,7 @@ export default function escape (state, silent) {
|
|
|
61
75
|
}
|
|
62
76
|
|
|
63
77
|
token.markup = origStr
|
|
64
|
-
token.info
|
|
78
|
+
token.info = 'escape'
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
state.pos = pos + 1
|
|
@@ -42,7 +42,7 @@ export default function html_inline (state, silent) {
|
|
|
42
42
|
const token = state.push('html_inline', '', 0)
|
|
43
43
|
token.content = match[0]
|
|
44
44
|
|
|
45
|
-
if (isLinkOpen(token.content))
|
|
45
|
+
if (isLinkOpen(token.content)) state.linkLevel++
|
|
46
46
|
if (isLinkClose(token.content)) state.linkLevel--
|
|
47
47
|
}
|
|
48
48
|
state.pos += match[0].length
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Inline parser state
|
|
2
2
|
|
|
3
3
|
import Token from '../token.mjs'
|
|
4
|
-
import { isWhiteSpace,
|
|
4
|
+
import { isWhiteSpace, isPunctCharCode, isMdAsciiPunct } from '../common/utils.mjs'
|
|
5
5
|
|
|
6
6
|
function StateInline (src, md, env, outTokens) {
|
|
7
7
|
this.src = src
|
|
@@ -89,8 +89,30 @@ StateInline.prototype.scanDelims = function (start, canSplitWord) {
|
|
|
89
89
|
const max = this.posMax
|
|
90
90
|
const marker = this.src.charCodeAt(start)
|
|
91
91
|
|
|
92
|
-
//
|
|
93
|
-
|
|
92
|
+
// Astral characters below are combined manually, because .codePointAt()
|
|
93
|
+
// does not guarantee numeric type output. And we don't wish JIT cache issues.
|
|
94
|
+
// The broken surrogate pairs are evaluated as U+FFFD to prevent possible
|
|
95
|
+
// crashes.
|
|
96
|
+
|
|
97
|
+
let lastChar
|
|
98
|
+
if (start === 0) {
|
|
99
|
+
// treat beginning of the line as a whitespace
|
|
100
|
+
lastChar = 0x20
|
|
101
|
+
} else if (start === 1) {
|
|
102
|
+
lastChar = this.src.charCodeAt(0)
|
|
103
|
+
if ((lastChar & 0xF800) === 0xD800) { lastChar = 0xFFFD }
|
|
104
|
+
} else {
|
|
105
|
+
lastChar = this.src.charCodeAt(start - 1)
|
|
106
|
+
if ((lastChar & 0xFC00) === 0xDC00) {
|
|
107
|
+
// low surrogate => add high one, replace broken pair with U+FFFD
|
|
108
|
+
const highSurr = this.src.charCodeAt(start - 2)
|
|
109
|
+
lastChar = (highSurr & 0xFC00) === 0xD800
|
|
110
|
+
? 0x10000 + ((highSurr - 0xD800) << 10) + (lastChar - 0xDC00)
|
|
111
|
+
: 0xFFFD
|
|
112
|
+
} else if ((lastChar & 0xFC00) === 0xD800) {
|
|
113
|
+
lastChar = 0xFFFD
|
|
114
|
+
}
|
|
115
|
+
}
|
|
94
116
|
|
|
95
117
|
let pos = start
|
|
96
118
|
while (pos < max && this.src.charCodeAt(pos) === marker) { pos++ }
|
|
@@ -98,10 +120,19 @@ StateInline.prototype.scanDelims = function (start, canSplitWord) {
|
|
|
98
120
|
const count = pos - start
|
|
99
121
|
|
|
100
122
|
// treat end of the line as a whitespace
|
|
101
|
-
|
|
123
|
+
let nextChar = pos < max ? this.src.charCodeAt(pos) : 0x20
|
|
124
|
+
if ((nextChar & 0xFC00) === 0xD800) {
|
|
125
|
+
// high surrogate => add low one, replace broken pair with U+FFFD
|
|
126
|
+
const lowSurr = this.src.charCodeAt(pos + 1)
|
|
127
|
+
nextChar = (lowSurr & 0xFC00) === 0xDC00
|
|
128
|
+
? 0x10000 + ((nextChar - 0xD800) << 10) + (lowSurr - 0xDC00)
|
|
129
|
+
: 0xFFFD
|
|
130
|
+
} else if ((nextChar & 0xFC00) === 0xDC00) {
|
|
131
|
+
nextChar = 0xFFFD
|
|
132
|
+
}
|
|
102
133
|
|
|
103
|
-
const isLastPunctChar = isMdAsciiPunct(lastChar) ||
|
|
104
|
-
const isNextPunctChar = isMdAsciiPunct(nextChar) ||
|
|
134
|
+
const isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctCharCode(lastChar)
|
|
135
|
+
const isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctCharCode(nextChar)
|
|
105
136
|
|
|
106
137
|
const isLastWhiteSpace = isWhiteSpace(lastChar)
|
|
107
138
|
const isNextWhiteSpace = isWhiteSpace(nextChar)
|
|
@@ -111,8 +142,8 @@ StateInline.prototype.scanDelims = function (start, canSplitWord) {
|
|
|
111
142
|
const right_flanking =
|
|
112
143
|
!isLastWhiteSpace && (!isLastPunctChar || isNextWhiteSpace || isNextPunctChar)
|
|
113
144
|
|
|
114
|
-
const can_open
|
|
115
|
-
const can_close = right_flanking && (canSplitWord || !left_flanking
|
|
145
|
+
const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar)
|
|
146
|
+
const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar)
|
|
116
147
|
|
|
117
148
|
return { can_open, can_close, length: count }
|
|
118
149
|
}
|
|
@@ -20,13 +20,13 @@ function strikethrough_tokenize (state, silent) {
|
|
|
20
20
|
let token
|
|
21
21
|
|
|
22
22
|
if (len % 2) {
|
|
23
|
-
token
|
|
23
|
+
token = state.push('text', '', 0)
|
|
24
24
|
token.content = ch
|
|
25
25
|
len--
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
for (let i = 0; i < len; i += 2) {
|
|
29
|
-
token
|
|
29
|
+
token = state.push('text', '', 0)
|
|
30
30
|
token.content = ch + ch
|
|
31
31
|
|
|
32
32
|
state.delimiters.push({
|
|
@@ -62,18 +62,18 @@ function postProcess (state, delimiters) {
|
|
|
62
62
|
|
|
63
63
|
const endDelim = delimiters[startDelim.end]
|
|
64
64
|
|
|
65
|
-
token
|
|
66
|
-
token.type
|
|
67
|
-
token.tag
|
|
65
|
+
token = state.tokens[startDelim.token]
|
|
66
|
+
token.type = 's_open'
|
|
67
|
+
token.tag = 's'
|
|
68
68
|
token.nesting = 1
|
|
69
|
-
token.markup
|
|
69
|
+
token.markup = '~~'
|
|
70
70
|
token.content = ''
|
|
71
71
|
|
|
72
|
-
token
|
|
73
|
-
token.type
|
|
74
|
-
token.tag
|
|
72
|
+
token = state.tokens[endDelim.token]
|
|
73
|
+
token.type = 's_close'
|
|
74
|
+
token.tag = 's'
|
|
75
75
|
token.nesting = -1
|
|
76
|
-
token.markup
|
|
76
|
+
token.markup = '~~'
|
|
77
77
|
token.content = ''
|
|
78
78
|
|
|
79
79
|
if (state.tokens[endDelim.token - 1].type === 'text' &&
|
package/lib/token.mjs
CHANGED
|
@@ -15,28 +15,28 @@ function Token (type, tag, nesting) {
|
|
|
15
15
|
*
|
|
16
16
|
* Type of the token (string, e.g. "paragraph_open")
|
|
17
17
|
**/
|
|
18
|
-
this.type
|
|
18
|
+
this.type = type
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Token#tag -> String
|
|
22
22
|
*
|
|
23
23
|
* html tag name, e.g. "p"
|
|
24
24
|
**/
|
|
25
|
-
this.tag
|
|
25
|
+
this.tag = tag
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Token#attrs -> Array
|
|
29
29
|
*
|
|
30
30
|
* Html attributes. Format: `[ [ name1, value1 ], [ name2, value2 ] ]`
|
|
31
31
|
**/
|
|
32
|
-
this.attrs
|
|
32
|
+
this.attrs = null
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Token#map -> Array
|
|
36
36
|
*
|
|
37
37
|
* Source map info. Format: `[ line_begin, line_end ]`
|
|
38
38
|
**/
|
|
39
|
-
this.map
|
|
39
|
+
this.map = null
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Token#nesting -> Number
|
|
@@ -47,14 +47,14 @@ function Token (type, tag, nesting) {
|
|
|
47
47
|
* - `0` means the tag is self-closing
|
|
48
48
|
* - `-1` means the tag is closing
|
|
49
49
|
**/
|
|
50
|
-
this.nesting
|
|
50
|
+
this.nesting = nesting
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Token#level -> Number
|
|
54
54
|
*
|
|
55
55
|
* nesting level, the same as `state.level`
|
|
56
56
|
**/
|
|
57
|
-
this.level
|
|
57
|
+
this.level = 0
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Token#children -> Array
|
|
@@ -69,14 +69,14 @@ function Token (type, tag, nesting) {
|
|
|
69
69
|
* In a case of self-closing tag (code, html, fence, etc.),
|
|
70
70
|
* it has contents of this tag.
|
|
71
71
|
**/
|
|
72
|
-
this.content
|
|
72
|
+
this.content = ''
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* Token#markup -> String
|
|
76
76
|
*
|
|
77
77
|
* '*' or '_' for emphasis, fence string for fence, etc.
|
|
78
78
|
**/
|
|
79
|
-
this.markup
|
|
79
|
+
this.markup = ''
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* Token#info -> String
|
|
@@ -87,14 +87,14 @@ function Token (type, tag, nesting) {
|
|
|
87
87
|
* - The value "auto" for autolink "link_open" and "link_close" tokens
|
|
88
88
|
* - The string value of the item marker for ordered-list "list_item_open" tokens
|
|
89
89
|
**/
|
|
90
|
-
this.info
|
|
90
|
+
this.info = ''
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
93
|
* Token#meta -> Object
|
|
94
94
|
*
|
|
95
95
|
* A place for plugins to store an arbitrary data
|
|
96
96
|
**/
|
|
97
|
-
this.meta
|
|
97
|
+
this.meta = null
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
100
|
* Token#block -> Boolean
|
|
@@ -102,7 +102,7 @@ function Token (type, tag, nesting) {
|
|
|
102
102
|
* True for block-level tokens, false for inline tokens.
|
|
103
103
|
* Used in renderer to calculate line breaks
|
|
104
104
|
**/
|
|
105
|
-
this.block
|
|
105
|
+
this.block = false
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
108
|
* Token#hidden -> Boolean
|
|
@@ -110,7 +110,7 @@ function Token (type, tag, nesting) {
|
|
|
110
110
|
* If it's true, ignore this element when rendering. Used for tight lists
|
|
111
111
|
* to hide paragraphs.
|
|
112
112
|
**/
|
|
113
|
-
this.hidden
|
|
113
|
+
this.hidden = false
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
/**
|