@peaceroad/markdown-it-strong-ja 0.3.6 → 0.4.1
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 +0 -29
- package/index.js +277 -223
- package/package.json +1 -1
- package/test/example-complex.txt +145 -2
- package/test/mditNoAttrs/example-complex.txt +121 -2
- package/test/test.js +3 -4
package/README.md
CHANGED
|
@@ -153,32 +153,3 @@ a****
|
|
|
153
153
|
[HTML]
|
|
154
154
|
<p>a****</p>
|
|
155
155
|
~~~
|
|
156
|
-
|
|
157
|
-
---
|
|
158
|
-
|
|
159
|
-
Warning. Commonmark converts it as follows, but the current plugin cannot convert it. (It converts it based on the first *. I don't think it's that bad in terms of appearance...)
|
|
160
|
-
|
|
161
|
-
~~~
|
|
162
|
-
[Markdown]
|
|
163
|
-
z*<>*a*b
|
|
164
|
-
[HTML:false]
|
|
165
|
-
<p>z*<><em>a</em>b</p>
|
|
166
|
-
[HTML:true]
|
|
167
|
-
<p>z*<><em>a</em>b</p>
|
|
168
|
-
|
|
169
|
-
[Markdown]
|
|
170
|
-
z*<span>*a*b
|
|
171
|
-
[HTML:false]
|
|
172
|
-
<p>z*<span><em>a</em>b</p>
|
|
173
|
-
[HTML:true]
|
|
174
|
-
<p>z*<span><em>a</em>b</p>
|
|
175
|
-
|
|
176
|
-
[Markdown]
|
|
177
|
-
z*<span>*a*b</span>
|
|
178
|
-
[HTML:false]
|
|
179
|
-
<p>z*<span><em>a</em>b</span></p>
|
|
180
|
-
[HTML:true]
|
|
181
|
-
<p>z*<span><em>a</em>b</span></p>
|
|
182
|
-
~~~
|
|
183
|
-
|
|
184
|
-
---
|
package/index.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
+
const REG_ASTERISKS = /^\*+$/
|
|
2
|
+
const REG_ATTRS = /{[^{}\n!@#%^&*()]+?}$/
|
|
3
|
+
const REG_PUNCTUATION = /[!-/:-@[-`{-~ ]/
|
|
4
|
+
const REG_JAPANESE = /[\u3040-\u309F\u30A0-\u30FF\u4E00-\u9FFF\uFF66-\uFF9F\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF01-\uFF60\uFFE0-\uFFE6]/ //漢字、ひらがな、カタカナ(半角含む)、全角英数字、絵文字、全角記号:/(?:[\p{Hiragana}\p{Katakana}\p{Han}]|[\uFF66-\uFF9F]|[A-Za-z0-9]|[\p{Emoji}]|[\uFF01-\uFF60\uFFE0-\uFFE6])/u;/(?:[\p{Hiragana}\p{Katakana}\p{Han}]|[\uFF66-\uFF9F]|[A-Za-z0-9]|[\p{Emoji}])/u
|
|
5
|
+
|
|
1
6
|
const hasBackslash = (state, start) => {
|
|
2
7
|
let slashNum = 0
|
|
3
8
|
let i = start - 1
|
|
9
|
+
const src = state.src
|
|
4
10
|
while(i >= 0) {
|
|
5
|
-
if (
|
|
11
|
+
if (src.charCodeAt(i) === 0x5C) { slashNum++; i--; continue }
|
|
6
12
|
break
|
|
7
13
|
}
|
|
8
|
-
return slashNum % 2 === 1
|
|
14
|
+
return slashNum % 2 === 1
|
|
9
15
|
}
|
|
10
16
|
|
|
11
17
|
const setToken = (state, inlines, opt) => {
|
|
18
|
+
const src = state.src
|
|
12
19
|
let i = 0
|
|
13
20
|
let attrsIsText = {
|
|
14
21
|
val: false,
|
|
@@ -32,9 +39,9 @@ const setToken = (state, inlines, opt) => {
|
|
|
32
39
|
type = 'text'
|
|
33
40
|
}
|
|
34
41
|
if (type === 'text') {
|
|
35
|
-
let content =
|
|
42
|
+
let content = src.slice(inlines[i].s, inlines[i].e + 1)
|
|
36
43
|
//console.log('content: ' + content)
|
|
37
|
-
if (
|
|
44
|
+
if (REG_ASTERISKS.test(content)) {
|
|
38
45
|
//console.log('asterisk process::')
|
|
39
46
|
const asteriskToken = state.push(type, '', 0)
|
|
40
47
|
asteriskToken.content = content
|
|
@@ -44,7 +51,7 @@ const setToken = (state, inlines, opt) => {
|
|
|
44
51
|
if (opt.mditAttrs && attrsIsText.val && i + 1 < inlines.length) {
|
|
45
52
|
const hasImmediatelyAfterAsteriskClose = inlines[i+1].type === attrsIsText.tag + '_close'
|
|
46
53
|
//console.log(hasImmediatelyAfterAsteriskClose, inlines[i+1].type, /^[\s\S]*{[^{}\n!@#%^&*()]+?}$/.test(content))
|
|
47
|
-
if (hasImmediatelyAfterAsteriskClose &&
|
|
54
|
+
if (hasImmediatelyAfterAsteriskClose && REG_ATTRS.test(content)) {
|
|
48
55
|
const attrsToken = state.push(type, '', 0)
|
|
49
56
|
|
|
50
57
|
const hasBackslashBeforeCurlyAttribute = content.match(/(\\+){/)
|
|
@@ -116,7 +123,7 @@ const setToken = (state, inlines, opt) => {
|
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
125
|
|
|
119
|
-
const
|
|
126
|
+
const pushInlines = (inlines, s, e, len, type, tag, tagType) => {
|
|
120
127
|
const inline = {
|
|
121
128
|
s: s,
|
|
122
129
|
sp: s,
|
|
@@ -124,6 +131,7 @@ const inlinesPush = (inlines, s, e, len, type, tag, tagType) => {
|
|
|
124
131
|
ep: e,
|
|
125
132
|
len: len,
|
|
126
133
|
type: type,
|
|
134
|
+
check: type === 'text' ? true : false,
|
|
127
135
|
}
|
|
128
136
|
if (tag) inline.tag = [tag, tagType]
|
|
129
137
|
inlines.push(inline)
|
|
@@ -131,13 +139,14 @@ const inlinesPush = (inlines, s, e, len, type, tag, tagType) => {
|
|
|
131
139
|
|
|
132
140
|
const hasNextSymbol = (state, n, max, symbol, noMark) => {
|
|
133
141
|
let nextSymbolPos = -1
|
|
134
|
-
|
|
142
|
+
const src = state.src
|
|
143
|
+
if (src.charCodeAt(n) === symbol && !hasBackslash(state, n)) {
|
|
135
144
|
let i = n + 1
|
|
136
145
|
let tempNoMark = noMark
|
|
137
146
|
while (i < max) {
|
|
138
|
-
tempNoMark +=
|
|
139
|
-
if (
|
|
140
|
-
noMark +=
|
|
147
|
+
tempNoMark += src[i]
|
|
148
|
+
if (src.charCodeAt(i) === symbol && !hasBackslash(state, i)) {
|
|
149
|
+
noMark += src.substring(n, i + 1)
|
|
141
150
|
nextSymbolPos = i
|
|
142
151
|
break
|
|
143
152
|
}
|
|
@@ -148,27 +157,29 @@ const hasNextSymbol = (state, n, max, symbol, noMark) => {
|
|
|
148
157
|
}
|
|
149
158
|
|
|
150
159
|
const createInlines = (state, start, max, opt) => {
|
|
160
|
+
const src = state.src
|
|
161
|
+
const srcLen = max;
|
|
151
162
|
let n = start
|
|
152
163
|
let inlines = []
|
|
153
164
|
let noMark = ''
|
|
154
165
|
let textStart = n
|
|
155
|
-
while (n <
|
|
166
|
+
while (n < srcLen) {
|
|
156
167
|
//console.log('n: ' + n + ', state.src[n]: ' + state.src[n] + ', noMark: ' + noMark)
|
|
157
168
|
let nextSymbolPos = -1;
|
|
158
|
-
[nextSymbolPos, noMark] = hasNextSymbol(state, n,
|
|
169
|
+
[nextSymbolPos, noMark] = hasNextSymbol(state, n, srcLen, 0x60, noMark) // '`'
|
|
159
170
|
if (nextSymbolPos !== -1) {
|
|
160
|
-
if (nextSymbolPos ===
|
|
161
|
-
|
|
171
|
+
if (nextSymbolPos === srcLen - 1) {
|
|
172
|
+
pushInlines(inlines, textStart, nextSymbolPos, nextSymbolPos - textStart + 1, 'text')
|
|
162
173
|
break
|
|
163
174
|
}
|
|
164
175
|
n = nextSymbolPos + 1
|
|
165
176
|
continue
|
|
166
177
|
}
|
|
167
178
|
if (opt.dollarMath) {
|
|
168
|
-
[nextSymbolPos, noMark] = hasNextSymbol(state, n,
|
|
179
|
+
[nextSymbolPos, noMark] = hasNextSymbol(state, n, srcLen, 0x24, noMark) // '$'
|
|
169
180
|
if (nextSymbolPos !== -1) {
|
|
170
|
-
if (nextSymbolPos ===
|
|
171
|
-
|
|
181
|
+
if (nextSymbolPos === srcLen - 1) {
|
|
182
|
+
pushInlines(inlines, textStart, nextSymbolPos, nextSymbolPos - textStart + 1, 'text')
|
|
172
183
|
break
|
|
173
184
|
}
|
|
174
185
|
n = nextSymbolPos + 1
|
|
@@ -177,16 +188,15 @@ const createInlines = (state, start, max, opt) => {
|
|
|
177
188
|
}
|
|
178
189
|
|
|
179
190
|
if (state.md.options.html) {
|
|
180
|
-
if (
|
|
191
|
+
if (src.charCodeAt(n) === 0x3C && !hasBackslash(state, n)) { // '<'
|
|
181
192
|
let i = n + 1
|
|
182
|
-
while (i <
|
|
183
|
-
if (
|
|
193
|
+
while (i < srcLen) {
|
|
194
|
+
if (src.charCodeAt(i) === 0x3E && !hasBackslash(state, i)) { // '>'
|
|
184
195
|
if (noMark.length !== 0) {
|
|
185
|
-
|
|
186
|
-
inlinesPush(inlines, textStart, n - 1, n - textStart, 'text')
|
|
196
|
+
pushInlines(inlines, textStart, n - 1, n - textStart, 'text')
|
|
187
197
|
noMark = ''
|
|
188
198
|
}
|
|
189
|
-
let tag =
|
|
199
|
+
let tag = src.slice(n + 1, i)
|
|
190
200
|
let tagType = ''
|
|
191
201
|
if (/^\//.test(tag)) {
|
|
192
202
|
tag = tag.slice(1)
|
|
@@ -194,7 +204,7 @@ const createInlines = (state, start, max, opt) => {
|
|
|
194
204
|
} else {
|
|
195
205
|
tagType = 'open'
|
|
196
206
|
}
|
|
197
|
-
|
|
207
|
+
pushInlines(inlines, n, i, i - n + 1, 'html_inline', tag, tagType)
|
|
198
208
|
textStart = i + 1
|
|
199
209
|
break
|
|
200
210
|
}
|
|
@@ -205,32 +215,23 @@ const createInlines = (state, start, max, opt) => {
|
|
|
205
215
|
}
|
|
206
216
|
}
|
|
207
217
|
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
inlinesPush(inlines, textStart, n, n - textStart + 1, 'text')
|
|
212
|
-
noMark = ''
|
|
213
|
-
n++
|
|
214
|
-
textStart = n
|
|
215
|
-
continue
|
|
216
|
-
}*/
|
|
217
|
-
if (n !== 0) {
|
|
218
|
-
//Add text before asterisk to inlines
|
|
219
|
-
inlinesPush(inlines, textStart, n - 1, n - textStart, 'text')
|
|
218
|
+
if (src.charCodeAt(n) === 0x2A && !hasBackslash(state, n)) { // '*'
|
|
219
|
+
if (n !== 0 && noMark.length !== 0) {
|
|
220
|
+
pushInlines(inlines, textStart, n - 1, n - textStart, 'text')
|
|
220
221
|
noMark = ''
|
|
221
222
|
}
|
|
222
|
-
if (n ===
|
|
223
|
-
|
|
223
|
+
if (n === srcLen - 1) {
|
|
224
|
+
pushInlines(inlines, n, n, 1 , '')
|
|
224
225
|
break
|
|
225
226
|
}
|
|
226
227
|
let i = n + 1
|
|
227
|
-
while (i <
|
|
228
|
-
if (
|
|
229
|
-
if (i ===
|
|
228
|
+
while (i < srcLen) {
|
|
229
|
+
if (src.charCodeAt(i) === 0x2A) {
|
|
230
|
+
if (i === srcLen - 1) pushInlines(inlines, n, i, i - n + 1 , '')
|
|
230
231
|
i++
|
|
231
232
|
continue
|
|
232
233
|
}
|
|
233
|
-
|
|
234
|
+
pushInlines(inlines, n, i - 1, i - n, '')
|
|
234
235
|
textStart = i
|
|
235
236
|
break
|
|
236
237
|
}
|
|
@@ -238,9 +239,9 @@ const createInlines = (state, start, max, opt) => {
|
|
|
238
239
|
continue
|
|
239
240
|
}
|
|
240
241
|
|
|
241
|
-
noMark +=
|
|
242
|
-
if (n ===
|
|
243
|
-
|
|
242
|
+
noMark += src[n]
|
|
243
|
+
if (n === srcLen - 1) {
|
|
244
|
+
pushInlines(inlines, textStart, n, n - textStart + 1, 'text')
|
|
244
245
|
break
|
|
245
246
|
}
|
|
246
247
|
n++
|
|
@@ -248,176 +249,202 @@ const createInlines = (state, start, max, opt) => {
|
|
|
248
249
|
return inlines
|
|
249
250
|
}
|
|
250
251
|
|
|
251
|
-
const
|
|
252
|
-
//
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
s
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
let i = marks.findIndex(o => o.s > s)
|
|
263
|
-
if (i === -1) {
|
|
264
|
-
marks.push(np)
|
|
265
|
-
} else {
|
|
266
|
-
marks.splice(i, 0, np)
|
|
252
|
+
const pushMark = (marks, opts) => {
|
|
253
|
+
//binary search
|
|
254
|
+
let left = 0, right = marks.length
|
|
255
|
+
while (left < right) {
|
|
256
|
+
const mid = (left + right) >> 1
|
|
257
|
+
if (marks[mid].s > opts.s) {
|
|
258
|
+
right = mid
|
|
259
|
+
} else {
|
|
260
|
+
left = mid + 1
|
|
261
|
+
}
|
|
267
262
|
}
|
|
263
|
+
marks.splice(left, 0, { ...opts });
|
|
268
264
|
}
|
|
269
265
|
|
|
270
266
|
const setStrong = (state, inlines, marks, n, memo, opt) => {
|
|
271
267
|
let i = n + 1
|
|
272
268
|
let j = 0
|
|
273
269
|
let nest = 0
|
|
274
|
-
let insideTagsIsClose = 1
|
|
275
|
-
let prevHtmlTags = {...memo.htmlTags}
|
|
270
|
+
let insideTagsIsClose = 1 // 1: closed, 0: open still, -1: error
|
|
276
271
|
while (i < inlines.length) {
|
|
277
|
-
|
|
278
|
-
if (
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
272
|
+
//console.log('[strong] i: ' + i + ', inlines[i].len: ' + inlines[i].len + ', inlines[i].type: ' + inlines[i].type)
|
|
273
|
+
if (inlines[i].len === 0 || inlines[i].check) { i++; continue }
|
|
274
|
+
if (inlines[i].type === 'html_inline') {
|
|
275
|
+
inlines[i].check = true
|
|
276
|
+
insideTagsIsClose = checkInsideTags(inlines, i, memo)
|
|
277
|
+
//console.log(' nest: ' + nest + ', insideTagsIsClose: ' + insideTagsIsClose )
|
|
278
|
+
if (insideTagsIsClose === -1) return n, nest
|
|
279
|
+
if (insideTagsIsClose === 0) { i++; continue }
|
|
285
280
|
}
|
|
286
281
|
if (inlines[i].type !== '') { i++; continue }
|
|
287
282
|
|
|
288
|
-
//console.log('n: ' + n + ' [strong]: inlines[n].len: ' + inlines[n].len + ', i: ' + i + ', inlines[i].len: ' + inlines[i].len)
|
|
289
|
-
|
|
290
283
|
nest = checkNest(inlines, marks, n, i)
|
|
291
|
-
//console.log('
|
|
292
|
-
if (nest === -1) return n, nest
|
|
284
|
+
//console.log(' check nest: ' + nest)
|
|
285
|
+
if (nest === -1) return n, nest
|
|
286
|
+
|
|
293
287
|
if (inlines[i].len === 1 && inlines[n].len > 2) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
288
|
+
//console.log(' check em inside strong:: i: ' + i)
|
|
289
|
+
pushMark(marks, {
|
|
290
|
+
nest: nest,
|
|
291
|
+
s: inlines[n].ep,
|
|
292
|
+
e: inlines[n].ep,
|
|
293
|
+
len: 1,
|
|
294
|
+
oLen: inlines[n].len - 1,
|
|
295
|
+
type: 'em_open'
|
|
296
|
+
})
|
|
297
|
+
pushMark(marks, {
|
|
298
|
+
nest: nest,
|
|
299
|
+
s: inlines[i].sp,
|
|
300
|
+
e: inlines[i].ep,
|
|
301
|
+
len: 1,
|
|
302
|
+
oLen: inlines[i].len - 1,
|
|
303
|
+
type: 'em_close'
|
|
304
|
+
})
|
|
297
305
|
inlines[n].len -= 1
|
|
298
306
|
inlines[n].ep -= 1
|
|
299
|
-
inlines[i].len
|
|
300
|
-
inlines[i].sp += 1
|
|
301
|
-
if (
|
|
302
|
-
|
|
303
|
-
nest++
|
|
304
|
-
} else {
|
|
305
|
-
return n, nest, memo
|
|
307
|
+
inlines[i].len -= 1
|
|
308
|
+
if (inlines[i].len > 0) inlines[i].sp += 1
|
|
309
|
+
if (insideTagsIsClose === 1) {
|
|
310
|
+
n, nest = setEm(state, inlines, marks, n, memo, opt)
|
|
306
311
|
}
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
//console.log('memo.html: ' + memo.html + 'insideTagsIsClose: ' + insideTagsIsClose + 'inlines[i].len: ' + inlines[i].len)
|
|
311
|
-
//if (memo.html && !insideTagsIsClose && inlines[i].len !== 1) {
|
|
312
|
-
if (memo.html && inlines[i].len < 2) {
|
|
313
|
-
i++; continue;
|
|
312
|
+
//console.log(marks)
|
|
314
313
|
}
|
|
315
|
-
|
|
314
|
+
//console.log(' check len:: inlines[n].len: ' + inlines[n].len + ', inlines[i].len: ' + inlines[i].len)
|
|
316
315
|
let strongNum = Math.trunc(Math.min(inlines[n].len, inlines[i].len) / 2)
|
|
317
316
|
|
|
318
317
|
if (inlines[i].len > 1) {
|
|
319
|
-
//console.log('
|
|
318
|
+
//console.log(' hasPunctuationOrNonJapanese: ' + hasPunctuationOrNonJapanese(state, inlines, n, i) + ', memo.inlineMarkEnd: ' + memo.inlineMarkEnd)
|
|
319
|
+
|
|
320
|
+
if (hasPunctuationOrNonJapanese(state, inlines, n, i)) {
|
|
321
|
+
if (memo.inlineMarkEnd) {
|
|
322
|
+
//console.log('check nest em.')
|
|
323
|
+
//console.log('~~~~~~~~~~~~~~~~~')
|
|
324
|
+
marks.push(...createMarks(state, inlines, i, inlines.length - 1, memo, opt))
|
|
325
|
+
//console.log('~~~~~~~~~~~~~~~~~')
|
|
326
|
+
if (inlines[i].len === 0) { i++; continue }
|
|
327
|
+
} else {
|
|
328
|
+
return n, nest
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
//console.log(' ===> strong normal push. n: ' + n + ', i: ' + i + ' , nest: ' + nest + ',strongNum: ' + strongNum)
|
|
332
|
+
|
|
320
333
|
j = 0
|
|
321
334
|
while (j < strongNum) {
|
|
322
|
-
//console.log('j: ' + j + ', inlines[i].sp: ' + inlines[i].sp)
|
|
323
|
-
|
|
335
|
+
//console.log(' - j: ' + j + ', inlines[i].sp: ' + inlines[i].sp)
|
|
336
|
+
pushMark(marks, {
|
|
337
|
+
nest: nest + strongNum - 1 - j,
|
|
338
|
+
s: inlines[n].ep - 1,
|
|
339
|
+
e: inlines[n].ep,
|
|
340
|
+
len: 2,
|
|
341
|
+
oLen: inlines[n].len - 2,
|
|
342
|
+
type: 'strong_open'
|
|
343
|
+
})
|
|
324
344
|
inlines[n].ep -= 2
|
|
325
345
|
inlines[n].len -= 2
|
|
326
|
-
|
|
346
|
+
pushMark(marks, {
|
|
347
|
+
nest: nest + strongNum - 1 - j,
|
|
348
|
+
s: inlines[i].sp,
|
|
349
|
+
e: inlines[i].sp + 1,
|
|
350
|
+
len: 2,
|
|
351
|
+
oLen: inlines[i].len - 2,
|
|
352
|
+
type: 'strong_close'
|
|
353
|
+
})
|
|
327
354
|
inlines[i].sp += 2
|
|
328
355
|
inlines[i].len -= 2
|
|
329
|
-
//console.log(marks)
|
|
330
356
|
j++
|
|
331
357
|
}
|
|
332
|
-
if (inlines[n].len === 0) return n, nest
|
|
358
|
+
if (inlines[n].len === 0) return n, nest
|
|
333
359
|
}
|
|
334
360
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
//console.log('check em that warp strong.')
|
|
361
|
+
if (inlines[n].len === 1 && inlines[i].len > 0) {
|
|
362
|
+
//console.log(' check em that warp strong.')
|
|
338
363
|
nest++
|
|
339
|
-
n, nest
|
|
340
|
-
if (memo.hasEmThatWrapStrong) {
|
|
341
|
-
//console.log('set em that wrap strong.')
|
|
342
|
-
let k = 0
|
|
343
|
-
while (k < strongNum) {
|
|
344
|
-
marks[marks.length - 2 - k * 2 - 1].nest += 1
|
|
345
|
-
marks[marks.length - 2 - k * 2].nest += 1
|
|
346
|
-
k++
|
|
347
|
-
}
|
|
348
|
-
}
|
|
364
|
+
n, nest = setEm(state, inlines, marks, n, memo, opt, nest)
|
|
349
365
|
}
|
|
350
|
-
|
|
366
|
+
|
|
351
367
|
i++
|
|
352
368
|
}
|
|
353
|
-
|
|
369
|
+
|
|
370
|
+
if (n == 0 && memo.inlineMarkEnd) {
|
|
371
|
+
//console.log('check nest em(inlineMarkEnd).')
|
|
372
|
+
//console.log('===============================')
|
|
373
|
+
marks.push(...createMarks(state, inlines, n + 1 , inlines.length - 1, memo, opt))
|
|
374
|
+
//console.log(marks)
|
|
375
|
+
//console.log('===============================')
|
|
376
|
+
}
|
|
377
|
+
return n, nest
|
|
354
378
|
}
|
|
355
379
|
|
|
356
|
-
const
|
|
357
|
-
//console.log(
|
|
358
|
-
if (inlines[
|
|
359
|
-
|
|
360
|
-
|
|
380
|
+
const checkInsideTags = (inlines, i, memo) => {
|
|
381
|
+
//console.log('isJumTag before::memo.htmlTags: ' + JSON.stringify(memo.htmlTags))
|
|
382
|
+
if (inlines[i].tag === undefined) return 0
|
|
383
|
+
const tagName = inlines[i].tag[0].toLowerCase()
|
|
384
|
+
if (memo.htmlTags[tagName] === undefined) {
|
|
385
|
+
memo.htmlTags[tagName] = 0
|
|
361
386
|
}
|
|
362
|
-
//console.log('
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
memo.htmlTags[inlines[n].tag[0]] += 1
|
|
387
|
+
//console.log('memo.htmlTags: ' + JSON.stringify(memo.htmlTags) + ', inlines[i]: ' + JSON.stringify(inlines[i]) + ', inlines[i]')
|
|
388
|
+
if (inlines[i].tag[1] === 'open') {
|
|
389
|
+
memo.htmlTags[tagName] += 1
|
|
366
390
|
}
|
|
367
|
-
if (inlines[
|
|
368
|
-
memo.htmlTags[
|
|
391
|
+
if (inlines[i].tag[1] === 'close') {
|
|
392
|
+
memo.htmlTags[tagName] -= 1
|
|
369
393
|
}
|
|
370
|
-
//console.log('
|
|
371
|
-
|
|
372
|
-
if (prevHtmlTags[inlines[n].tag[0]] === undefined) prevHtmlTags[inlines[n].tag[0]] = 0
|
|
373
|
-
if (memo.htmlTags[inlines[n].tag[0]] < prevHtmlTags[inlines[n].tag[0]]) {
|
|
394
|
+
//console.log(' i: ' + i + ', tagName: ' + tagName + ', memo.htmlTags[tagName]: ' + memo.htmlTags[tagName] + ', prevHtmlTags[tagName]: ' + prevHtmlTags[tagName])
|
|
395
|
+
if (memo.htmlTags[tagName] < 0) {
|
|
374
396
|
return -1
|
|
375
397
|
}
|
|
376
|
-
//console.log(
|
|
398
|
+
//console.log('isJumTag after::memo.htmlTags: ' + JSON.stringify(memo.htmlTags))
|
|
377
399
|
const closeAllTags = Object.values(memo.htmlTags).every(val => val === 0)
|
|
378
|
-
//console.log('closeAllTags: ' + closeAllTags)
|
|
379
400
|
if (closeAllTags) return 1
|
|
380
|
-
// if (inlines[n].tag[1] === 'close') return -1
|
|
381
|
-
//memo.htmlTags = {}
|
|
382
401
|
return 0
|
|
383
402
|
}
|
|
384
403
|
|
|
404
|
+
const isPunctuation = (ch) => {
|
|
405
|
+
return REG_PUNCTUATION.test(ch)
|
|
406
|
+
}
|
|
407
|
+
const isJapanese = (ch) => {
|
|
408
|
+
return REG_JAPANESE.test(ch)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const hasPunctuationOrNonJapanese = (state, inlines, n, i) => {
|
|
412
|
+
const src = state.src
|
|
413
|
+
const openPrevChar = src[inlines[n].s - 1] || ''
|
|
414
|
+
//const checkOpenPrevChar =
|
|
415
|
+
const openNextChar = src[inlines[n].e + 1] || ''
|
|
416
|
+
const checkOpenNextChar = isPunctuation(openNextChar)
|
|
417
|
+
const closePrevChar = src[inlines[i].s - 1] || ''
|
|
418
|
+
const checkClosePrevChar = isPunctuation(closePrevChar)
|
|
419
|
+
const closeNextChar = src[inlines[i].e + 1] || ''
|
|
420
|
+
const checkCloseNextChar = (isPunctuation(closeNextChar) || i === inlines.length - 1)
|
|
421
|
+
if ((checkOpenNextChar || checkClosePrevChar) && !checkCloseNextChar && !(isJapanese(openPrevChar) || isJapanese(closeNextChar))) return true
|
|
422
|
+
return false
|
|
423
|
+
}
|
|
424
|
+
|
|
385
425
|
const setEm = (state, inlines, marks, n, memo, opt, sNest) => {
|
|
386
426
|
let i = n + 1
|
|
387
427
|
let nest = 0
|
|
388
428
|
let strongPNum = 0
|
|
389
|
-
let insideTagsIsClose = 1
|
|
390
|
-
let prevHtmlTags = {...memo.htmlTags}
|
|
391
|
-
//console.log('memo.prevHtmlTags: ' + JSON.stringify(memo.prevHtmlTags))
|
|
429
|
+
let insideTagsIsClose = 1
|
|
392
430
|
while (i < inlines.length) {
|
|
393
|
-
//console.log('i: ' + i + ', src: ' + state.src.slice(inlines[i].sp, inlines[i].ep + 1) + ', inlines[i]: ' + JSON.stringify(inlines[i]))
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
if (
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
431
|
+
//console.log('[em] i: ' + i + ', src: ' + state.src.slice(inlines[i].sp, inlines[i].ep + 1) + ', inlines[i]: ' + JSON.stringify(inlines[i]))
|
|
432
|
+
//console.log(inlines[i].type, JSON.stringify(memo.htmlTags))
|
|
433
|
+
if (inlines[i].len === 0 || inlines[i].check) { i++; continue }
|
|
434
|
+
if (!sNest && inlines[i].type === 'html_inline') {
|
|
435
|
+
inlines.check = true
|
|
436
|
+
insideTagsIsClose = checkInsideTags(inlines, i, memo)
|
|
437
|
+
//console.log(' i: ' + i + ', insideTagsIsClose: ' + insideTagsIsClose)
|
|
438
|
+
if (insideTagsIsClose === -1) return n, nest
|
|
439
|
+
if (insideTagsIsClose === 0) { i++; continue }
|
|
403
440
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
441
|
if (inlines[i].type !== '') { i++; continue }
|
|
407
442
|
|
|
408
443
|
const emNum = Math.min(inlines[n].len, inlines[i].len)
|
|
409
|
-
if (memo.isEm && emNum !== 1) return n, sNest, memo
|
|
410
|
-
//console.log('n: ' + n + ' [em]: inlines[n].len: ' + inlines[n].len + ', i: ' + i, ', inlines[i].len: ' + inlines[i].len + ', isEm: ' + memo.isEm)
|
|
411
|
-
//console.log(marks)
|
|
412
444
|
|
|
413
|
-
|
|
414
|
-
if (
|
|
415
|
-
|
|
416
|
-
if (/{[^{}\n!@#%^&*()]+?}$/.test(checkText)) {
|
|
417
|
-
curlyProcess = true
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
//if (memo.isEm && !curlyProcess && inlines[i].len === 2 && !memo.inlineMarkStart) {
|
|
445
|
+
//console.log('sNest: ' + sNest + ', emNum: ' + emNum)
|
|
446
|
+
if (!sNest && emNum !== 1) return n, sNest, memo
|
|
447
|
+
|
|
421
448
|
const hasMarkersAtStartAndEnd = (i) => {
|
|
422
449
|
let flag = memo.inlineMarkStart
|
|
423
450
|
if (!flag) return false
|
|
@@ -426,7 +453,7 @@ const setEm = (state, inlines, marks, n, memo, opt, sNest) => {
|
|
|
426
453
|
inlines[i].len > 1 ? flag = true : flag = false
|
|
427
454
|
return flag
|
|
428
455
|
}
|
|
429
|
-
if (
|
|
456
|
+
if (!sNest && inlines[i].len === 2 && !hasMarkersAtStartAndEnd(i)) {
|
|
430
457
|
strongPNum++
|
|
431
458
|
i++
|
|
432
459
|
continue
|
|
@@ -437,44 +464,83 @@ const setEm = (state, inlines, marks, n, memo, opt, sNest) => {
|
|
|
437
464
|
} else {
|
|
438
465
|
nest = checkNest(inlines, marks, n, i)
|
|
439
466
|
}
|
|
440
|
-
//console.log('
|
|
441
|
-
if (nest === -1) return n, nest
|
|
467
|
+
//console.log(' nest: ' + nest + ', emNum: ' + emNum)
|
|
468
|
+
if (nest === -1) return n, nest
|
|
442
469
|
|
|
443
470
|
if (emNum === 1) {
|
|
444
|
-
//console.log(
|
|
445
|
-
if (
|
|
471
|
+
//console.log(' hasPunctuationOrNonJapanese: ' + hasPunctuationOrNonJapanese(state, inlines, n, i) + ', memo.inlineMarkEnd: ' + memo.inlineMarkEnd)
|
|
472
|
+
if (hasPunctuationOrNonJapanese(state, inlines, n, i)) {
|
|
473
|
+
if (memo.inlineMarkEnd) {
|
|
474
|
+
//console.log('check nest em.')
|
|
475
|
+
//console.log('~~~~~~~~~~~~~~~~~')
|
|
476
|
+
marks.push(...createMarks(state, inlines, i, inlines.length - 1, memo, opt))
|
|
477
|
+
//console.log('~~~~~~~~~~~~~~~~~')
|
|
478
|
+
|
|
479
|
+
if (inlines[i].len === 0) { i++; continue }
|
|
480
|
+
} else {
|
|
481
|
+
return n, nest
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
//console.log('inlines[i].len: ' + inlines[i].len)
|
|
485
|
+
if (inlines[i].len < 1) { // memo.html
|
|
446
486
|
i++; continue;
|
|
447
487
|
}
|
|
448
488
|
|
|
449
|
-
//console.log('n: ' + n +
|
|
489
|
+
//console.log(' ===> em Normal push. n: ' + n + ', i: ' + i + ', nest: ' + nest, ', strongPNum: ' + strongPNum)
|
|
450
490
|
//console.log(inlines[n].ep, inlines[n].sp, inlines[n].s)
|
|
451
|
-
|
|
452
|
-
|
|
491
|
+
pushMark(marks, {
|
|
492
|
+
nest: nest,
|
|
493
|
+
s: inlines[n].ep,
|
|
494
|
+
e: inlines[n].ep,
|
|
495
|
+
len: 1,
|
|
496
|
+
oLen: inlines[n].len - 1,
|
|
497
|
+
type: 'em_open'
|
|
498
|
+
})
|
|
453
499
|
inlines[n].ep -= 1
|
|
454
500
|
inlines[n].len -= 1
|
|
455
501
|
|
|
456
502
|
if (strongPNum % 2 === 0 || inlines[i].len < 2) {
|
|
457
|
-
|
|
503
|
+
pushMark(marks, {
|
|
504
|
+
nest: nest,
|
|
505
|
+
s: inlines[i].sp,
|
|
506
|
+
e: inlines[i].sp,
|
|
507
|
+
len: 1,
|
|
508
|
+
oLen: inlines[i].len - 1,
|
|
509
|
+
type: 'em_close'
|
|
510
|
+
})
|
|
458
511
|
inlines[i].sp += 1
|
|
459
512
|
} else {
|
|
460
|
-
|
|
513
|
+
pushMark(marks, {
|
|
514
|
+
nest: nest,
|
|
515
|
+
s: inlines[i].ep,
|
|
516
|
+
e: inlines[i].ep,
|
|
517
|
+
len: 1,
|
|
518
|
+
oLen: inlines[i].len - 1,
|
|
519
|
+
type: 'em_close'
|
|
520
|
+
})
|
|
461
521
|
inlines[i].sp = inlines[i].ep - 1
|
|
462
522
|
inlines[i].ep -= 1
|
|
463
523
|
}
|
|
464
524
|
inlines[i].len -= 1
|
|
465
525
|
//console.log(marks)
|
|
466
|
-
if (
|
|
467
|
-
if (inlines[n].len === 0) return n, nest, memo
|
|
526
|
+
if (inlines[n].len === 0) return n, nest
|
|
468
527
|
}
|
|
469
528
|
|
|
470
529
|
i++
|
|
471
530
|
}
|
|
472
|
-
return n, nest
|
|
531
|
+
return n, nest
|
|
473
532
|
}
|
|
474
533
|
|
|
475
534
|
const setText = (inlines, marks, n, nest) => {
|
|
476
535
|
//console.log('n: ' + n + ' [text]: inlines[n].len: ' + inlines[n].len)
|
|
477
|
-
|
|
536
|
+
pushMark(marks, {
|
|
537
|
+
nest: nest,
|
|
538
|
+
s: inlines[n].sp,
|
|
539
|
+
e: inlines[n].ep,
|
|
540
|
+
len: inlines[n].len,
|
|
541
|
+
oLen: -1,
|
|
542
|
+
type: 'text'
|
|
543
|
+
})
|
|
478
544
|
inlines[n].len = 0
|
|
479
545
|
}
|
|
480
546
|
|
|
@@ -503,7 +569,6 @@ const checkNest = (inlines, marks, n, i) => {
|
|
|
503
569
|
if (parentCloseN < marks.length) {
|
|
504
570
|
while (parentCloseN < marks.length) {
|
|
505
571
|
if (marks[parentCloseN].nest === parentNest) break
|
|
506
|
-
//if (marks.length - 1 == parentCloseN) break
|
|
507
572
|
parentCloseN++
|
|
508
573
|
}
|
|
509
574
|
//console.log('parentCloseN: ' + parentCloseN)
|
|
@@ -528,71 +593,66 @@ const createMarks = (state, inlines, start, end, memo, opt) => {
|
|
|
528
593
|
let marks = []
|
|
529
594
|
let n = start
|
|
530
595
|
while (n < end) {
|
|
531
|
-
if (inlines[n].type !== ''
|
|
532
|
-
memo.isEm = inlines[n].len === 1 ? true : false
|
|
533
|
-
memo.wrapEm = 0
|
|
596
|
+
if (inlines[n].type !== '') { n++; continue }
|
|
534
597
|
let nest = 0
|
|
535
|
-
|
|
536
|
-
if (
|
|
537
|
-
n, nest
|
|
598
|
+
//console.log('n: ' + n + ' ----- inlines:: src: ' + state.src.slice(inlines[n].sp, inlines[n].ep + 1) + ', inlines[n].sp: ' + inlines[n].sp + ', inlines[n].len: ' + inlines[n].len + ', memo.isEm: ' + memo.isEm)
|
|
599
|
+
if (inlines[n].len > 1) {
|
|
600
|
+
n, nest = setStrong(state, inlines, marks, n, memo, opt)
|
|
601
|
+
}
|
|
602
|
+
if (inlines[n].len !== 0) {
|
|
603
|
+
n, nest = setEm(state, inlines, marks, n, memo, opt)
|
|
604
|
+
}
|
|
605
|
+
if (inlines[n].len !== 0) {
|
|
606
|
+
setText(inlines, marks, n, nest)
|
|
538
607
|
}
|
|
539
|
-
n, nest, memo = setEm(state, inlines, marks, n, memo, opt)
|
|
540
|
-
if (inlines[n].len !== 0) setText(inlines, marks, n, nest)
|
|
541
|
-
//console.log(marks)
|
|
542
608
|
n++
|
|
543
609
|
}
|
|
544
610
|
return marks
|
|
545
611
|
}
|
|
546
612
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
//console.log('n: ' + n + ', i: ' + i + ', marks[i].type: ' + marks[i].type)
|
|
558
|
-
inlines.splice(n + i + 1, 0, marks[i])
|
|
559
|
-
i++
|
|
560
|
-
continue
|
|
613
|
+
|
|
614
|
+
const mergeInlinesAndMarks = (inlines, marks) => {
|
|
615
|
+
marks.sort((a, b) => a.s - b.s)
|
|
616
|
+
const merged = []
|
|
617
|
+
let markIndex = 0
|
|
618
|
+
for (const token of inlines) {
|
|
619
|
+
if (token.type === '') {
|
|
620
|
+
while (markIndex < marks.length && marks[markIndex].s >= token.s && marks[markIndex].e <= token.e) {
|
|
621
|
+
merged.push(marks[markIndex])
|
|
622
|
+
markIndex++
|
|
561
623
|
}
|
|
562
|
-
break
|
|
563
|
-
}
|
|
564
|
-
if (marks.length) {
|
|
565
|
-
marks.splice(0, i)
|
|
566
|
-
inlines.splice(n, 1)
|
|
567
|
-
n += i
|
|
568
624
|
} else {
|
|
569
|
-
|
|
570
|
-
n++
|
|
625
|
+
merged.push(token)
|
|
571
626
|
}
|
|
572
627
|
}
|
|
628
|
+
while (markIndex < marks.length) {
|
|
629
|
+
merged.push(marks[markIndex++])
|
|
630
|
+
}
|
|
631
|
+
return merged
|
|
573
632
|
}
|
|
574
633
|
|
|
575
634
|
const strongJa = (state, silent, opt) => {
|
|
576
635
|
if (silent) return false
|
|
577
636
|
const start = state.pos
|
|
578
637
|
let max = state.posMax
|
|
638
|
+
const src = state.src
|
|
579
639
|
let attributesSrc
|
|
580
640
|
if (start > max) return false
|
|
581
|
-
if (
|
|
641
|
+
if (src.charCodeAt(start) !== 0x2A) return false
|
|
582
642
|
if (hasBackslash(state, start)) return false
|
|
583
643
|
|
|
584
644
|
if (opt.mditAttrs) {
|
|
585
|
-
attributesSrc =
|
|
645
|
+
attributesSrc = src.match(/((\n)? *){([^{}\n!@#%^&*()]+?)} *$/)
|
|
586
646
|
if (attributesSrc && attributesSrc[3] !== '.') {
|
|
587
|
-
max =
|
|
647
|
+
max = src.slice(0, attributesSrc.index).length
|
|
588
648
|
if (attributesSrc[2] === '\n') {
|
|
589
|
-
max =
|
|
649
|
+
max = src.slice(0, attributesSrc.index - 1).length
|
|
590
650
|
}
|
|
591
651
|
if(hasBackslash(state, attributesSrc.index) && attributesSrc[2] === '' && attributesSrc[1].length === 0) {
|
|
592
652
|
max = state.posMax
|
|
593
653
|
}
|
|
594
654
|
} else {
|
|
595
|
-
let endCurlyKet =
|
|
655
|
+
let endCurlyKet = src.match(/(\n *){([^{}\n!@#%^&*()]*?)}.*(} *?)$/)
|
|
596
656
|
if (endCurlyKet) {
|
|
597
657
|
max -= endCurlyKet[3].length
|
|
598
658
|
}
|
|
@@ -605,20 +665,17 @@ const strongJa = (state, silent, opt) => {
|
|
|
605
665
|
//console.log(inlines)
|
|
606
666
|
|
|
607
667
|
const memo = {
|
|
608
|
-
isEm: false,
|
|
609
|
-
hasEmThatWrapStrong: false,
|
|
610
|
-
noSetStrongEnd: false,
|
|
611
668
|
html: state.md.options.html,
|
|
612
669
|
htmlTags: {},
|
|
613
|
-
inlineMarkStart:
|
|
614
|
-
inlineMarkEnd:
|
|
670
|
+
inlineMarkStart: src.charCodeAt(0) === 0x2A ? true : false,
|
|
671
|
+
inlineMarkEnd: src.charCodeAt(max - 1) === 0x2A ? true : false,
|
|
615
672
|
}
|
|
616
673
|
|
|
617
674
|
let marks = createMarks(state, inlines, 0, inlines.length, memo, opt)
|
|
618
675
|
//console.log('marks: ')
|
|
619
676
|
//console.log(marks)
|
|
620
677
|
|
|
621
|
-
|
|
678
|
+
inlines = mergeInlinesAndMarks(inlines, marks)
|
|
622
679
|
//console.log('fix inlines:')
|
|
623
680
|
//console.log(inlines)
|
|
624
681
|
|
|
@@ -638,7 +695,7 @@ const strongJa = (state, silent, opt) => {
|
|
|
638
695
|
state.pos = max
|
|
639
696
|
}
|
|
640
697
|
} else {
|
|
641
|
-
state.pos = max
|
|
698
|
+
state.pos = max
|
|
642
699
|
}
|
|
643
700
|
//console.log(state.tokens)
|
|
644
701
|
return true
|
|
@@ -649,13 +706,10 @@ const mditStrongJa = (md, option) => {
|
|
|
649
706
|
dollarMath: true, //inline math $...$
|
|
650
707
|
mditAttrs: true, //markdown-it-attrs
|
|
651
708
|
}
|
|
652
|
-
if (option
|
|
653
|
-
|
|
654
|
-
opt[o] = option[o]
|
|
655
|
-
}
|
|
656
|
-
}
|
|
709
|
+
if (option) Object.assign(opt, option)
|
|
710
|
+
|
|
657
711
|
md.inline.ruler.before('emphasis', 'strong_ja', (state, silent) => {
|
|
658
712
|
return strongJa(state, silent, opt)
|
|
659
713
|
})
|
|
660
714
|
}
|
|
661
|
-
export default mditStrongJa
|
|
715
|
+
export default mditStrongJa
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peaceroad/markdown-it-strong-ja",
|
|
3
3
|
"description": "This is a plugin for markdown-it. It is an alternative to the standard `**` (strong) and `*` (em) processing. It also processes strings that cannot be converted by the standard.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
package/test/example-complex.txt
CHANGED
|
@@ -215,10 +215,25 @@ aa<span>b*ef*</span>cc
|
|
|
215
215
|
[Markdown]
|
|
216
216
|
a*a<span>b*ef*</span>c*c
|
|
217
217
|
[HTML:false]
|
|
218
|
-
<p>a<em>a<span>b</em>ef
|
|
218
|
+
<p>a<em>a<span>b</em>ef*</span>c*c</p>
|
|
219
219
|
[HTML:true]
|
|
220
220
|
<p>a<em>a<span>b</em>ef*</span>c*c</p>
|
|
221
221
|
|
|
222
|
+
[Markdown]
|
|
223
|
+
a*a<span>b*ef*e</span>c*c
|
|
224
|
+
[HTML:false]
|
|
225
|
+
<p>a<em>a<span>b</em>ef<em>e</span>c</em>c</p>
|
|
226
|
+
[HTML:true]
|
|
227
|
+
<p>a<em>a<span>b</em>ef<em>e</span>c</em>c</p>
|
|
228
|
+
|
|
229
|
+
[Markdown]
|
|
230
|
+
**eee*z<span>a*b</span>*
|
|
231
|
+
[HTML:false]
|
|
232
|
+
<p>*<em>eee<em>z<span>a</em>b</span></em></p>
|
|
233
|
+
[HTML:true]
|
|
234
|
+
<p>*<em>eee<em>z<span>a</em>b</span></em></p>
|
|
235
|
+
|
|
236
|
+
|
|
222
237
|
[Markdown]
|
|
223
238
|
a***a<span>b</span>c***c
|
|
224
239
|
[HTML:false]
|
|
@@ -226,7 +241,6 @@ a***a<span>b</span>c***c
|
|
|
226
241
|
[HTML:true]
|
|
227
242
|
<p>a<em><strong>a<span>b</span>c</strong></em>c</p>
|
|
228
243
|
|
|
229
|
-
|
|
230
244
|
[Markdown]
|
|
231
245
|
a***a<span>b***e</span>cc
|
|
232
246
|
[HTML:false]
|
|
@@ -361,3 +375,132 @@ b<span>c</span>*
|
|
|
361
375
|
<p>**<br></p>
|
|
362
376
|
[HTML:true]
|
|
363
377
|
<p>**<br></p>
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
[Markdown]
|
|
381
|
+
a*b<>c*d*e
|
|
382
|
+
[HTML:false]
|
|
383
|
+
<p>a<em>b<>c</em>d*e</p>
|
|
384
|
+
[HTML:true]
|
|
385
|
+
<p>a<em>b<>c</em>d*e</p>
|
|
386
|
+
|
|
387
|
+
[Markdown]
|
|
388
|
+
z*<>*a*b
|
|
389
|
+
[HTML:false]
|
|
390
|
+
<p>z*<><em>a</em>b</p>
|
|
391
|
+
[HTML:true]
|
|
392
|
+
<p>z*<><em>a</em>b</p>
|
|
393
|
+
|
|
394
|
+
[Markdown]
|
|
395
|
+
z*<span>*a*b
|
|
396
|
+
[HTML:false]
|
|
397
|
+
<p>z*<span><em>a</em>b</p>
|
|
398
|
+
[HTML:true]
|
|
399
|
+
<p>z*<span><em>a</em>b</p>
|
|
400
|
+
|
|
401
|
+
[Markdown]
|
|
402
|
+
z*<span>*a*b</span>
|
|
403
|
+
[HTML:false]
|
|
404
|
+
<p>z*<span><em>a</em>b</span></p>
|
|
405
|
+
[HTML:true]
|
|
406
|
+
<p>z*<span><em>a</em>b</span></p>
|
|
407
|
+
|
|
408
|
+
[Markdown]
|
|
409
|
+
*z<span>*a*b</span>
|
|
410
|
+
[HTML:false]
|
|
411
|
+
<p>*z<span><em>a</em>b</span></p>
|
|
412
|
+
[HTML:true]
|
|
413
|
+
<p>*z<span><em>a</em>b</span></p>
|
|
414
|
+
|
|
415
|
+
[Markdown]
|
|
416
|
+
**eee*z<span>*a*b</span>*
|
|
417
|
+
[HTML:false]
|
|
418
|
+
<p>**eee<em>z<span><em>a</em>b</span></em></p>
|
|
419
|
+
[HTML:true]
|
|
420
|
+
<p>**eee<em>z<span><em>a</em>b</span></em></p>
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
[Markdown]
|
|
424
|
+
***eee*z<span>*a*b</span>**
|
|
425
|
+
[HTML:false]
|
|
426
|
+
<p><strong><em>eee</em>z<span><em>a</em>b</span></strong></p>
|
|
427
|
+
[HTML:true]
|
|
428
|
+
<p><strong><em>eee</em>z<span><em>a</em>b</span></strong></p>
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
[Markdown]
|
|
432
|
+
***a*b<span>c</span>**
|
|
433
|
+
[HTML:false]
|
|
434
|
+
<p><strong><em>a</em>b<span>c</span></strong></p>
|
|
435
|
+
[HTML:true]
|
|
436
|
+
<p><strong><em>a</em>b<span>c</span></strong></p>
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
[Markdown]
|
|
440
|
+
***<sPan>aa*bb</spaN>cc**
|
|
441
|
+
[HTML:false]
|
|
442
|
+
<p><strong><em><sPan>aa</em>bb</spaN>cc</strong></p>
|
|
443
|
+
[HTML:true]
|
|
444
|
+
<p><strong><em><sPan>aa</em>bb</spaN>cc</strong></p>
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
[Markdown]
|
|
448
|
+
e*z<span>*a*b*
|
|
449
|
+
[HTML:false]
|
|
450
|
+
<p>e<em>z<span><em>a</em>b</em></p>
|
|
451
|
+
[HTML:true]
|
|
452
|
+
<p>e<em>z<span><em>a</em>b</em></p>
|
|
453
|
+
|
|
454
|
+
[Markdown]
|
|
455
|
+
**e<span>**e**e**
|
|
456
|
+
[HTML:false]
|
|
457
|
+
<p><strong>e<span><strong>e</strong>e</strong></p>
|
|
458
|
+
[HTML:true]
|
|
459
|
+
<p><strong>e<span><strong>e</strong>e</strong></p>
|
|
460
|
+
|
|
461
|
+
[Markdown]
|
|
462
|
+
e*z<span> *a*b*
|
|
463
|
+
[HTML:false]
|
|
464
|
+
<p>e<em>z<span> <em>a</em>b</em></p>
|
|
465
|
+
[HTML:true]
|
|
466
|
+
<p>e<em>z<span> <em>a</em>b</em></p>
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
[Markdown]
|
|
470
|
+
***eee*z<span>a*b</span>**
|
|
471
|
+
[HTML:false]
|
|
472
|
+
<p><em><em><em>eee</em>z<span>a</em>b</span></em>*</p>
|
|
473
|
+
[HTML:true]
|
|
474
|
+
<p><em><em><em>eee</em>z<span>a</em>b</span></em>*</p>
|
|
475
|
+
|
|
476
|
+
[Markdown]
|
|
477
|
+
***<sPan>a</spaN>b**
|
|
478
|
+
[HTML:false]
|
|
479
|
+
<p>*<strong><sPan>a</spaN>b</strong></p>
|
|
480
|
+
[HTML:true]
|
|
481
|
+
<p>*<strong><sPan>a</spaN>b</strong></p>
|
|
482
|
+
|
|
483
|
+
[Markdown]
|
|
484
|
+
a**`b`**a
|
|
485
|
+
[HTML:false]
|
|
486
|
+
<p>a**<code>b</code>**a</p>
|
|
487
|
+
|
|
488
|
+
[Markdown]
|
|
489
|
+
a(**`b`**)a
|
|
490
|
+
[HTML:false]
|
|
491
|
+
<p>a(<strong><code>b</code></strong>)a</p>
|
|
492
|
+
|
|
493
|
+
[Markdown]
|
|
494
|
+
あ**`b`**あ
|
|
495
|
+
[HTML:false :: commommark: <p>あ**<code>b</code>**あ</p>]
|
|
496
|
+
<p>あ<strong><code>b</code></strong>あ</p>
|
|
497
|
+
|
|
498
|
+
[Markdown]
|
|
499
|
+
あ(**`b`**)あ
|
|
500
|
+
[HTML:false]
|
|
501
|
+
<p>あ(<strong><code>b</code></strong>)あ</p>
|
|
502
|
+
|
|
503
|
+
[Markdown]
|
|
504
|
+
(**`b`**)あ
|
|
505
|
+
[HTML:false]
|
|
506
|
+
<p>(<strong><code>b</code></strong>)あ</p>
|
|
@@ -216,10 +216,24 @@ aa<span>b*ef*</span>cc
|
|
|
216
216
|
[Markdown]
|
|
217
217
|
a*a<span>b*ef*</span>c*c
|
|
218
218
|
[HTML:false]
|
|
219
|
-
<p>a<em>a<span>b</em>ef
|
|
219
|
+
<p>a<em>a<span>b</em>ef*</span>c*c</p>
|
|
220
220
|
[HTML:true]
|
|
221
221
|
<p>a<em>a<span>b</em>ef*</span>c*c</p>
|
|
222
222
|
|
|
223
|
+
[Markdown]
|
|
224
|
+
a*a<span>b*ef*e</span>c*c
|
|
225
|
+
[HTML:false]
|
|
226
|
+
<p>a<em>a<span>b</em>ef<em>e</span>c</em>c</p>
|
|
227
|
+
[HTML:true]
|
|
228
|
+
<p>a<em>a<span>b</em>ef<em>e</span>c</em>c</p>
|
|
229
|
+
|
|
230
|
+
[Markdown]
|
|
231
|
+
**eee*z<span>a*b</span>*
|
|
232
|
+
[HTML:false]
|
|
233
|
+
<p>*<em>eee<em>z<span>a</em>b</span></em></p>
|
|
234
|
+
[HTML:true]
|
|
235
|
+
<p>*<em>eee<em>z<span>a</em>b</span></em></p>
|
|
236
|
+
|
|
223
237
|
[Markdown]
|
|
224
238
|
a***a<span>b</span>c***c
|
|
225
239
|
[HTML:false]
|
|
@@ -390,4 +404,109 @@ z*<span>*a*b</span>
|
|
|
390
404
|
[HTML:false]
|
|
391
405
|
<p>z*<span><em>a</em>b</span></p>
|
|
392
406
|
[HTML:true]
|
|
393
|
-
<p>z*<span><em>a</em>b</span></p>
|
|
407
|
+
<p>z*<span><em>a</em>b</span></p>
|
|
408
|
+
|
|
409
|
+
[Markdown]
|
|
410
|
+
*z<span>*a*b</span>
|
|
411
|
+
[HTML:false]
|
|
412
|
+
<p>*z<span><em>a</em>b</span></p>
|
|
413
|
+
[HTML:true]
|
|
414
|
+
<p>*z<span><em>a</em>b</span></p>
|
|
415
|
+
|
|
416
|
+
[Markdown]
|
|
417
|
+
**eee*z<span>*a*b</span>*
|
|
418
|
+
[HTML:false]
|
|
419
|
+
<p>**eee<em>z<span><em>a</em>b</span></em></p>
|
|
420
|
+
[HTML:true]
|
|
421
|
+
<p>**eee<em>z<span><em>a</em>b</span></em></p>
|
|
422
|
+
|
|
423
|
+
[Markdown]
|
|
424
|
+
***eee*z<span>*a*b</span>**
|
|
425
|
+
[HTML:false]
|
|
426
|
+
<p><strong><em>eee</em>z<span><em>a</em>b</span></strong></p>
|
|
427
|
+
[HTML:true]
|
|
428
|
+
<p><strong><em>eee</em>z<span><em>a</em>b</span></strong></p>
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
[Markdown]
|
|
432
|
+
***a*b<span>c</span>**
|
|
433
|
+
[HTML:false]
|
|
434
|
+
<p><strong><em>a</em>b<span>c</span></strong></p>
|
|
435
|
+
[HTML:true]
|
|
436
|
+
<p><strong><em>a</em>b<span>c</span></strong></p>
|
|
437
|
+
|
|
438
|
+
[Markdown]
|
|
439
|
+
***<sPan>aa*bb</spaN>cc**
|
|
440
|
+
[HTML:false]
|
|
441
|
+
<p><strong><em><sPan>aa</em>bb</spaN>cc</strong></p>
|
|
442
|
+
[HTML:true]
|
|
443
|
+
<p><strong><em><sPan>aa</em>bb</spaN>cc</strong></p>
|
|
444
|
+
|
|
445
|
+
[Markdown]
|
|
446
|
+
e*z<span>*a*b*
|
|
447
|
+
[HTML:false]
|
|
448
|
+
<p>e<em>z<span><em>a</em>b</em></p>
|
|
449
|
+
[HTML:true]
|
|
450
|
+
<p>e<em>z<span><em>a</em>b</em></p>
|
|
451
|
+
|
|
452
|
+
[Markdown]
|
|
453
|
+
**e<span>**e**e**
|
|
454
|
+
[HTML:false]
|
|
455
|
+
<p><strong>e<span><strong>e</strong>e</strong></p>
|
|
456
|
+
[HTML:true]
|
|
457
|
+
<p><strong>e<span><strong>e</strong>e</strong></p>
|
|
458
|
+
|
|
459
|
+
[Markdown]
|
|
460
|
+
e*z<span> *a*b*
|
|
461
|
+
[HTML:false]
|
|
462
|
+
<p>e<em>z<span> <em>a</em>b</em></p>
|
|
463
|
+
[HTML:true]
|
|
464
|
+
<p>e<em>z<span> <em>a</em>b</em></p>
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
[Markdown]
|
|
469
|
+
***eee*z<span>a*b</span>**
|
|
470
|
+
[HTML:false]
|
|
471
|
+
<p><em><em><em>eee</em>z<span>a</em>b</span></em>*</p>
|
|
472
|
+
[HTML:true]
|
|
473
|
+
<p><em><em><em>eee</em>z<span>a</em>b</span></em>*</p>
|
|
474
|
+
|
|
475
|
+
[Markdown]
|
|
476
|
+
***<sPan>a</spaN>b**
|
|
477
|
+
[HTML:false]
|
|
478
|
+
<p>*<strong><sPan>a</spaN>b</strong></p>
|
|
479
|
+
[HTML:true]
|
|
480
|
+
<p>*<strong><sPan>a</spaN>b</strong></p>
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
[Markdown]
|
|
484
|
+
a**`b`**a
|
|
485
|
+
[HTML:false]
|
|
486
|
+
<p>a**<code>b</code>**a</p>
|
|
487
|
+
|
|
488
|
+
[Markdown]
|
|
489
|
+
a(**`b`**)a
|
|
490
|
+
[HTML:false]
|
|
491
|
+
<p>a(<strong><code>b</code></strong>)a</p>
|
|
492
|
+
|
|
493
|
+
[Markdown]
|
|
494
|
+
あ**`b`**あ
|
|
495
|
+
[HTML:false :: commommark: <p>あ**<code>b</code>**あ</p>]
|
|
496
|
+
<p>あ<strong><code>b</code></strong>あ</p>
|
|
497
|
+
|
|
498
|
+
[Markdown]
|
|
499
|
+
あ(**`b`**)あ
|
|
500
|
+
[HTML:false]
|
|
501
|
+
<p>あ(<strong><code>b</code></strong>)あ</p>
|
|
502
|
+
|
|
503
|
+
[Markdown]
|
|
504
|
+
(**`b`**)あ
|
|
505
|
+
[HTML:false]
|
|
506
|
+
<p>(<strong><code>b</code></strong>)あ</p>
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
package/test/test.js
CHANGED
|
@@ -23,7 +23,7 @@ const mditNoAttrsCJKBreaksWithHtml = mdit({html: true}).use(mditStrongJa, {mditA
|
|
|
23
23
|
const check = (ms, example, allPass, useAttrs) => {
|
|
24
24
|
let n = 1
|
|
25
25
|
while (n < ms.length) {
|
|
26
|
-
//if (n !==
|
|
26
|
+
//if (n !== 81) { n++; continue }
|
|
27
27
|
const m = ms[n].markdown
|
|
28
28
|
let h = ''
|
|
29
29
|
if (example === 'withLineBreak') {
|
|
@@ -35,7 +35,7 @@ const check = (ms, example, allPass, useAttrs) => {
|
|
|
35
35
|
assert.strictEqual(h, ms[n].html)
|
|
36
36
|
} catch(e) {
|
|
37
37
|
console.log('Test [' + n + ', HTML: false, useAttrs: ' + useAttrs + '] >>>')
|
|
38
|
-
console.log('Input: ' + ms[n].markdown + '\
|
|
38
|
+
console.log('Input: ' + ms[n].markdown + '\nOutput: ' + h + 'Correct: ' + ms[n].html)
|
|
39
39
|
allPass = false
|
|
40
40
|
}
|
|
41
41
|
if (ms[n].htmlWithHtmlTrue) {
|
|
@@ -49,7 +49,7 @@ const check = (ms, example, allPass, useAttrs) => {
|
|
|
49
49
|
assert.strictEqual(hh, ms[n].htmlWithHtmlTrue)
|
|
50
50
|
} catch(e) {
|
|
51
51
|
console.log('Test [' + n + ', HTML: true, useAttrs: ' + useAttrs + '] >>>')
|
|
52
|
-
console.log('Input: ' + ms[n].markdown + '\
|
|
52
|
+
console.log('Input: ' + ms[n].markdown + '\nOutput: ' + hh + 'Correct: ' + ms[n].htmlWithHtmlTrue)
|
|
53
53
|
allPass = false
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -58,7 +58,6 @@ const check = (ms, example, allPass, useAttrs) => {
|
|
|
58
58
|
return allPass
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
|
|
62
61
|
const examples = {
|
|
63
62
|
strong: __dirname + '/example-strong.txt',
|
|
64
63
|
em: __dirname + '/example-em.txt',
|