@peaceroad/markdown-it-strong-ja 0.4.0 → 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/index.js +23 -25
- package/package.json +1 -1
- package/test/example-complex.txt +26 -1
- package/test/mditNoAttrs/example-complex.txt +33 -1
- package/test/test.js +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const REG_ASTERISKS = /^\*+$/
|
|
2
2
|
const REG_ATTRS = /{[^{}\n!@#%^&*()]+?}$/
|
|
3
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
|
|
4
5
|
|
|
5
6
|
const hasBackslash = (state, start) => {
|
|
6
7
|
let slashNum = 0
|
|
@@ -314,19 +315,20 @@ const setStrong = (state, inlines, marks, n, memo, opt) => {
|
|
|
314
315
|
let strongNum = Math.trunc(Math.min(inlines[n].len, inlines[i].len) / 2)
|
|
315
316
|
|
|
316
317
|
if (inlines[i].len > 1) {
|
|
317
|
-
|
|
318
|
-
|
|
318
|
+
//console.log(' hasPunctuationOrNonJapanese: ' + hasPunctuationOrNonJapanese(state, inlines, n, i) + ', memo.inlineMarkEnd: ' + memo.inlineMarkEnd)
|
|
319
|
+
|
|
320
|
+
if (hasPunctuationOrNonJapanese(state, inlines, n, i)) {
|
|
319
321
|
if (memo.inlineMarkEnd) {
|
|
320
322
|
//console.log('check nest em.')
|
|
321
323
|
//console.log('~~~~~~~~~~~~~~~~~')
|
|
322
|
-
|
|
324
|
+
marks.push(...createMarks(state, inlines, i, inlines.length - 1, memo, opt))
|
|
323
325
|
//console.log('~~~~~~~~~~~~~~~~~')
|
|
324
326
|
if (inlines[i].len === 0) { i++; continue }
|
|
325
327
|
} else {
|
|
326
328
|
return n, nest
|
|
327
329
|
}
|
|
328
330
|
}
|
|
329
|
-
|
|
331
|
+
//console.log(' ===> strong normal push. n: ' + n + ', i: ' + i + ' , nest: ' + nest + ',strongNum: ' + strongNum)
|
|
330
332
|
|
|
331
333
|
j = 0
|
|
332
334
|
while (j < strongNum) {
|
|
@@ -357,7 +359,7 @@ const setStrong = (state, inlines, marks, n, memo, opt) => {
|
|
|
357
359
|
}
|
|
358
360
|
|
|
359
361
|
if (inlines[n].len === 1 && inlines[i].len > 0) {
|
|
360
|
-
|
|
362
|
+
//console.log(' check em that warp strong.')
|
|
361
363
|
nest++
|
|
362
364
|
n, nest = setEm(state, inlines, marks, n, memo, opt, nest)
|
|
363
365
|
}
|
|
@@ -402,26 +404,22 @@ const checkInsideTags = (inlines, i, memo) => {
|
|
|
402
404
|
const isPunctuation = (ch) => {
|
|
403
405
|
return REG_PUNCTUATION.test(ch)
|
|
404
406
|
}
|
|
407
|
+
const isJapanese = (ch) => {
|
|
408
|
+
return REG_JAPANESE.test(ch)
|
|
409
|
+
}
|
|
405
410
|
|
|
406
|
-
const
|
|
411
|
+
const hasPunctuationOrNonJapanese = (state, inlines, n, i) => {
|
|
407
412
|
const src = state.src
|
|
408
|
-
const
|
|
409
|
-
//const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
//console.log('openPrevChar: ' + openPrevChar + ', openNextChar: ' + openNextChar + ', closePrevChar: ' + closePrevChar + ', closeNextChar: ' + closeNextChar + ', lastCharIsAsterisk: ' + lastCharIsAsterisk + ', firstCharIsAsterisk: ' + firstCharIsAsterisk + ', next condition: ' + ((openNextChar || closePrevChar) && !closeNextChar))
|
|
419
|
-
//if ((openNextChar || closePrevChar) && !closeNextChar) {
|
|
420
|
-
if ((openNextChar || closePrevChar) && !closeNextChar) {
|
|
421
|
-
return true
|
|
422
|
-
} else {
|
|
423
|
-
return false
|
|
424
|
-
}
|
|
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
|
|
425
423
|
}
|
|
426
424
|
|
|
427
425
|
const setEm = (state, inlines, marks, n, memo, opt, sNest) => {
|
|
@@ -470,8 +468,8 @@ const setEm = (state, inlines, marks, n, memo, opt, sNest) => {
|
|
|
470
468
|
if (nest === -1) return n, nest
|
|
471
469
|
|
|
472
470
|
if (emNum === 1) {
|
|
473
|
-
//console.log('
|
|
474
|
-
if (
|
|
471
|
+
//console.log(' hasPunctuationOrNonJapanese: ' + hasPunctuationOrNonJapanese(state, inlines, n, i) + ', memo.inlineMarkEnd: ' + memo.inlineMarkEnd)
|
|
472
|
+
if (hasPunctuationOrNonJapanese(state, inlines, n, i)) {
|
|
475
473
|
if (memo.inlineMarkEnd) {
|
|
476
474
|
//console.log('check nest em.')
|
|
477
475
|
//console.log('~~~~~~~~~~~~~~~~~')
|
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.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
package/test/example-complex.txt
CHANGED
|
@@ -478,4 +478,29 @@ e*z<span> *a*b*
|
|
|
478
478
|
[HTML:false]
|
|
479
479
|
<p>*<strong><sPan>a</spaN>b</strong></p>
|
|
480
480
|
[HTML:true]
|
|
481
|
-
<p>*<strong><sPan>a</spaN>b</strong></p>
|
|
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>
|
|
@@ -477,4 +477,36 @@ e*z<span> *a*b*
|
|
|
477
477
|
[HTML:false]
|
|
478
478
|
<p>*<strong><sPan>a</spaN>b</strong></p>
|
|
479
479
|
[HTML:true]
|
|
480
|
-
<p>*<strong><sPan>a</spaN>b</strong></p>
|
|
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') {
|