@peaceroad/markdown-it-strong-ja 0.1.2 → 0.1.4

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
@@ -1,6 +1,4 @@
1
- import mdit from 'markdown-it'
2
-
3
- const strongJa = (state, silent, mdOptions) => {
1
+ const strongJa = (state, silent, md) => {
4
2
 
5
3
  let content, token
6
4
  let found = false
@@ -33,14 +31,13 @@ const strongJa = (state, silent, mdOptions) => {
33
31
 
34
32
 
35
33
  content = state.src.slice(start + 2, end - 1)
36
-
37
34
  //console.log('content: ' + content)
38
35
 
39
36
  token = state.push('strong_open', 'strong', 1)
40
37
  token.markup = '**'
41
38
 
42
- const md = new mdit({html: mdOptions.html})
43
- const childTokens = md.parseInline(content)
39
+ //**An error will occur if there are [] inside the brackets. I needed an argument for state.env.
40
+ const childTokens = md.parseInline(content, state.env)
44
41
 
45
42
  if (childTokens[0] && childTokens[0].children) {
46
43
  childTokens[0].children.forEach(t => {
@@ -62,6 +59,8 @@ const strongJa = (state, silent, mdOptions) => {
62
59
  token.markup = '**'
63
60
 
64
61
  state.pos = end + 1
62
+ // When there is `** at the end of a paragraph(state.pos === max), if state.pos = end + 1 remains, the output is `</strong>undefined</p>`.
63
+ //For now, I created md.core.ruler.push('remove_strong_ja_sp_chars') and it worked.
65
64
  if (state.pos === max) {
66
65
  state.pos = end
67
66
  token = state.push('text', '', 0)
@@ -76,8 +75,7 @@ const strongJa = (state, silent, mdOptions) => {
76
75
 
77
76
  const mdStrongJa = (md) => {
78
77
  md.inline.ruler.before('emphasis', 'strong_ja', (state, silent) => {
79
- strongJa(state, silent, md.options)
80
-
78
+ strongJa(state, silent, md)
81
79
  })
82
80
 
83
81
  md.core.ruler.push('remove_strong_ja_sp_chars', (state) => {
@@ -89,14 +87,19 @@ const mdStrongJa = (md) => {
89
87
  continue
90
88
  }
91
89
  //console.log(state.tokens[i].children)
92
- if(state.tokens[i].children[state.tokens[i].children.length - 1].content === '★mdStrongJa★*') {
93
- //console.log(state.tokens[i].children[state.tokens[i].children.length - 1])
94
- state.tokens[i].children.pop()
95
-
90
+ if (state.tokens[i].children) {
91
+ if(state.tokens[i].children[state.tokens[i].children.length - 1]) {
92
+ if (state.tokens[i].children[state.tokens[i].children.length - 1].content) {
93
+ if(state.tokens[i].children[state.tokens[i].children.length - 1].content === '★mdStrongJa★*') {
94
+ //console.log(state.tokens[i].children[state.tokens[i].children.length - 1])
95
+ state.tokens[i].children.pop()
96
+ }
97
+ }
98
+ }
96
99
  }
97
100
  i++
98
101
  }
99
102
  })
100
103
  }
101
104
 
102
- export default mdStrongJa
105
+ export default mdStrongJa
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) processing. It also processes strings that cannot be converted by the standard.",
4
- "version": "0.1.2",
4
+ "version": "0.1.4",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
@@ -10,7 +10,7 @@
10
10
  "repository": "https://github.com/peaceroad/p7d-markdown-it-strong-ja.git",
11
11
  "author": "peaceroad <peaceroad@gmail.com>",
12
12
  "license": "MIT",
13
- "dependencies": {
13
+ "devDependencies": {
14
14
  "markdown-it": "^14.1.0"
15
15
  }
16
16
  }
@@ -137,3 +137,36 @@ HTMLは**「HyperText <b>Markup</b> Language」**
137
137
  [HTML:true]
138
138
  <p>HTMLは<strong>「HyperText <b>Markup</b> Language」</strong></p>
139
139
  <p>HTMLは<strong>「HyperText <b>Markup</b> Language」</strong></p>
140
+
141
+ [Markdown]
142
+ HTMLは**「Hyper[Text] Markup Language」**
143
+ [HTML]
144
+ <p>HTMLは<strong>「Hyper[Text] Markup Language」</strong></p>
145
+
146
+ [Markdown]
147
+ HTMLは**「Hyper[Text] <b>Markup</b> Language」**
148
+ [HTML:false]
149
+ <p>HTMLは<strong>「Hyper[Text] &lt;b&gt;Markup&lt;/b&gt; Language」</strong></p>
150
+ [HTML:true]
151
+ <p>HTMLは<strong>「Hyper[Text] <b>Markup</b> Language」</strong></p>
152
+
153
+
154
+ [Markdown]
155
+ HTMLは**「Hyper[Text] Markup Language」**
156
+ [HTML]
157
+ <p>HTMLは<strong>「Hyper[Text] Markup Language」</strong></p>
158
+
159
+ [Markdown]
160
+ HTMLは**「Hyper[Text] <b>Markup</b> Language」**
161
+ [HTML:false]
162
+ <p>HTMLは<strong>「Hyper[Text] &lt;b&gt;Markup&lt;/b&gt; Language」</strong></p>
163
+ [HTML:true]
164
+ <p>HTMLは<strong>「Hyper[Text] <b>Markup</b> Language」</strong></p>
165
+
166
+
167
+ [Markdown]
168
+ - HTMLは**「Hyper[Text] Markup Language」**
169
+ [HTML]
170
+ <ul>
171
+ <li>HTMLは<strong>「Hyper[Text] Markup Language」</strong></li>
172
+ </ul>
package/test/test.js CHANGED
@@ -4,13 +4,13 @@ import path from 'path'
4
4
  import url from 'url'
5
5
 
6
6
  import mdit from 'markdown-it'
7
- import mdStrongJa from '../index.js'
7
+ import mditStrongJa from '../index.js'
8
8
 
9
9
  const __dirname = path.dirname(url.fileURLToPath(import.meta.url)).replace(/\\/g, '/')
10
10
 
11
11
  const check = (ms, example) => {
12
- const md = mdit().use(mdStrongJa)
13
- const mdWithHtml = mdit({html: true}).use(mdStrongJa)
12
+ const md = mdit().use(mditStrongJa)
13
+ const mdWithHtml = mdit({html: true}).use(mditStrongJa)
14
14
  let n = 1
15
15
  while (n < ms.length) {
16
16
  //if (n !== 13) { n++; continue }