@peaceroad/markdown-it-strong-ja 0.1.0 → 0.1.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/README.md CHANGED
@@ -9,7 +9,7 @@ import mdit from 'markdown-it'
9
9
  import mdStrongJa from '@peaceroad/markdown-it-strong-ja'
10
10
  const md = mdit().use(mdStrongJa)
11
11
 
12
- md.renderer('HTMLは**「HyperText Markup Language」**の略です。')
12
+ md.render('HTMLは**「HyperText Markup Language」**の略です。')
13
13
  // <p>HTMLは<strong>「HyperText Markup Language」</strong>の略です。</p>
14
14
  ```
15
15
 
@@ -98,4 +98,49 @@ HTMLは`**`は**「HyperText Markup Language」**の略です。
98
98
  [HTML:true]
99
99
  <pre><code>HTMLは`**`は**「HyperText Markup Language」**の略です。
100
100
  </code></pre>
101
+
102
+
103
+ [Markdown]
104
+ HTMLは**「HyperText <b>Markup</b> Language」**
105
+ [HTML:false]
106
+ <p>HTMLは<strong>「HyperText &lt;b&gt;Markup&lt;/b&gt; Language」</strong></p>
107
+ [HTML:true]
108
+ <p>HTMLは<strong>「HyperText <b>Markup</b> Language」</strong></p>
109
+
110
+
111
+ [Markdown]
112
+ HTMLは「**HyperText Markup Language**」
113
+ [HTML]
114
+ <p>HTMLは「<strong>HyperText Markup Language</strong>」</p>
115
+
116
+ [Markdown]
117
+ HTMLは**「HyperText Markup Language」**。
118
+ [HTML]
119
+ <p>HTMLは<strong>「HyperText Markup Language」</strong>。</p>
120
+
121
+ [Markdown]
122
+ HTMLは**「HyperText Markup Language」**
123
+ [HTML]
124
+ <p>HTMLは<strong>「HyperText Markup Language」</strong></p>
125
+
126
+
127
+ [Markdown]
128
+ HTMLは**「HyperText Markup Language」**。
129
+ [HTML]
130
+ <p>HTMLは<strong>「HyperText Markup Language」</strong>。</p>
131
+
132
+ [Markdown]
133
+ ****
134
+ [HTML]
135
+ <hr>
136
+
137
+ [Markdown]
138
+ a****b
139
+ [HTML]
140
+ <p>a<strong></strong>b</p>
141
+
142
+ [Markdown]
143
+ a****
144
+ [HTML]
145
+ <p>a<strong></strong></p>
101
146
  ~~~
package/index.js CHANGED
@@ -1,76 +1,101 @@
1
1
  import mdit from 'markdown-it'
2
2
 
3
3
  const strongJa = (state, silent, mdOptions) => {
4
- let found, content,token
4
+
5
+ let content, token
6
+ let found = false
5
7
  const max = state.posMax
6
8
  const start = state.pos
7
9
 
8
- if (state.src.charCodeAt(start) !== 0x2A || state.src.charCodeAt(start + 1) !== 0x2A) return false
10
+ // console.log('input:: state.src.length: ' + state.src.length + ', state.posMax: ' + state.posMax + ', state.pos: ' + state.pos + ', start: ' + start)
11
+
9
12
  if (silent) return false
10
- if (start + 3 >= max) return false
11
- state.pos = start + 2
13
+ if (start + 3 > max) return false
14
+ if (state.src.charCodeAt(start) !== 0x2A || state.src.charCodeAt(start + 1) !== 0x2A) return false
12
15
 
13
- while (state.pos < max) {
14
- if (state.src.charCodeAt(state.pos) === 0x2A && state.src.charCodeAt(state.pos - 1) === 0x2A) {
16
+
17
+ let end = start + 2
18
+ while (end < max) {
19
+ if (state.src.charCodeAt(end) === 0x2A && state.src.charCodeAt(end +1) === 0x2A) {
15
20
  found = true
21
+ end++
16
22
  break
17
23
  }
18
- state.md.inline.skipToken(state);
24
+ //state.md.inline.skipToken(state);
25
+ end++
19
26
  }
20
- //console.log('found: ' + found)
27
+ //console.log('found: ' + found + ', start: ' + start + ', end: '+ end)
21
28
 
22
- if (!found || start + 2 === state.pos) {
29
+ if (!found) {
23
30
  state.pos = start
24
31
  return false
25
32
  }
26
33
 
27
- content = state.src.slice(start + 2, state.pos - 1)
28
-
29
- if(!mdOptions.html) {
30
- content = content.replace(/</g, '&lt;').replace(/>/g, '&gt;')
31
- }
32
34
 
35
+ content = state.src.slice(start + 2, end - 1)
33
36
 
34
- state.posMax = state.pos
35
- state.pos = start + 2
36
- //console.log('state.posMax: ' + state.posMax + ', state.pos: ' + state.pos)
37
+ //console.log('content: ' + content)
37
38
 
38
39
  token = state.push('strong_open', 'strong', 1)
39
40
  token.markup = '**'
40
41
 
41
-
42
- const md = new mdit({html: true})
42
+ const md = new mdit({html: mdOptions.html})
43
43
  const childTokens = md.parseInline(content)
44
44
 
45
- token = childTokens[0].children.map(t => {
46
- const aToken = state.push(t.type, t.tag, t.nesting)
47
- aToken.attrs = t.attrs
48
- aToken.map = t.map
49
- aToken.level = t.level
50
- aToken.children = t.children
51
- aToken.content = t.content
52
- aToken.markup = t.markup
53
- aToken.info = t.info
54
- aToken.meta = t.meta
55
- aToken.block = t.block
56
- aToken.hidden = t.hidden
57
- return aToken
58
- })
59
-
60
- // console.log(token)
45
+ if (childTokens[0] && childTokens[0].children) {
46
+ childTokens[0].children.forEach(t => {
47
+ token = state.push(t.type, t.tag, t.nesting)
48
+ token.attrs = t.attrs
49
+ token.map = t.map
50
+ token.level = t.level
51
+ token.children = t.children
52
+ token.content = t.content
53
+ token.markup = t.markup
54
+ token.info = t.info
55
+ token.meta = t.meta
56
+ token.block = t.block
57
+ token.hidden = t.hidden
58
+ })
59
+ }
61
60
 
62
61
  token = state.push('strong_close', 'strong', -1)
63
62
  token.markup = '**'
64
63
 
65
- state.pos = state.posMax + 1
66
- state.posMax = max
64
+ state.pos = end + 1
65
+ if (state.pos === max) {
66
+ state.pos = end
67
+ token = state.push('text', '', 0)
68
+ token.content = '★mdStrongJa★'
69
+ return true
70
+ }
71
+
72
+ //console.log('output:: state.src.length: ' + state.src.length + ', state.posMax: ' + state.posMax + ', state.pos: ' + state.pos)
67
73
 
68
- return
74
+ return false
69
75
  }
70
76
 
71
77
  const mdStrongJa = (md) => {
72
78
  md.inline.ruler.before('emphasis', 'strong_ja', (state, silent) => {
73
79
  strongJa(state, silent, md.options)
80
+
81
+ })
82
+
83
+ md.core.ruler.push('remove_strong_ja_sp_chars', (state) => {
84
+ let i = 0
85
+ while (i < state.tokens.length) {
86
+ //console.log(state.tokens[i].type)
87
+ if (state.tokens[i].type !== 'inline') {
88
+ i++
89
+ continue
90
+ }
91
+ //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
+
96
+ }
97
+ i++
98
+ }
74
99
  })
75
100
  }
76
101
 
package/package.json CHANGED
@@ -1,12 +1,13 @@
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.0",
4
+ "version": "0.1.2",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "test": "node test/test.js"
9
9
  },
10
+ "repository": "https://github.com/peaceroad/p7d-markdown-it-strong-ja.git",
10
11
  "author": "peaceroad <peaceroad@gmail.com>",
11
12
  "license": "MIT",
12
13
  "dependencies": {
@@ -81,3 +81,59 @@ HTMLは`**`は**「HyperText Markup Language」**の略です。
81
81
  <pre><code>HTMLは`**`は**「HyperText Markup Language」**の略です。
82
82
  </code></pre>
83
83
 
84
+
85
+ [Markdown]
86
+ HTMLは**「HyperText <b>Markup</b> Language」**
87
+ [HTML:false]
88
+ <p>HTMLは<strong>「HyperText &lt;b&gt;Markup&lt;/b&gt; Language」</strong></p>
89
+ [HTML:true]
90
+ <p>HTMLは<strong>「HyperText <b>Markup</b> Language」</strong></p>
91
+
92
+
93
+ [Markdown]
94
+ HTMLは「**HyperText Markup Language**」
95
+ [HTML]
96
+ <p>HTMLは「<strong>HyperText Markup Language</strong>」</p>
97
+
98
+ [Markdown]
99
+ HTMLは**「HyperText Markup Language」**。
100
+ [HTML]
101
+ <p>HTMLは<strong>「HyperText Markup Language」</strong>。</p>
102
+
103
+ [Markdown]
104
+ HTMLは**「HyperText Markup Language」**
105
+ [HTML]
106
+ <p>HTMLは<strong>「HyperText Markup Language」</strong></p>
107
+
108
+
109
+ [Markdown]
110
+ HTMLは**「HyperText Markup Language」**。
111
+ [HTML]
112
+ <p>HTMLは<strong>「HyperText Markup Language」</strong>。</p>
113
+
114
+ [Markdown]
115
+ ****
116
+ [HTML]
117
+ <hr>
118
+
119
+ [Markdown]
120
+ a****b
121
+ [HTML]
122
+ <p>a<strong></strong>b</p>
123
+
124
+ [Markdown]
125
+ a****
126
+ [HTML]
127
+ <p>a<strong></strong></p>
128
+
129
+
130
+ [Markdown]
131
+ HTMLは**「HyperText <b>Markup</b> Language」**
132
+
133
+ HTMLは**「HyperText <b>Markup</b> Language」**
134
+ [HTML:false]
135
+ <p>HTMLは<strong>「HyperText &lt;b&gt;Markup&lt;/b&gt; Language」</strong></p>
136
+ <p>HTMLは<strong>「HyperText &lt;b&gt;Markup&lt;/b&gt; Language」</strong></p>
137
+ [HTML:true]
138
+ <p>HTMLは<strong>「HyperText <b>Markup</b> Language」</strong></p>
139
+ <p>HTMLは<strong>「HyperText <b>Markup</b> Language」</strong></p>
package/test/test.js CHANGED
@@ -13,7 +13,8 @@ const check = (ms, example) => {
13
13
  const mdWithHtml = mdit({html: true}).use(mdStrongJa)
14
14
  let n = 1
15
15
  while (n < ms.length) {
16
- //if (n !== 7) { n++; continue }
16
+ //if (n !== 13) { n++; continue }
17
+ //if (n !== 2) { n++; continue }
17
18
  const m = ms[n].markdown
18
19
 
19
20
  console.log('Test [' + n + ', HTML: false] >>>')