@peaceroad/markdown-it-strong-ja 0.3.2 → 0.3.3
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/index.js +214 -113
- package/package.json +1 -1
- package/test/example-complex.txt +76 -2
- package/test/example-strong.txt +1 -2
- package/test/test.js +2 -2
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@ const hasBackslash = (state, start) => {
|
|
|
12
12
|
const setToken = (state, inlines) => {
|
|
13
13
|
let i = 0
|
|
14
14
|
while (i < inlines.length) {
|
|
15
|
-
|
|
15
|
+
let type = inlines[i].type
|
|
16
16
|
const tag = type.replace(/(?:_open|_close)$/, '')
|
|
17
17
|
|
|
18
18
|
if (/_open$/.test(type)) {
|
|
@@ -20,19 +20,22 @@ const setToken = (state, inlines) => {
|
|
|
20
20
|
startToken.markup = tag === 'strong' ? '**' : '*'
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
if (type === 'html_inline') {
|
|
24
|
+
type = 'text'
|
|
25
|
+
}
|
|
23
26
|
if (type === 'text') {
|
|
24
27
|
const content = state.src.slice(inlines[i].s, inlines[i].e + 1)
|
|
25
28
|
if (/^\**$/.test(content)) {
|
|
26
29
|
//console.log('asterisk process::')
|
|
27
30
|
const asteriskToken = state.push(type, '', 0)
|
|
28
31
|
asteriskToken.content = content
|
|
29
|
-
//console.log('asteriskToken: ' + asteriskToken.content)
|
|
30
32
|
i++
|
|
31
33
|
continue
|
|
32
34
|
}
|
|
33
|
-
const childTokens = state.md.parseInline(content, state.env)
|
|
34
35
|
|
|
36
|
+
const childTokens = state.md.parseInline(content, state.env)
|
|
35
37
|
if (childTokens[0] && childTokens[0].children) {
|
|
38
|
+
//console.log(state.tokens)
|
|
36
39
|
//console.log(state.tokens[state.tokens.length - 1])
|
|
37
40
|
state.tokens[state.tokens.length - 1].children = childTokens[0].children
|
|
38
41
|
childTokens[0].children.forEach(t => {
|
|
@@ -50,25 +53,6 @@ const setToken = (state, inlines) => {
|
|
|
50
53
|
token.hidden = t.hidden
|
|
51
54
|
})
|
|
52
55
|
}
|
|
53
|
-
//console.log(childTokens[0].children)
|
|
54
|
-
/*
|
|
55
|
-
if (childTokens[0] && childTokens[0].children) {
|
|
56
|
-
state.tokens[state.tokens.length - 1].children = childTokens[0].children
|
|
57
|
-
childTokens[0].children.forEach(t => {
|
|
58
|
-
//console.log('t.type: ' + t.type + ', t.tag: ' + t.tag + ', t.nesting: ' + t.nesting)
|
|
59
|
-
const token = state.push(t.type, t.tag, t.nesting)
|
|
60
|
-
token.attrs = t.attrs
|
|
61
|
-
token.map = t.map
|
|
62
|
-
token.level = t.level
|
|
63
|
-
token.children = t.children
|
|
64
|
-
token.content = t.content
|
|
65
|
-
token.markup = t.markup
|
|
66
|
-
token.info = t.info
|
|
67
|
-
token.meta = t.meta
|
|
68
|
-
token.block = t.block
|
|
69
|
-
token.hidden = t.hidden
|
|
70
|
-
})
|
|
71
|
-
}*/
|
|
72
56
|
}
|
|
73
57
|
|
|
74
58
|
if (/_close$/.test(type)) {
|
|
@@ -80,62 +64,113 @@ const setToken = (state, inlines) => {
|
|
|
80
64
|
}
|
|
81
65
|
}
|
|
82
66
|
|
|
83
|
-
const inlinesPush = (inlines, s, e, len, type) => {
|
|
84
|
-
|
|
67
|
+
const inlinesPush = (inlines, s, e, len, type, tag, tagType) => {
|
|
68
|
+
const inline = {
|
|
85
69
|
s: s,
|
|
86
70
|
sp: s,
|
|
87
71
|
e: e,
|
|
88
72
|
ep: e,
|
|
89
73
|
len: len,
|
|
90
74
|
type: type,
|
|
91
|
-
}
|
|
75
|
+
}
|
|
76
|
+
if (tag) inline.tag = [tag, tagType]
|
|
77
|
+
inlines.push(inline)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const hasNextSymbol = (state, n, max, symbol, noMark) => {
|
|
81
|
+
let nextSymbolPos = -1
|
|
82
|
+
if (state.src.charCodeAt(n) === symbol && !hasBackslash(state, n)) {
|
|
83
|
+
let i = n + 1
|
|
84
|
+
let tempNoMark = noMark
|
|
85
|
+
while (i < max) {
|
|
86
|
+
tempNoMark += state.src[i]
|
|
87
|
+
if (state.src.charCodeAt(i) === symbol && !hasBackslash(state, i)) {
|
|
88
|
+
noMark += state.src[n]
|
|
89
|
+
nextSymbolPos = i
|
|
90
|
+
break
|
|
91
|
+
}
|
|
92
|
+
i++
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return nextSymbolPos
|
|
92
96
|
}
|
|
93
97
|
|
|
94
98
|
const createInlines = (state, start, max, opt) => {
|
|
95
99
|
let n = start
|
|
96
100
|
let inlines = []
|
|
97
101
|
let noMark = ''
|
|
98
|
-
let
|
|
99
|
-
let
|
|
100
|
-
|
|
101
|
-
let beforeIsMark = true
|
|
102
|
+
let isInStartMark = true
|
|
103
|
+
let textStart = n
|
|
104
|
+
|
|
102
105
|
while (n < max) {
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
let nextSymbolPos = hasNextSymbol(state, n, max, 0x60, noMark) // '`'
|
|
107
|
+
if (nextSymbolPos !== -1) {
|
|
108
|
+
n = nextSymbolPos + 1
|
|
109
|
+
continue
|
|
105
110
|
}
|
|
106
111
|
if (opt.dollarMath) {
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
nextSymbolPos = hasNextSymbol(state, n, max, 0x24, noMark) // '$'
|
|
113
|
+
if (nextSymbolPos !== -1) {
|
|
114
|
+
n = nextSymbolPos + 1
|
|
115
|
+
continue
|
|
109
116
|
}
|
|
110
117
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
|
|
119
|
+
if (state.md.options.html) {
|
|
120
|
+
if (state.src.charCodeAt(n) === 0x3C && !hasBackslash(state, n)) { // '<'
|
|
121
|
+
let i = n + 1
|
|
122
|
+
while (i < max) {
|
|
123
|
+
if (state.src.charCodeAt(i) === 0x3E && !hasBackslash(state, i)) { // '>'
|
|
124
|
+
if (noMark.length !== 0) {
|
|
125
|
+
inlinesPush(inlines, textStart, n - 1, n - textStart, 'text')
|
|
126
|
+
}
|
|
127
|
+
let tag = state.src.slice(n + 1, i)
|
|
128
|
+
let tagType = ''
|
|
129
|
+
if (/^\//.test(tag)) {
|
|
130
|
+
tag = tag.slice(1)
|
|
131
|
+
tagType = 'close'
|
|
132
|
+
} else {
|
|
133
|
+
tagType = 'open'
|
|
134
|
+
}
|
|
135
|
+
inlinesPush(inlines, n, i, i - n + 1, 'html_inline', tag, tagType)
|
|
136
|
+
textStart = i + 1
|
|
137
|
+
break
|
|
138
|
+
}
|
|
139
|
+
i++
|
|
117
140
|
}
|
|
118
|
-
n
|
|
141
|
+
n = i + 1
|
|
119
142
|
continue
|
|
120
143
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (state.src.charCodeAt(n) === 0x2A && !hasBackslash(state, n)) { // '*'
|
|
147
|
+
if (!isInStartMark) {
|
|
148
|
+
inlinesPush(inlines, textStart, n - 1, n - textStart, 'text')
|
|
125
149
|
}
|
|
126
|
-
noMark = ''
|
|
127
150
|
if (n === max - 1) {
|
|
128
|
-
inlinesPush(inlines, n
|
|
151
|
+
inlinesPush(inlines, n, n, 1 , '')
|
|
152
|
+
break
|
|
129
153
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
inlinesPush(inlines, n -
|
|
154
|
+
let i = n + 1
|
|
155
|
+
while (i < max) {
|
|
156
|
+
if (state.src.charCodeAt(i) === 0x2A) {
|
|
157
|
+
if (i === max - 1) inlinesPush(inlines, n, i, i - n + 1 , '')
|
|
158
|
+
i++
|
|
159
|
+
continue
|
|
160
|
+
}
|
|
161
|
+
inlinesPush(inlines, n, i - 1, i - n, '')
|
|
162
|
+
textStart = i
|
|
163
|
+
break
|
|
138
164
|
}
|
|
165
|
+
n = i
|
|
166
|
+
continue
|
|
167
|
+
}
|
|
168
|
+
isInStartMark = false
|
|
169
|
+
noMark += state.src[n]
|
|
170
|
+
//console.log('noMark: ' + noMark)
|
|
171
|
+
if (n === max - 1 || max < 3) {
|
|
172
|
+
inlinesPush(inlines, textStart, n, n - textStart + 1, 'text')
|
|
173
|
+
break
|
|
139
174
|
}
|
|
140
175
|
n++
|
|
141
176
|
}
|
|
@@ -153,7 +188,6 @@ const marksPush = (marks, nest, s, e, len, outsideLen, type) => {
|
|
|
153
188
|
oLen: outsideLen,
|
|
154
189
|
type: type,
|
|
155
190
|
}
|
|
156
|
-
//let i = marks.findIndex(o => o.s > s)
|
|
157
191
|
let i = marks.findIndex(o => o.s > s)
|
|
158
192
|
if (i === -1) {
|
|
159
193
|
marks.push(np)
|
|
@@ -163,17 +197,27 @@ const marksPush = (marks, nest, s, e, len, outsideLen, type) => {
|
|
|
163
197
|
}
|
|
164
198
|
|
|
165
199
|
const setStrong = (inlines, marks, n, memo) => {
|
|
166
|
-
let i = n +
|
|
200
|
+
let i = n + 1
|
|
167
201
|
let j = 0
|
|
168
202
|
let nest = 0
|
|
203
|
+
let insideTagsIsClose = 1
|
|
169
204
|
while (i < inlines.length) {
|
|
170
|
-
if (inlines[i].len === 0) { i
|
|
205
|
+
if (inlines[i].len === 0) { i++; continue }
|
|
206
|
+
if (memo.html) {
|
|
207
|
+
if (inlines[i].type === 'html_inline') {
|
|
208
|
+
insideTagsIsClose = isJumpTag(inlines, i, memo)
|
|
209
|
+
//console.log('insideTagsIsClose: ' + insideTagsIsClose )
|
|
210
|
+
if (insideTagsIsClose === -1) return n, nest, memo
|
|
211
|
+
if (insideTagsIsClose === 0) { i++; continue }
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (inlines[i].type !== '') { i++; continue }
|
|
215
|
+
|
|
171
216
|
//console.log('n: ' + n + ' [strong]: inlines[n].len: ' + inlines[n].len + ', i: ' + i + ', inlines[i].len: ' + inlines[i].len)
|
|
172
217
|
|
|
173
218
|
nest = checkNest(inlines, marks, n, i)
|
|
174
219
|
//console.log('n: ' + n + ' [strong]: nest: ' + nest)
|
|
175
220
|
if (nest === -1) return n, nest, memo
|
|
176
|
-
|
|
177
221
|
if (inlines[i].len === 1 && inlines[n].len > 2) {
|
|
178
222
|
//console.log('n: ' + n + ' [strong]: check em inside strong: ' + nest)
|
|
179
223
|
marksPush(marks, nest, inlines[n].ep, inlines[n].ep, 1, inlines[n].len - 1, 'em_open')
|
|
@@ -182,17 +226,21 @@ const setStrong = (inlines, marks, n, memo) => {
|
|
|
182
226
|
inlines[n].ep -= 1
|
|
183
227
|
inlines[i].len = 0
|
|
184
228
|
inlines[i].sp += 1
|
|
185
|
-
if (i
|
|
186
|
-
i
|
|
229
|
+
if (i++ < inlines.length) {
|
|
230
|
+
i++
|
|
187
231
|
nest++
|
|
188
232
|
} else {
|
|
189
233
|
return n, nest, memo
|
|
190
234
|
}
|
|
191
|
-
|
|
192
|
-
//console.log('n: ' + n + ' [strong]: check em inside strong end.')
|
|
235
|
+
if (i > inlines.length - 1) return n, nest, memo
|
|
193
236
|
}
|
|
194
237
|
|
|
238
|
+
if (memo.html && !insideTagsIsClose && inlines[i].len !== 1) {
|
|
239
|
+
memo.htmlTags = {}
|
|
240
|
+
return n, nest, memo
|
|
241
|
+
}
|
|
195
242
|
let strongNum = Math.trunc(Math.min(inlines[n].len, inlines[i].len) / 2)
|
|
243
|
+
|
|
196
244
|
if (inlines[i].len > 1) {
|
|
197
245
|
//console.log('n: ' + n + ' [strong]: normal push, nest: ' + nest)
|
|
198
246
|
j = 0
|
|
@@ -207,16 +255,15 @@ const setStrong = (inlines, marks, n, memo) => {
|
|
|
207
255
|
//console.log(marks)
|
|
208
256
|
j++
|
|
209
257
|
}
|
|
210
|
-
|
|
211
258
|
if (inlines[n].len === 0) return n, nest, memo
|
|
212
259
|
}
|
|
213
260
|
|
|
214
261
|
if (inlines[n].len === 1) {
|
|
215
|
-
//console.log('check em that warp strong
|
|
262
|
+
//console.log('check em that warp strong.')
|
|
216
263
|
nest++
|
|
217
|
-
n, nest, memo= setEm(inlines, marks, n, memo, nest)
|
|
264
|
+
n, nest, memo = setEm(inlines, marks, n, memo, nest)
|
|
218
265
|
if (memo.hasEmThatWrapStrong) {
|
|
219
|
-
//console.log('
|
|
266
|
+
//console.log('set em that wrap strong.')
|
|
220
267
|
let k = 0
|
|
221
268
|
while (k < strongNum) {
|
|
222
269
|
marks[marks.length - 2 - k * 2 - 1].nest += 1
|
|
@@ -225,19 +272,57 @@ const setStrong = (inlines, marks, n, memo) => {
|
|
|
225
272
|
}
|
|
226
273
|
}
|
|
227
274
|
}
|
|
228
|
-
|
|
229
275
|
if (inlines[n].len === 0) return n, nest, memo
|
|
230
|
-
i
|
|
276
|
+
i++
|
|
231
277
|
}
|
|
232
278
|
return n, nest, memo
|
|
233
279
|
}
|
|
234
280
|
|
|
281
|
+
const isJumpTag = (inlines, n, memo) => {
|
|
282
|
+
//console.log(n, 'before::memo.htmlTags: ' + JSON.stringify(memo.htmlTags))
|
|
283
|
+
const hasSet = Object.keys(memo.htmlTags).some(tag => {
|
|
284
|
+
if (tag === inlines[n].tag[0]) {
|
|
285
|
+
if (inlines[n].tag[1] === 'open') {
|
|
286
|
+
memo.htmlTags[tag]++ }
|
|
287
|
+
else {
|
|
288
|
+
memo.htmlTags[tag]--
|
|
289
|
+
}
|
|
290
|
+
return true
|
|
291
|
+
}
|
|
292
|
+
return false
|
|
293
|
+
})
|
|
294
|
+
if (!hasSet && !memo.htmlTags[inlines[n].tag[0]]) {
|
|
295
|
+
if (inlines[n].tag[1] === 'close') {
|
|
296
|
+
memo.htmlTags = {}
|
|
297
|
+
return -1
|
|
298
|
+
}
|
|
299
|
+
memo.htmlTags[inlines[n].tag[0]] = 1
|
|
300
|
+
}
|
|
301
|
+
//console.log(n, 'after::memo.htmlTags: ' + JSON.stringify(memo.htmlTags))
|
|
302
|
+
const closeAllTags = Object.values(memo.htmlTags).every(val => val === 0)
|
|
303
|
+
//console.log('closeAllTags: ' + closeAllTags)
|
|
304
|
+
if (closeAllTags) return 1
|
|
305
|
+
//memo.htmlTags = {}
|
|
306
|
+
return 0
|
|
307
|
+
}
|
|
308
|
+
|
|
235
309
|
const setEm = (inlines, marks, n, memo, sNest) => {
|
|
236
|
-
let i = n +
|
|
310
|
+
let i = n + 1
|
|
237
311
|
let nest = 0
|
|
238
312
|
let strongPNum = 0
|
|
313
|
+
let insideTagsIsClose = 1
|
|
239
314
|
while (i < inlines.length) {
|
|
240
|
-
if (inlines[i].len === 0) { i
|
|
315
|
+
if (inlines[i].len === 0) { i++; continue }
|
|
316
|
+
if (memo.isEm && memo.html) {
|
|
317
|
+
if (inlines[i].type === 'html_inline') {
|
|
318
|
+
insideTagsIsClose = isJumpTag(inlines, i, memo)
|
|
319
|
+
//console.log('insideTagsIsClose: ' + insideTagsIsClose )
|
|
320
|
+
if (insideTagsIsClose === -1) return n, nest, memo
|
|
321
|
+
if (insideTagsIsClose === 0) { i++; continue }
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (inlines[i].type !== '') { i++; continue }
|
|
325
|
+
|
|
241
326
|
const emNum = Math.min(inlines[n].len, inlines[i].len)
|
|
242
327
|
if (memo.isEm && emNum !== 1) return n, sNest, memo
|
|
243
328
|
//console.log('n: ' + n + ' [em]: inlines[n].len: ' + inlines[n].len + ', i: ' + i, ', inlines[i].len: ' + inlines[i].len + ', isEm: ' + memo.isEm)
|
|
@@ -245,7 +330,7 @@ const setEm = (inlines, marks, n, memo, sNest) => {
|
|
|
245
330
|
|
|
246
331
|
if (memo.isEm && inlines[i].len === 2) {
|
|
247
332
|
strongPNum++
|
|
248
|
-
i
|
|
333
|
+
i++
|
|
249
334
|
continue
|
|
250
335
|
}
|
|
251
336
|
|
|
@@ -258,6 +343,11 @@ const setEm = (inlines, marks, n, memo, sNest) => {
|
|
|
258
343
|
if (nest === -1) return n, nest, memo
|
|
259
344
|
|
|
260
345
|
if (emNum === 1) {
|
|
346
|
+
//console.log(n, i, 'insideTagsIsClose: ' + insideTagsIsClose)
|
|
347
|
+
if (memo.html && !insideTagsIsClose && inlines[i].len !== 2) {
|
|
348
|
+
memo.htmlTags = {}
|
|
349
|
+
return n, nest, memo
|
|
350
|
+
}
|
|
261
351
|
//console.log('n: ' + n + ' [em]: normal push, nest: ' + nest)
|
|
262
352
|
//console.log('strongPNum: ' + strongPNum)
|
|
263
353
|
//console.log(inlines[n].ep, inlines[n].sp, inlines[n].s)
|
|
@@ -281,9 +371,8 @@ const setEm = (inlines, marks, n, memo, sNest) => {
|
|
|
281
371
|
if (inlines[n].len === 0) return n, nest, memo
|
|
282
372
|
}
|
|
283
373
|
|
|
284
|
-
i
|
|
374
|
+
i++
|
|
285
375
|
}
|
|
286
|
-
|
|
287
376
|
return n, nest, memo
|
|
288
377
|
}
|
|
289
378
|
|
|
@@ -334,27 +423,54 @@ const checkNest = (inlines, marks, n, i) => {
|
|
|
334
423
|
return nest
|
|
335
424
|
}
|
|
336
425
|
|
|
337
|
-
const createMarks = (inlines,
|
|
426
|
+
const createMarks = (inlines, start, end, memo) => {
|
|
338
427
|
let marks = []
|
|
339
|
-
let n =
|
|
340
|
-
while (n <
|
|
341
|
-
if (inlines[n].type !== '') { n
|
|
342
|
-
|
|
343
|
-
memo.isEm = inlines[n].len === 1 ? true : false
|
|
428
|
+
let n = start
|
|
429
|
+
while (n < end) {
|
|
430
|
+
if (inlines[n].type !== '' || inlines[n].len === 0) { n++; continue }
|
|
431
|
+
memo.isEm = inlines[n].len === 1 ? true : false
|
|
344
432
|
memo.wrapEm = 0
|
|
345
433
|
let nest = 0
|
|
346
|
-
|
|
434
|
+
//console.log('n: ' + n + ' ----- inlines.length: ' + inlines.length + ', memo.isEm: ' + memo.isEm)
|
|
347
435
|
if (!memo.isEm) {
|
|
348
436
|
n, nest, memo = setStrong(inlines, marks, n, memo)
|
|
349
437
|
}
|
|
350
438
|
n, nest, memo = setEm(inlines, marks, n, memo)
|
|
351
439
|
|
|
352
440
|
if (inlines[n].len !== 0) setText(inlines, marks, n, nest)
|
|
353
|
-
n
|
|
441
|
+
n++
|
|
354
442
|
}
|
|
355
443
|
return marks
|
|
356
444
|
}
|
|
357
445
|
|
|
446
|
+
const fixInlines = (inlines, marks) => {
|
|
447
|
+
let n = 0
|
|
448
|
+
while (n < inlines.length) {
|
|
449
|
+
if (inlines[n].type !== '') { n++; continue }
|
|
450
|
+
let i = 0
|
|
451
|
+
//console.log('n: ' + n + ', inlines[n].s: ' + inlines[n].s + ', inlines[n].e: ' + inlines[n].e)
|
|
452
|
+
while (i < marks.length) {
|
|
453
|
+
//console.log(marks[i].type, marks[i].s, inlines[n].e, marks[i].e, inlines[n].e)
|
|
454
|
+
//console.log(marks[i].s >= inlines[n].s , marks[i].e <= inlines[n].e)
|
|
455
|
+
if (marks[i].s >= inlines[n].s && marks[i].e <= inlines[n].e) {
|
|
456
|
+
//console.log('n: ' + n + ', i: ' + i + ', marks[i].type: ' + marks[i].type)
|
|
457
|
+
inlines.splice(n + i + 1, 0, marks[i])
|
|
458
|
+
i++
|
|
459
|
+
continue
|
|
460
|
+
}
|
|
461
|
+
break
|
|
462
|
+
}
|
|
463
|
+
if (marks.length) {
|
|
464
|
+
marks.splice(0, i)
|
|
465
|
+
inlines.splice(n, 1)
|
|
466
|
+
n += i
|
|
467
|
+
} else {
|
|
468
|
+
//if (inlines[n].type === '') inlines[n].type = 'text'
|
|
469
|
+
n++
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
358
474
|
const strongJa = (state, silent, opt) => {
|
|
359
475
|
if (silent) return false
|
|
360
476
|
const start = state.pos
|
|
@@ -371,6 +487,7 @@ const strongJa = (state, silent, opt) => {
|
|
|
371
487
|
}
|
|
372
488
|
if (start > max) return false
|
|
373
489
|
if (state.src.charCodeAt(start) !== 0x2A) return false
|
|
490
|
+
|
|
374
491
|
if (hasBackslash(state, start)) return false
|
|
375
492
|
//console.log('state.src.length: ' + state.src.length + ', start: ' + start + ', state.src: ' + state.src)
|
|
376
493
|
let inlines = createInlines(state, start, max, opt)
|
|
@@ -381,58 +498,42 @@ const strongJa = (state, silent, opt) => {
|
|
|
381
498
|
isEm: false,
|
|
382
499
|
hasEmThatWrapStrong: false,
|
|
383
500
|
noSetStrongEnd: false,
|
|
501
|
+
html: state.md.options.html,
|
|
502
|
+
htmlTags: {},
|
|
384
503
|
inlineMarkStart: state.src.charCodeAt(0) === 0x2A ? true : false,
|
|
385
504
|
inlineMarkEnd: state.src.charCodeAt(max - 1) === 0x2A ? true : false,
|
|
386
505
|
}
|
|
506
|
+
/*
|
|
507
|
+
if (memo.html) {
|
|
508
|
+
let beforeInlines = createInlines(state, 0, start - 1, opt)
|
|
509
|
+
isJumpTag(beforeInlines, beforeInlines.length - 1, memo)
|
|
510
|
+
}*/
|
|
387
511
|
let marks = createMarks(inlines, 0, inlines.length, memo)
|
|
388
512
|
//console.log('marks: ')
|
|
389
513
|
//console.log(marks)
|
|
390
514
|
|
|
391
|
-
|
|
392
|
-
while (n < inlines.length) {
|
|
393
|
-
if (inlines[n].type !== '') { n++; continue }
|
|
394
|
-
let i = 0
|
|
395
|
-
//console.log('n: ' + n + ', inlines[n].s: ' + inlines[n].s + ', inlines[n].e: ' + inlines[n].e)
|
|
396
|
-
let c = 0
|
|
397
|
-
while (i < marks.length) {
|
|
398
|
-
//console.log(marks[i].s, inlines[n].e, marks[i].e, inlines[n].e)
|
|
399
|
-
//console.log(marks[i].s >= inlines[n].s , marks[i].e <= inlines[n].e)
|
|
400
|
-
if (marks[i].s >= inlines[n].s && marks[i].e <= inlines[n].e) {
|
|
401
|
-
//console.log('n: ' + n + ', i: ' + i + ', marks[i].type: ' + marks[i].type)
|
|
402
|
-
inlines.splice(n + i + 1, 0, marks[i])
|
|
403
|
-
c++
|
|
404
|
-
i++
|
|
405
|
-
continue
|
|
406
|
-
}
|
|
407
|
-
break
|
|
408
|
-
}
|
|
409
|
-
if (marks.length) {
|
|
410
|
-
marks.splice(0, c)
|
|
411
|
-
inlines.splice(n, 1)
|
|
412
|
-
n += c
|
|
413
|
-
} else {
|
|
414
|
-
inlines[n].type = 'text'
|
|
415
|
-
n++
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
515
|
+
fixInlines(inlines, marks)
|
|
419
516
|
//console.log('fix inlines:')
|
|
420
517
|
//console.log(inlines)
|
|
518
|
+
|
|
421
519
|
setToken(state, inlines)
|
|
422
520
|
|
|
423
|
-
//console.log('state.pos: ' + state.pos + ', inlines[inlines.length - 1].e + 1: ' + (inlines[inlines.length - 1].e + 1) + ', max: ' + max)
|
|
424
|
-
state.pos = inlines[inlines.length - 1].e + 1
|
|
425
521
|
if (attributesSrc) {
|
|
522
|
+
//console.log('attributesSrc[1].length: ' + attributesSrc[1].length)
|
|
426
523
|
if (attributesSrc[1].length > 1) {
|
|
427
|
-
|
|
524
|
+
state.pos = max + attributesSrc[1].length
|
|
525
|
+
} else {
|
|
526
|
+
state.pos = max
|
|
428
527
|
}
|
|
528
|
+
} else {
|
|
529
|
+
state.pos = max + 1
|
|
429
530
|
}
|
|
430
531
|
return true
|
|
431
532
|
}
|
|
432
533
|
|
|
433
534
|
const mditStrongJa = (md, option) => {
|
|
434
535
|
const opt = {
|
|
435
|
-
dollarMath: true
|
|
536
|
+
dollarMath: true,
|
|
436
537
|
}
|
|
437
538
|
if (option !== undefined) {
|
|
438
539
|
for (let o in option) {
|
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.3.
|
|
4
|
+
"version": "0.3.3",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
package/test/example-complex.txt
CHANGED
|
@@ -146,9 +146,9 @@ a[*](https://example*.com)*b*
|
|
|
146
146
|
<p><strong>重要な文・文節や語句</strong>は<code>**</code>を使って囲みます。<em>文脈上強調する語句</em>は<code>*</code>を使って囲みます。</p>
|
|
147
147
|
|
|
148
148
|
[Markdown]
|
|
149
|
-
|
|
149
|
+
インラインコードは`*`と`*`で*囲みます*。
|
|
150
150
|
[HTML]
|
|
151
|
-
<p
|
|
151
|
+
<p>インラインコードは<code>*</code>と<code>*</code>で<em>囲みます</em>。</p>
|
|
152
152
|
|
|
153
153
|
[Markdown]
|
|
154
154
|
[node_modules/*](#)の*はすべてを意味します。
|
|
@@ -184,3 +184,77 @@ a**b**{.style}
|
|
|
184
184
|
a**b**c {.style}
|
|
185
185
|
[HTML]
|
|
186
186
|
<p class="style">a<strong>b</strong>c</p>
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
[Markdown]
|
|
190
|
+
z*a<span>b*c</span>d*e
|
|
191
|
+
[HTML]
|
|
192
|
+
<p>z<em>a<span>b</em>c</span>d*e</p>
|
|
193
|
+
[HTML:true]
|
|
194
|
+
<p>z*a<span>b*c</span>d*e</p>
|
|
195
|
+
|
|
196
|
+
[Markdown]
|
|
197
|
+
a<span>b*c</span>d*e*f
|
|
198
|
+
[HTML]
|
|
199
|
+
<p>a<span>b<em>c</span>d</em>e*f</p>
|
|
200
|
+
[HTML:true]
|
|
201
|
+
<p>a<span>b*c</span>d<em>e</em>f</p>
|
|
202
|
+
|
|
203
|
+
[Markdown]
|
|
204
|
+
a*a<span>b</span>c*c
|
|
205
|
+
[HTML:false]
|
|
206
|
+
<p>a<em>a<span>b</span>c</em>c</p>
|
|
207
|
+
[HTML:true]
|
|
208
|
+
<p>a<em>a<span>b</span>c</em>c</p>
|
|
209
|
+
|
|
210
|
+
[Markdown]
|
|
211
|
+
aa<span>b*ef*</span>cc
|
|
212
|
+
[HTML:false]
|
|
213
|
+
<p>aa<span>b<em>ef</em></span>cc</p>
|
|
214
|
+
[HTML:true]
|
|
215
|
+
<p>aa<span>b<em>ef</em></span>cc</p>
|
|
216
|
+
|
|
217
|
+
[Markdown]
|
|
218
|
+
a*a<span>b*ef*</span>c*c
|
|
219
|
+
[HTML:false]
|
|
220
|
+
<p>a<em>a<span>b</em>ef<em></span>c</em>c</p>
|
|
221
|
+
[HTML:true, commonmark: <p>a<em>a<span>b</em>ef*</span>c*c</p>]
|
|
222
|
+
<p>a<em>a<span>b<em>ef</em></span>c</em>c</p>
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
[Markdown]
|
|
226
|
+
a***a<span>b</span>c***c
|
|
227
|
+
[HTML:false]
|
|
228
|
+
<p>a<em><strong>a<span>b</span>c</strong></em>c</p>
|
|
229
|
+
[HTML:true]
|
|
230
|
+
<p>a<em><strong>a<span>b</span>c</strong></em>c</p>
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
[Markdown]
|
|
234
|
+
a***a<span>b***e</span>cc
|
|
235
|
+
[HTML:false]
|
|
236
|
+
<p>a<em><strong>a<span>b</strong></em>e</span>cc</p>
|
|
237
|
+
[HTML:true]
|
|
238
|
+
<p>a***a<span>b***e</span>cc</p>
|
|
239
|
+
|
|
240
|
+
[Markdown]
|
|
241
|
+
aa<span>b*e<s>f</s>*</span>cc
|
|
242
|
+
[HTML:false]
|
|
243
|
+
<p>aa<span>b<em>e<s>f</s></em></span>cc</p>
|
|
244
|
+
[HTML:true]
|
|
245
|
+
<p>aa<span>b<em>e<s>f</s></em></span>cc</p>
|
|
246
|
+
|
|
247
|
+
[Markdown]
|
|
248
|
+
**aa<span>b*e<s>f</s>*</span>cc**
|
|
249
|
+
[HTML:false]
|
|
250
|
+
<p><strong>aa<span>b<em>e<s>f</s></em></span>cc</strong></p>
|
|
251
|
+
[HTML:true]
|
|
252
|
+
<p><strong>aa<span>b<em>e<s>f</s></em></span>cc</strong></p>
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
[Markdown]
|
|
256
|
+
*aa<span>b**e<s>f</s>**</span>cc*
|
|
257
|
+
[HTML:false]
|
|
258
|
+
<p><em>aa<span>b<strong>e<s>f</s></strong></span>cc</em></p>
|
|
259
|
+
[HTML:true]
|
|
260
|
+
<p><em>aa<span>b<strong>e<s>f</s></strong></span>cc</em></p>
|
package/test/example-strong.txt
CHANGED
package/test/test.js
CHANGED
|
@@ -14,7 +14,8 @@ const check = (ms, example) => {
|
|
|
14
14
|
const mdWithHtml = mdit({html: true}).use(mditStrongJa).use(mditAttrs)
|
|
15
15
|
let n = 1
|
|
16
16
|
while (n < ms.length) {
|
|
17
|
-
|
|
17
|
+
//if (n !== 43 ) { n++; continue }
|
|
18
|
+
//if (n !== 36 ) { n++; continue }
|
|
18
19
|
const m = ms[n].markdown
|
|
19
20
|
console.log('Test [' + n + ', HTML: false] >>>')
|
|
20
21
|
const h = md.render(m)
|
|
@@ -23,7 +24,6 @@ const check = (ms, example) => {
|
|
|
23
24
|
} catch(e) {
|
|
24
25
|
console.log('Input: ' + ms[n].markdown + '\nConvert: ' + h + 'Correct: ' + ms[n].html)
|
|
25
26
|
}
|
|
26
|
-
|
|
27
27
|
if (ms[n].htmlWithHtmlTrue) {
|
|
28
28
|
console.log('Test [' + n + ', HTML: true] >>>')
|
|
29
29
|
const hh = mdWithHtml.render(m)
|