@peaceroad/markdown-it-strong-ja 0.3.3 → 0.3.5
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 +36 -29
- package/package.json +1 -1
- package/test/example-complex.txt +107 -1
- package/test/test.js +2 -2
package/index.js
CHANGED
|
@@ -85,32 +85,39 @@ const hasNextSymbol = (state, n, max, symbol, noMark) => {
|
|
|
85
85
|
while (i < max) {
|
|
86
86
|
tempNoMark += state.src[i]
|
|
87
87
|
if (state.src.charCodeAt(i) === symbol && !hasBackslash(state, i)) {
|
|
88
|
-
noMark += state.src
|
|
88
|
+
noMark += state.src.substring(n, i + 1)
|
|
89
89
|
nextSymbolPos = i
|
|
90
90
|
break
|
|
91
91
|
}
|
|
92
92
|
i++
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
return nextSymbolPos
|
|
95
|
+
return [nextSymbolPos, noMark]
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
const createInlines = (state, start, max, opt) => {
|
|
99
99
|
let n = start
|
|
100
100
|
let inlines = []
|
|
101
101
|
let noMark = ''
|
|
102
|
-
let isInStartMark = true
|
|
103
102
|
let textStart = n
|
|
104
|
-
|
|
105
103
|
while (n < max) {
|
|
106
|
-
let nextSymbolPos =
|
|
104
|
+
let nextSymbolPos = -1;
|
|
105
|
+
[nextSymbolPos, noMark] = hasNextSymbol(state, n, max, 0x60, noMark) // '`'
|
|
107
106
|
if (nextSymbolPos !== -1) {
|
|
107
|
+
if (nextSymbolPos === max - 1) {
|
|
108
|
+
inlinesPush(inlines, textStart, nextSymbolPos, nextSymbolPos - textStart + 1, 'text')
|
|
109
|
+
break
|
|
110
|
+
}
|
|
108
111
|
n = nextSymbolPos + 1
|
|
109
112
|
continue
|
|
110
113
|
}
|
|
111
114
|
if (opt.dollarMath) {
|
|
112
|
-
nextSymbolPos = hasNextSymbol(state, n, max, 0x24, noMark) // '$'
|
|
115
|
+
[nextSymbolPos, noMark] = hasNextSymbol(state, n, max, 0x24, noMark) // '$'
|
|
113
116
|
if (nextSymbolPos !== -1) {
|
|
117
|
+
if (nextSymbolPos === max - 1) {
|
|
118
|
+
inlinesPush(inlines, textStart, nextSymbolPos, nextSymbolPos - textStart + 1, 'text')
|
|
119
|
+
break
|
|
120
|
+
}
|
|
114
121
|
n = nextSymbolPos + 1
|
|
115
122
|
continue
|
|
116
123
|
}
|
|
@@ -142,9 +149,8 @@ const createInlines = (state, start, max, opt) => {
|
|
|
142
149
|
continue
|
|
143
150
|
}
|
|
144
151
|
}
|
|
145
|
-
|
|
146
152
|
if (state.src.charCodeAt(n) === 0x2A && !hasBackslash(state, n)) { // '*'
|
|
147
|
-
if (
|
|
153
|
+
if (n !== 0) {
|
|
148
154
|
inlinesPush(inlines, textStart, n - 1, n - textStart, 'text')
|
|
149
155
|
}
|
|
150
156
|
if (n === max - 1) {
|
|
@@ -165,10 +171,8 @@ const createInlines = (state, start, max, opt) => {
|
|
|
165
171
|
n = i
|
|
166
172
|
continue
|
|
167
173
|
}
|
|
168
|
-
isInStartMark = false
|
|
169
174
|
noMark += state.src[n]
|
|
170
|
-
|
|
171
|
-
if (n === max - 1 || max < 3) {
|
|
175
|
+
if (n === max - 1) {
|
|
172
176
|
inlinesPush(inlines, textStart, n, n - textStart + 1, 'text')
|
|
173
177
|
break
|
|
174
178
|
}
|
|
@@ -235,9 +239,9 @@ const setStrong = (inlines, marks, n, memo) => {
|
|
|
235
239
|
if (i > inlines.length - 1) return n, nest, memo
|
|
236
240
|
}
|
|
237
241
|
|
|
242
|
+
//console.log('memo.html: ' + memo.html + 'insideTagsIsClose: ' + insideTagsIsClose + 'inlines[i].len: ' + inlines[i].len)
|
|
238
243
|
if (memo.html && !insideTagsIsClose && inlines[i].len !== 1) {
|
|
239
|
-
|
|
240
|
-
return n, nest, memo
|
|
244
|
+
i++; continue
|
|
241
245
|
}
|
|
242
246
|
let strongNum = Math.trunc(Math.min(inlines[n].len, inlines[i].len) / 2)
|
|
243
247
|
|
|
@@ -258,7 +262,8 @@ const setStrong = (inlines, marks, n, memo) => {
|
|
|
258
262
|
if (inlines[n].len === 0) return n, nest, memo
|
|
259
263
|
}
|
|
260
264
|
|
|
261
|
-
|
|
265
|
+
//console.log('len: ', inlines[n].len, inlines[i].len)
|
|
266
|
+
if ((inlines[n].len > 0 && inlines[i] === 1) || (inlines[n].len === 1 && inlines[i].len > 0)) {
|
|
262
267
|
//console.log('check em that warp strong.')
|
|
263
268
|
nest++
|
|
264
269
|
n, nest, memo = setEm(inlines, marks, n, memo, nest)
|
|
@@ -345,8 +350,7 @@ const setEm = (inlines, marks, n, memo, sNest) => {
|
|
|
345
350
|
if (emNum === 1) {
|
|
346
351
|
//console.log(n, i, 'insideTagsIsClose: ' + insideTagsIsClose)
|
|
347
352
|
if (memo.html && !insideTagsIsClose && inlines[i].len !== 2) {
|
|
348
|
-
|
|
349
|
-
return n, nest, memo
|
|
353
|
+
i++; continue;
|
|
350
354
|
}
|
|
351
355
|
//console.log('n: ' + n + ' [em]: normal push, nest: ' + nest)
|
|
352
356
|
//console.log('strongPNum: ' + strongPNum)
|
|
@@ -391,6 +395,7 @@ const checkNest = (inlines, marks, n, i) => {
|
|
|
391
395
|
let strongNest = 0
|
|
392
396
|
let emNest = 0
|
|
393
397
|
let j = 0
|
|
398
|
+
//console.log(inlines)
|
|
394
399
|
//console.log(marks)
|
|
395
400
|
//console.log('n: ' + n + ', i: ' + i + ', inlines[n].s: ' + inlines[n].s + ', inlines[i].s: ' + inlines[i].s)
|
|
396
401
|
while (j < marks.length) {
|
|
@@ -408,10 +413,16 @@ const checkNest = (inlines, marks, n, i) => {
|
|
|
408
413
|
if (parentCloseN < marks.length) {
|
|
409
414
|
while (parentCloseN < marks.length) {
|
|
410
415
|
if (marks[parentCloseN].nest === parentNest) break
|
|
416
|
+
//if (marks.length - 1 == parentCloseN) break
|
|
411
417
|
parentCloseN++
|
|
412
418
|
}
|
|
413
|
-
//console.log(parentCloseN
|
|
414
|
-
if (marks
|
|
419
|
+
//console.log('parentCloseN: ' + parentCloseN)
|
|
420
|
+
if (parentCloseN > marks.length - 1) {
|
|
421
|
+
isRange = true
|
|
422
|
+
} else {
|
|
423
|
+
//console.log(marks[parentCloseN].s, i, inlines[i].s)
|
|
424
|
+
if (marks[parentCloseN].s < inlines[i].s) isRange = false
|
|
425
|
+
}
|
|
415
426
|
}
|
|
416
427
|
//console.log('isRange: ' + isRange)
|
|
417
428
|
|
|
@@ -431,13 +442,13 @@ const createMarks = (inlines, start, end, memo) => {
|
|
|
431
442
|
memo.isEm = inlines[n].len === 1 ? true : false
|
|
432
443
|
memo.wrapEm = 0
|
|
433
444
|
let nest = 0
|
|
434
|
-
|
|
445
|
+
//console.log('n: ' + n + ' ----- inlines.length: ' + inlines.length + ', memo.isEm: ' + memo.isEm)
|
|
435
446
|
if (!memo.isEm) {
|
|
436
447
|
n, nest, memo = setStrong(inlines, marks, n, memo)
|
|
437
448
|
}
|
|
438
449
|
n, nest, memo = setEm(inlines, marks, n, memo)
|
|
439
|
-
|
|
440
450
|
if (inlines[n].len !== 0) setText(inlines, marks, n, nest)
|
|
451
|
+
//console.log(marks)
|
|
441
452
|
n++
|
|
442
453
|
}
|
|
443
454
|
return marks
|
|
@@ -475,11 +486,8 @@ const strongJa = (state, silent, opt) => {
|
|
|
475
486
|
if (silent) return false
|
|
476
487
|
const start = state.pos
|
|
477
488
|
let max = state.posMax
|
|
478
|
-
const hasCurlyAttributes = state.md.core.ruler.__rules__.filter(rule => {
|
|
479
|
-
rule.name === 'curly_attributes' // markdown-it-attrs
|
|
480
|
-
})
|
|
481
489
|
let attributesSrc
|
|
482
|
-
if (hasCurlyAttributes) {
|
|
490
|
+
if (opt.hasCurlyAttributes) {
|
|
483
491
|
attributesSrc = state.src.match(/( *){.*?}$/)
|
|
484
492
|
if (attributesSrc) {
|
|
485
493
|
max = state.src.slice(0, attributesSrc.index).length
|
|
@@ -503,11 +511,6 @@ const strongJa = (state, silent, opt) => {
|
|
|
503
511
|
inlineMarkStart: state.src.charCodeAt(0) === 0x2A ? true : false,
|
|
504
512
|
inlineMarkEnd: state.src.charCodeAt(max - 1) === 0x2A ? true : false,
|
|
505
513
|
}
|
|
506
|
-
/*
|
|
507
|
-
if (memo.html) {
|
|
508
|
-
let beforeInlines = createInlines(state, 0, start - 1, opt)
|
|
509
|
-
isJumpTag(beforeInlines, beforeInlines.length - 1, memo)
|
|
510
|
-
}*/
|
|
511
514
|
let marks = createMarks(inlines, 0, inlines.length, memo)
|
|
512
515
|
//console.log('marks: ')
|
|
513
516
|
//console.log(marks)
|
|
@@ -534,7 +537,11 @@ const strongJa = (state, silent, opt) => {
|
|
|
534
537
|
const mditStrongJa = (md, option) => {
|
|
535
538
|
const opt = {
|
|
536
539
|
dollarMath: true,
|
|
540
|
+
hasCurlyAttributes: false,
|
|
537
541
|
}
|
|
542
|
+
opt.hasCurlyAttributes = md.core.ruler.__rules__.filter(rule => {
|
|
543
|
+
rule.name === 'curly_attributes' // markdown-it-attrs
|
|
544
|
+
})
|
|
538
545
|
if (option !== undefined) {
|
|
539
546
|
for (let o in option) {
|
|
540
547
|
opt[o] = option[o]
|
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.5",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
package/test/example-complex.txt
CHANGED
|
@@ -191,7 +191,7 @@ z*a<span>b*c</span>d*e
|
|
|
191
191
|
[HTML]
|
|
192
192
|
<p>z<em>a<span>b</em>c</span>d*e</p>
|
|
193
193
|
[HTML:true]
|
|
194
|
-
<p>z
|
|
194
|
+
<p>z<em>a<span>b*c</span>d</em>e</p>
|
|
195
195
|
|
|
196
196
|
[Markdown]
|
|
197
197
|
a<span>b*c</span>d*e*f
|
|
@@ -258,3 +258,109 @@ aa<span>b*e<s>f</s>*</span>cc
|
|
|
258
258
|
<p><em>aa<span>b<strong>e<s>f</s></strong></span>cc</em></p>
|
|
259
259
|
[HTML:true]
|
|
260
260
|
<p><em>aa<span>b<strong>e<s>f</s></strong></span>cc</em></p>
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
[Markdown]
|
|
264
|
+
*ab
|
|
265
|
+
[HTML]
|
|
266
|
+
<p>*ab</p>
|
|
267
|
+
[HTML:true]
|
|
268
|
+
<p>*ab</p>
|
|
269
|
+
|
|
270
|
+
[Markdown]
|
|
271
|
+
*a<span>b</span>
|
|
272
|
+
[HTML]
|
|
273
|
+
<p>*a<span>b</span></p>
|
|
274
|
+
[HTML:true]
|
|
275
|
+
<p>*a<span>b</span></p>
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
[Markdown]
|
|
279
|
+
bc*
|
|
280
|
+
[HTML]
|
|
281
|
+
<p>bc*</p>
|
|
282
|
+
[HTML:true]
|
|
283
|
+
<p>bc*</p>
|
|
284
|
+
|
|
285
|
+
[Markdown]
|
|
286
|
+
b<span>c</span>*
|
|
287
|
+
[HTML]
|
|
288
|
+
<p>b<span>c</span>*</p>
|
|
289
|
+
[HTML:true]
|
|
290
|
+
<p>b<span>c</span>*</p>
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
[Markdown]
|
|
294
|
+
***a***
|
|
295
|
+
[HTML]
|
|
296
|
+
<p><em><strong>a</strong></em></p>
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
[Markdown]
|
|
300
|
+
****a***
|
|
301
|
+
[HTML]
|
|
302
|
+
<p>*<em><strong>a</strong></em></p>
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
[Markdown]
|
|
306
|
+
***a****
|
|
307
|
+
[HTML]
|
|
308
|
+
<p><em><strong>a</strong></em>*</p>
|
|
309
|
+
|
|
310
|
+
[Markdown]
|
|
311
|
+
*****a***
|
|
312
|
+
[HTML]
|
|
313
|
+
<p>**<em><strong>a</strong></em></p>
|
|
314
|
+
|
|
315
|
+
[Markdown]
|
|
316
|
+
*****a*****
|
|
317
|
+
[HTML]
|
|
318
|
+
<p><em><strong><strong>a</strong></strong></em></p>
|
|
319
|
+
|
|
320
|
+
[Markdown]
|
|
321
|
+
******a******
|
|
322
|
+
[HTML]
|
|
323
|
+
<p><strong><strong><strong>a</strong></strong></strong></p>
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
[Markdown]
|
|
327
|
+
***a*b*
|
|
328
|
+
[HTML]
|
|
329
|
+
<p>*<em><em>a</em>b</em></p>
|
|
330
|
+
|
|
331
|
+
[Markdown]
|
|
332
|
+
***<span>a</span>*b*
|
|
333
|
+
[HTML]
|
|
334
|
+
<p>*<em><em><span>a</span></em>b</em></p>
|
|
335
|
+
[HTML: true]
|
|
336
|
+
<p>*<em><em><span>a</span></em>b</em></p>
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
[Markdown]
|
|
340
|
+
*`a`*
|
|
341
|
+
[HTML]
|
|
342
|
+
<p><em><code>a</code></em></p>
|
|
343
|
+
|
|
344
|
+
[Markdown]
|
|
345
|
+
**z`a`b**
|
|
346
|
+
[HTML]
|
|
347
|
+
<p><strong>z<code>a</code>b</strong></p>
|
|
348
|
+
|
|
349
|
+
[Markdown]
|
|
350
|
+
**`a`
|
|
351
|
+
[HTML]
|
|
352
|
+
<p>**<code>a</code></p>
|
|
353
|
+
|
|
354
|
+
[Markdown]
|
|
355
|
+
**<b>a</b>**
|
|
356
|
+
[HTML:false]
|
|
357
|
+
<p><strong><b>a</b></strong></p>
|
|
358
|
+
[HTML:true]
|
|
359
|
+
<p><strong><b>a</b></strong></p>
|
|
360
|
+
|
|
361
|
+
[Markdown]
|
|
362
|
+
**<br>
|
|
363
|
+
[HTML:false]
|
|
364
|
+
<p>**<br></p>
|
|
365
|
+
[HTML:true]
|
|
366
|
+
<p>**<br></p>
|
package/test/test.js
CHANGED
|
@@ -14,8 +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
|
-
//if (n !==
|
|
18
|
-
//if (n !==
|
|
17
|
+
//if (n !== 23 ) { n++; continue }
|
|
18
|
+
//if (n !== 59 ) { n++; continue }
|
|
19
19
|
const m = ms[n].markdown
|
|
20
20
|
console.log('Test [' + n + ', HTML: false] >>>')
|
|
21
21
|
const h = md.render(m)
|