@peaceroad/markdown-it-strong-ja 0.4.1 → 0.4.2

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 CHANGED
@@ -85,7 +85,7 @@ const setToken = (state, inlines, opt) => {
85
85
  let j = 0
86
86
  while (j < childTokens[0].children.length) {
87
87
  const t = childTokens[0].children[j]
88
- if (t.type === 'softbreak') {
88
+ if (t.type === 'softbreak' && !opt.mdBreaks) {
89
89
  t.type = 'text'
90
90
  t.tag = ''
91
91
  t.content = '\n'
@@ -705,6 +705,7 @@ const mditStrongJa = (md, option) => {
705
705
  const opt = {
706
706
  dollarMath: true, //inline math $...$
707
707
  mditAttrs: true, //markdown-it-attrs
708
+ mdBreaks: md.options.breaks,
708
709
  }
709
710
  if (option) Object.assign(opt, option)
710
711
 
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.1",
4
+ "version": "0.4.2",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
@@ -0,0 +1,46 @@
1
+ [Markdown]
2
+ 吾輩は猫である。名前は<span>まだ</span>無い。
3
+ どこで生れたか*とんと見当*が<span>つかぬ</span>。
4
+ 何でも薄暗い*じめじめした所*でニャーニャー泣いていた事だけは記憶している。
5
+ [HTML:false]
6
+ <p>吾輩は猫である。名前は&lt;span&gt;まだ&lt;/span&gt;無い。<br>
7
+ どこで生れたか<em>とんと見当</em>が&lt;span&gt;つかぬ&lt;/span&gt;。<br>
8
+ 何でも薄暗い<em>じめじめした所</em>でニャーニャー泣いていた事だけは記憶している。</p>
9
+ [HTML:true]
10
+ <p>吾輩は猫である。名前は<span>まだ</span>無い。<br>
11
+ どこで生れたか<em>とんと見当</em>が<span>つかぬ</span>。<br>
12
+ 何でも薄暗い<em>じめじめした所</em>でニャーニャー泣いていた事だけは記憶している。</p>
13
+
14
+ [Markdown]
15
+ a*b
16
+ c*d
17
+ [HTML:false]
18
+ <p>a<em>b<br>
19
+ c</em>d</p>
20
+ [HTML:true]
21
+ <p>a<em>b<br>
22
+ c</em>d</p>
23
+
24
+ [Markdown]
25
+ a**b
26
+ c*d*e**f
27
+ [HTML:false]
28
+ <p>a<strong>b<br>
29
+ c<em>d</em>e</strong>f</p>
30
+ [HTML:true]
31
+ <p>a<strong>b<br>
32
+ c<em>d</em>e</strong>f</p>
33
+
34
+ [Markdown]
35
+ - *aあ {.li-style}
36
+ \{.ul-style} aa {.next-li-style}
37
+ [HTML:false]
38
+ <ul>
39
+ <li>*aあ {.li-style}<br>
40
+ {.ul-style} aa {.next-li-style}</li>
41
+ </ul>
42
+ [HTML:true]
43
+ <ul>
44
+ <li>*aあ {.li-style}<br>
45
+ {.ul-style} aa {.next-li-style}</li>
46
+ </ul>
package/test/test.js CHANGED
@@ -20,6 +20,10 @@ const mditNoAttrsWithHtml = mdit({html: true}).use(mditStrongJa, {mditAttrs: fal
20
20
  const mditNoAttrsCJKBreaks = mdit().use(mditStrongJa, {mditAttrs: false}).use(mditCJKBreaks, {either: true})
21
21
  const mditNoAttrsCJKBreaksWithHtml = mdit({html: true}).use(mditStrongJa, {mditAttrs: false}).use(mditCJKBreaks, {either: true})
22
22
 
23
+ const mditNoAttrsLinebreak = mdit({breaks: true}).use(mditStrongJa, {mditAttrs: false})
24
+ const mditNoAttrsLinebreakWithHtml = mdit({html: true, breaks: true}).use(mditStrongJa, {mditAttrs: false})
25
+
26
+
23
27
  const check = (ms, example, allPass, useAttrs) => {
24
28
  let n = 1
25
29
  while (n < ms.length) {
@@ -58,6 +62,34 @@ const check = (ms, example, allPass, useAttrs) => {
58
62
  return allPass
59
63
  }
60
64
 
65
+ const checkBreaks = (ms, example, allPass, useAttrs) => {
66
+ let n = 1
67
+ while (n < ms.length) {
68
+ //if (n !== 81) { n++; continue }
69
+ const m = ms[n].markdown
70
+ const h = mditNoAttrsLinebreak.render(ms[n].markdown);
71
+ try {
72
+ assert.strictEqual(h, ms[n].html);
73
+ } catch(e) {
74
+ console.log('Test [linebreak, HTML: false, useAttrs: ' + useAttrs + '] >>>');
75
+ console.log('Input: ' + ms[n].markdown + '\nOutput: ' + h + ' Correct: ' + ms[n].html)
76
+ allPass = false
77
+ }
78
+ if (ms[n].htmlWithHtmlTrue) {
79
+ let hh = mditNoAttrsLinebreakWithHtml.render(ms[n].markdown)
80
+ try {
81
+ assert.strictEqual(hh, ms[n].htmlWithHtmlTrue)
82
+ } catch(e) {
83
+ console.log('Test [' + n + ', HTML: true, useAttrs: ' + useAttrs + '] >>>')
84
+ console.log('Input: ' + ms[n].markdown + '\nOutput: ' + hh + 'Correct: ' + ms[n].htmlWithHtmlTrue)
85
+ allPass = false
86
+ }
87
+ }
88
+ n++
89
+ }
90
+ return allPass
91
+ }
92
+
61
93
  const examples = {
62
94
  strong: __dirname + '/example-strong.txt',
63
95
  em: __dirname + '/example-em.txt',
@@ -72,7 +104,11 @@ const examplesMditNoAttrs = {
72
104
  withLineBreak: __dirname + '/mditNoAttrs/example-with-linebreak.txt',
73
105
  }
74
106
 
75
- const runTests = (examples, useAttrs) => {
107
+ const examplesMditBreaks = {
108
+ linebreak: __dirname + '/mditNoAttrs/example-mdit-linebrek.txt',
109
+ }
110
+
111
+ const runTests = (examples, checkFunction, useAttrs) => {
76
112
  let allPass = true
77
113
  for (let example in examples) {
78
114
  const exampleCont = fs.readFileSync(examples[example], 'utf-8').trim()
@@ -98,12 +134,13 @@ const runTests = (examples, useAttrs) => {
98
134
  n++
99
135
  }
100
136
  console.log('Check ' + example + ' process [mditAttrs: ' + useAttrs + '] =======================')
101
- allPass = check(ms, example, allPass, useAttrs)
137
+ allPass = checkFunction(ms, example, allPass, useAttrs)
102
138
  }
103
139
  return allPass
104
140
  }
105
141
 
106
- let allPass = runTests(examples, true)
107
- allPass = runTests(examplesMditNoAttrs, false) && allPass
142
+ let allPass = runTests(examples, check, true)
143
+ allPass = runTests(examplesMditNoAttrs, check, false) && allPass
144
+ allPass = runTests(examplesMditBreaks, checkBreaks, false) && allPass
108
145
 
109
146
  if (allPass) console.log('Passed all tests.')