@peaceroad/markdown-it-strong-ja 0.2.0 → 0.3.0

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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "cSpell.ignoreWords": [
3
+ "inlines"
4
+ ]
5
+ }
package/README.md CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  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
4
 
5
- Since em processing was added from 0.2, the package name is strange.
5
+ Notice: this is slightly different from the commonmark processing.
6
6
 
7
7
  ## Use
8
8
 
9
9
  ```js
10
10
  import mdit from 'markdown-it'
11
- import mdStrongJa from '@peaceroad/markdown-it-strong-ja'
12
- const md = mdit().use(mdStrongJa)
11
+ import mditStrongJa from '@peaceroad/markdown-it-strong-ja'
12
+ const md = mdit().use(mditStrongJa)
13
13
 
14
14
  md.render('HTMLは**「HyperText Markup Language」**の略です。')
15
15
  // <p>HTMLは<strong>「HyperText Markup Language」</strong>の略です。</p>
package/index.js CHANGED
@@ -1,115 +1,391 @@
1
- const processInlineTokens = (state, start, end, type, max) => {
2
- let token
3
- const content = type === 'strong' ? state.src.slice(start, end - 1) : state.src.slice(start, end)
4
-
5
- const childTokens = state.md.parseInline(content, state.env)
6
-
7
- token = state.push(`${type}_open`, type, 1)
8
- token.markup = type === 'strong' ? '**' : '*'
9
-
10
- if (childTokens[0] && childTokens[0].children) {
11
- childTokens[0].children.forEach(t => {
12
- token = state.push(t.type, t.tag, t.nesting)
13
- token.attrs = t.attrs
14
- token.map = t.map
15
- token.level = t.level
16
- token.children = t.children
17
- token.content = t.content
18
- token.markup = t.markup
19
- token.info = t.info
20
- token.meta = t.meta
21
- token.block = t.block
22
- token.hidden = t.hidden
23
- })
1
+ const hasSlashFlag = (state, start) => {
2
+ let slashNum = 0
3
+ let i = start - 1
4
+ while(i >= 0) {
5
+ /// if (state.src.charCodeAt(i) === 0x2A) { i--; continue }
6
+ if (state.src.charCodeAt(i) === 0x5C) { slashNum++; i--; continue }
7
+ break
24
8
  }
9
+ return slashNum % 2 === 1 ? true : false
10
+ }
25
11
 
26
- token = state.push(`${type}_close`, type, -1)
27
- token.markup = type === 'strong' ? '**' : '*'
12
+ const setToken = (state, inlines) => {
13
+ let i = 0
14
+ while (i < inlines.length) {
15
+ const type = inlines[i].type
16
+ const tag = type.replace(/(?:_open|_close)$/, '')
28
17
 
29
- state.pos = end + 1
18
+ if (/_open$/.test(type)) {
19
+ const startToken = state.push(type, tag, 1)
20
+ startToken.markup = tag === 'strong' ? '**' : '*'
21
+ }
30
22
 
31
- if (state.pos === max) {
32
- state.pos = end
33
- token = state.push('text', '', 0)
34
- token.content = '★mdStrongJa★'
23
+ if (type === 'text') {
24
+ const content = state.src.slice(inlines[i].s, inlines[i].e + 1)
25
+ if (/^\**$/.test(content)) {
26
+ //console.log('asterisk process::')
27
+ const asteriskToken = state.push(type, '', 0)
28
+ asteriskToken.content = content
29
+ //console.log('asteriskToken: ' + asteriskToken.content)
30
+ i++
31
+ continue
32
+ }
33
+ const childTokens = state.md.parseInline(content, state.env)
34
+ if (childTokens[0] && childTokens[0].children) {
35
+ state.tokens[state.tokens.length - 1].children = childTokens[0].children
36
+ childTokens[0].children.forEach(t => {
37
+ const token = state.push(t.type, t.tag, t.nesting)
38
+ token.attrs = t.attrs
39
+ token.map = t.map
40
+ token.level = t.level
41
+ token.children = t.children
42
+ token.content = t.content
43
+ token.markup = t.markup
44
+ token.info = t.info
45
+ token.meta = t.meta
46
+ token.block = t.block
47
+ token.hidden = t.hidden
48
+ })
49
+ }
50
+ }
51
+
52
+ if (/_close$/.test(type)) {
53
+ const closeToken = state.push(type, tag, -1)
54
+ closeToken.markup = tag === 'strong' ? '**' : '*'
55
+ }
56
+
57
+ i++
35
58
  }
36
59
  }
37
60
 
38
- const strongJa = (state, silent, md) => {
39
- let end, type
40
- const max = state.posMax
41
- const start = state.pos
61
+ const inlinesPush = (inlines, s, e, len, type) => {
62
+ inlines.push({
63
+ s: s,
64
+ sp: s,
65
+ e: e,
66
+ ep: e,
67
+ len: len,
68
+ type: type,
69
+ })
70
+ }
42
71
 
43
- if (silent) return false
44
- if (start + 1 > max) return false
45
- if (state.src.charCodeAt(start) !== 0x2A) return false
72
+ const crateInlines = (state, start, max) => {
73
+ let n = start
74
+ let inlines = []
75
+ let noMark = ''
76
+ let mark = ''
77
+ let beforeIsMark = true
78
+ while (n < max) {
79
+ if (state.src.charCodeAt(n) === 0x2A) {
80
+ if (hasSlashFlag(state, n)) {
81
+ beforeIsMark = false
82
+ noMark += state.src[n]
83
+ if (n === max - 1) {
84
+ inlinesPush(inlines, n - noMark.length + 1, n, noMark.length, 'text')
85
+ }
86
+ n++
87
+ continue
88
+ }
89
+ beforeIsMark = true
90
+ mark += '*'
91
+ if (n !== start && noMark !== '') {
92
+ inlinesPush(inlines, n - noMark.length, n - 1, noMark.length, 'text')
93
+ }
94
+ noMark = ''
95
+ if (n === max - 1) {
96
+ inlinesPush(inlines, n - mark.length + 1, n, mark.length, '')
97
+ }
98
+ } else {
99
+ noMark += state.src[n]
100
+ if (state.src[n-1] === '*' && beforeIsMark) {
101
+ inlinesPush(inlines, n - mark.length, n - 1, mark.length, '')
102
+ mark = ''
103
+ }
104
+ if (n === max - 1) {
105
+ inlinesPush(inlines, n - noMark.length + 1, n, noMark.length, 'text')
106
+ }
107
+ }
108
+ n++
109
+ }
110
+ return inlines
111
+ }
46
112
 
47
- if (state.src.charCodeAt(start + 1) === 0x2A) {
48
- end = start + 2
49
- type = 'strong'
113
+ const marksPush = (marks, nest, s, e, len, outsideLen, type) => {
114
+ //console.log('before marks:')
115
+ //console.log(marks)
116
+ const np = {
117
+ nest: nest,
118
+ s: s,
119
+ e: e,
120
+ len: len,
121
+ oLen: outsideLen,
122
+ type: type,
123
+ }
124
+ //let i = marks.findIndex(o => o.s > s)
125
+ let i = marks.findIndex(o => o.s > s)
126
+ if (i === -1) {
127
+ marks.push(np)
50
128
  } else {
51
- end = start + 1
52
- type = 'em'
129
+ marks.splice(i, 0, np)
53
130
  }
131
+ }
54
132
 
55
- while (end < max) {
56
- if (state.src.charCodeAt(end) === 0x2A) {
57
- if (type === 'strong' && state.src.charCodeAt(end + 1) === 0x2A) {
58
- end += 1
59
- break
60
- } else if (type === 'em' && (state.src.charCodeAt(end - 1) === 0x2A || state.src.charCodeAt(end + 1) === 0x2A)) {
61
- end++
62
- continue
63
- } else if (type === 'em') {
64
- break
133
+ const setStrong = (inlines, marks, n, memo) => {
134
+ let i = n + 2
135
+ let j = 0
136
+ let nest = 0
137
+ while (i < inlines.length) {
138
+ if (inlines[i].len === 0) { i += 2; continue }
139
+ //console.log('n: ' + n + ' [strong]: inlines[n].len: ' + inlines[n].len + ', i: ' + i + ', inlines[i].len: ' + inlines[i].len)
140
+
141
+ nest = checkNest(inlines, marks, n, i)
142
+ //console.log('n: ' + n + ' [strong]: nest: ' + nest)
143
+ if (nest === -1) return n, nest, memo
144
+
145
+ if (inlines[i].len === 1 && inlines[n].len > 2) {
146
+ //console.log('n: ' + n + ' [strong]: check em inside strong: ' + nest)
147
+ marksPush(marks, nest, inlines[n].ep, inlines[n].ep, 1, inlines[n].len - 1, 'em_open')
148
+ marksPush(marks, nest, inlines[i].sp, inlines[i].ep, 1, inlines[i].len - 1, 'em_close')
149
+ inlines[n].len -= 1
150
+ inlines[n].ep -= 1
151
+ inlines[i].len = 0
152
+ inlines[i].sp += 1
153
+ if (i + 2 < inlines.length) {
154
+ i += 2
155
+ nest++
156
+ } else {
157
+ return n, nest, memo
65
158
  }
159
+ //console.log(marks)
160
+ //console.log('n: ' + n + ' [strong]: check em inside strong end.')
66
161
  }
67
- end++
162
+
163
+ let strongNum = Math.trunc(Math.min(inlines[n].len, inlines[i].len) / 2)
164
+ if (inlines[i].len > 1) {
165
+ //console.log('n: ' + n + ' [strong]: normal push, nest: ' + nest)
166
+ j = 0
167
+ while (j < strongNum) {
168
+ //console.log('j: ' + j + ', inlines[i].sp: ' + inlines[i].sp)
169
+ marksPush(marks, nest + strongNum - 1 - j , inlines[n].ep - 1, inlines[n].ep, 2, inlines[n].len - 2,'strong_open')
170
+ inlines[n].ep -= 2
171
+ inlines[n].len -= 2
172
+ marksPush(marks, nest + strongNum - 1 - j, inlines[i].sp, inlines[i].sp + 1, 2, inlines[i].len - 2,'strong_close')
173
+ inlines[i].sp += 2
174
+ inlines[i].len -= 2
175
+ //console.log(marks)
176
+ j++
177
+ }
178
+
179
+ if (inlines[n].len === 0) return n, nest, memo
180
+ }
181
+
182
+ if (inlines[n].len === 1) {
183
+ //console.log('check em that warp strong: ')
184
+ nest++
185
+ n, nest, memo= setEm(inlines, marks, n, memo, nest)
186
+ if (memo.hasEmThatWrapStrong) {
187
+ //console.log('fix strong wrapped em:')
188
+ let k = 0
189
+ while (k < strongNum) {
190
+ marks[marks.length - 2 - k * 2 - 1].nest += 1
191
+ marks[marks.length - 2 - k * 2].nest += 1
192
+ k++
193
+ }
194
+ }
195
+ }
196
+
197
+ if (inlines[n].len === 0) return n, nest, memo
198
+ i += 2
68
199
  }
69
- const noContent = type === 'strong' ? end === start + 3 :end === start + 1
70
- if (end >= max || noContent) {
71
- state.pos = start
72
- return false
200
+ return n, nest, memo
201
+ }
202
+
203
+ const setEm = (inlines, marks, n, memo, sNest) => {
204
+ let i = n + 2
205
+ let nest = 0
206
+ let strongPNum = 0
207
+ while (i < inlines.length) {
208
+ if (inlines[i].len === 0) { i += 2; continue }
209
+ const emNum = Math.min(inlines[n].len, inlines[i].len)
210
+ if (memo.isEm && emNum !== 1) return n, sNest, memo
211
+ //console.log('n: ' + n + ' [em]: inlines[n].len: ' + inlines[n].len + ', i: ' + i, ', inlines[i].len: ' + inlines[i].len + ', isEm: ' + memo.isEm)
212
+ //console.log(marks)
213
+
214
+ if (memo.isEm && inlines[i].len === 2) {
215
+ strongPNum++
216
+ i += 2
217
+ continue
218
+ }
219
+
220
+ if (sNest) {
221
+ nest = sNest - 1
222
+ } else {
223
+ nest = checkNest(inlines, marks, n, i)
224
+ }
225
+ //console.log('n: ' + n + ' [em]: nest: ' + nest)
226
+ if (nest === -1) return n, nest, memo
227
+
228
+ if (emNum === 1) {
229
+ //console.log('n: ' + n + ' [em]: normal push, nest: ' + nest)
230
+ //console.log('strongPNum: ' + strongPNum)
231
+ //console.log(inlines[n].ep, inlines[n].sp, inlines[n].s)
232
+
233
+ marksPush(marks, nest, inlines[n].ep, inlines[n].ep, 1, inlines[n].len - 1, 'em_open')
234
+ inlines[n].ep -= 1
235
+ inlines[n].len -= 1
236
+
237
+ if (strongPNum % 2 === 0 || inlines[i].len < 2) {
238
+ marksPush(marks, nest, inlines[i].sp, inlines[i].sp, 1, inlines[i].len - 1, 'em_close')
239
+ inlines[i].sp += 1
240
+ } else {
241
+ marksPush(marks, nest, inlines[i].ep, inlines[i].ep, 1, inlines[i].len - 1, 'em_close')
242
+ inlines[i].sp = inlines[i].ep - 1
243
+ inlines[i].ep -= 1
244
+
245
+ }
246
+ inlines[i].len -= 1
247
+ //console.log(marks)
248
+ if (!memo.isEm) memo.hasEmThatWrapStrong = true
249
+ if (inlines[n].len === 0) return n, nest, memo
250
+ }
251
+
252
+ i += 2
73
253
  }
74
- //console.log('start: ' + start + ', end: '+ end+ ', state.pos: ' + state.pos)
75
254
 
76
- processInlineTokens(state, start + (type === 'strong' ? 2 : 1), end, type, max)
77
- //console.log('output:: state.src.length: ' + state.src.length + ', state.posMax: ' + state.posMax + ', state.pos: ' + state.pos)
78
- return true
255
+ return n, nest, memo
79
256
  }
80
257
 
81
- const mdStrongJa = (md) => {
82
- md.inline.ruler.before('emphasis', 'strong_ja', (state, silent) => {
83
- strongJa(state, silent, md)
84
- })
85
- /*
86
- md.inline.ruler.before('emphasis', 'em_ja', (state, silent) => {
87
- emJa(state, silent, md)
88
- })*/
258
+ const setText = (inlines, marks, n, nest) => {
259
+ //console.log('n: ' + n + ' [text]: inlines[n].len: ' + inlines[n].len)
260
+ //marksPush(marks, -1, inlines[n].sp + 1, inlines[n].ep, inlines[n].len, -1, 'text')
261
+ marksPush(marks, nest, inlines[n].sp, inlines[n].ep, inlines[n].len, -1, 'text')
262
+ //inlines[n].sp += 1
263
+ inlines[n].len = 0
264
+ }
265
+
266
+ const checkNest = (inlines, marks, n, i) => {
267
+ let nest = 1
268
+ let isRange = true
269
+ if (marks.length === 0) return nest
270
+ let strongNest = 0
271
+ let emNest = 0
272
+ let j = 0
273
+ //console.log(marks)
274
+ //console.log('n: ' + n + ', i: ' + i + ', inlines[n].s: ' + inlines[n].s + ', inlines[i].s: ' + inlines[i].s)
275
+ while (j < marks.length) {
276
+ if (marks[j].s <= inlines[n].s) {
277
+ if (marks[j].type === 'strong_open') strongNest++
278
+ if (marks[j].type === 'strong_close') strongNest--
279
+ if (marks[j].type === 'em_open') emNest++
280
+ if (marks[j].type === 'em_close') emNest--
281
+ } else { break }
282
+ j++
283
+ }
284
+ let parentNest = strongNest + emNest
285
+ let parentCloseN = j
286
+ //console.log('strongNest: ' + strongNest + ', emNest: ' + emNest + ', parentNest: ' + parentNest + ', parentCloseN: ' + parentCloseN)
287
+ if (parentCloseN < marks.length) {
288
+ while (parentCloseN < marks.length) {
289
+ if (marks[parentCloseN].nest === parentNest) break
290
+ parentCloseN++
291
+ }
292
+ //console.log(parentCloseN, marks[parentCloseN].s, i, inlines[i].s)
293
+ if (marks[parentCloseN].s < inlines[i].s) isRange = false
294
+ }
295
+ //console.log('isRange: ' + isRange)
296
+
297
+ if (isRange) {
298
+ nest = parentNest + 1
299
+ } else {
300
+ nest = -1
301
+ }
302
+ return nest
303
+ }
89
304
 
305
+ const createMarks = (inlines, inlinesStart, inlinesEnd, memo) => {
306
+ let marks = []
307
+ let n = inlinesStart
308
+ while (n < inlinesEnd) {
309
+ if (inlines[n].type !== '') { n += 2; continue }
310
+ if (inlines[n].len === 0) { n += 2; continue }
311
+ memo.isEm = inlines[n].len === 1 ? true : false
312
+ memo.wrapEm = 0
313
+ let nest = 0
314
+ //console.log('n: ' + n + ' ----- inlines.length: ' + inlines.length + ', memo.isEm: ' + memo.isEm)
315
+ if (!memo.isEm) {
316
+ n, nest, memo = setStrong(inlines, marks, n, memo)
317
+ }
318
+ n, nest, memo = setEm(inlines, marks, n, memo)
319
+
320
+ if (inlines[n].len !== 0) setText(inlines, marks, n, nest)
321
+ n += 2
322
+ }
323
+ return marks
324
+ }
90
325
 
91
- md.core.ruler.push('remove_strong_ja_sp_chars', (state) => {
326
+ const strongJa = (state, silent) => {
327
+ const max = state.posMax
328
+ const start = state.pos
329
+ if (silent) return false
330
+ if (start > max) return false
331
+ if (state.src.charCodeAt(start) !== 0x2A) return false
332
+ if (hasSlashFlag(state, start)) return false
333
+ //console.log('state.src.length: ' + state.src.length + ', start: ' + start + ', state.src: ' + state.src)
334
+ let inlines = crateInlines(state, start, max)
335
+ //console.log('inlines: ')
336
+ //console.log(inlines)
337
+
338
+ const memo = {
339
+ isEm: false,
340
+ hasEmThatWrapStrong: false,
341
+ noSetStrongEnd: false,
342
+ inlineMarkStart: state.src.charCodeAt(0) === 0x2A ? true : false,
343
+ inlineMarkEnd: state.src.charCodeAt(max - 1) === 0x2A ? true : false,
344
+ }
345
+ let marks = createMarks(inlines, 0, inlines.length, memo)
346
+ //console.log('marks: ')
347
+ //console.log(marks)
348
+
349
+ let n = 0
350
+ while (n < inlines.length) {
351
+ if (inlines[n].type !== '') { n++; continue }
92
352
  let i = 0
93
- while (i < state.tokens.length) {
94
- //console.log(state.tokens[i].type)
95
- if (state.tokens[i].type !== 'inline') {
353
+ //console.log('n: ' + n + ', inlines[n].s: ' + inlines[n].s + ', inlines[n].e: ' + inlines[n].e)
354
+ let c = 0
355
+ while (i < marks.length) {
356
+ //console.log(marks[i].s, inlines[n].e, marks[i].e, inlines[n].e)
357
+ //console.log(marks[i].s >= inlines[n].s , marks[i].e <= inlines[n].e)
358
+ if (marks[i].s >= inlines[n].s && marks[i].e <= inlines[n].e) {
359
+ //console.log('n: ' + n + ', i: ' + i + ', marks[i].type: ' + marks[i].type)
360
+ inlines.splice(n + i + 1, 0, marks[i])
361
+ c++
96
362
  i++
97
363
  continue
98
364
  }
99
- //console.log(state.tokens[i].children)
100
- if (state.tokens[i].children) {
101
- if(state.tokens[i].children[state.tokens[i].children.length - 1]) {
102
- if (state.tokens[i].children[state.tokens[i].children.length - 1].content) {
103
- if(state.tokens[i].children[state.tokens[i].children.length - 1].content === '★mdStrongJa★*') {
104
- //console.log(state.tokens[i].children[state.tokens[i].children.length - 1])
105
- state.tokens[i].children.pop()
106
- }
107
- }
108
- }
109
- }
110
- i++
365
+ break
111
366
  }
112
- })
367
+ if (marks.length) {
368
+ marks.splice(0, c)
369
+ inlines.splice(n, 1)
370
+ n += c
371
+ } else {
372
+ inlines[n].type = 'text'
373
+ n++
374
+ }
375
+ }
376
+
377
+ //console.log('fix inlines:')
378
+ //console.log(inlines)
379
+ setToken(state, inlines)
380
+
381
+ //console.log('state.pos: ' + state.pos + ', inlines[inlines.length - 1].e + 1: ' + (inlines[inlines.length - 1].e + 1) + ', max: ' + max)
382
+ state.pos = inlines[inlines.length - 1].e + 1
383
+ return true
113
384
  }
114
385
 
115
- export default mdStrongJa
386
+ const mditStrongJa = (md) => {
387
+ md.inline.ruler.before('emphasis', 'strong_ja', (state, silent) => {
388
+ return strongJa(state, silent)
389
+ })
390
+ }
391
+ export default mditStrongJa
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.2.0",
4
+ "version": "0.3.0",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
@@ -0,0 +1,141 @@
1
+ [Markdown]
2
+ HTMLは「***HyperText Markup Language***」の略です。
3
+ [HTML]
4
+ <p>HTMLは「<em><strong>HyperText Markup Language</strong></em>」の略です。</p>
5
+
6
+
7
+ [Markdown]
8
+ HTMLは***「HyperText Markup Language」***の略です。
9
+ [HTML]
10
+ <p>HTMLは<em><strong>「HyperText Markup Language」</strong></em>の略です。</p>
11
+
12
+
13
+ [Markdown]
14
+ HTMLは「****HyperText Markup Language****」の略です。
15
+ [HTML]
16
+ <p>HTMLは「<strong><strong>HyperText Markup Language</strong></strong>」の略です。</p>
17
+
18
+
19
+ [Markdown]
20
+ HTMLは****「HyperText Markup Language」****の略です。
21
+ [HTML]
22
+ <p>HTMLは<strong><strong>「HyperText Markup Language」</strong></strong>の略です。</p>
23
+
24
+
25
+ [Markdown]
26
+ HTMLは**「*HyperText* Markup *Language*」**の略です。
27
+ [HTML]
28
+ <p>HTMLは<strong>「<em>HyperText</em> Markup <em>Language</em>」</strong>の略です。</p>
29
+
30
+
31
+
32
+ [Markdown]
33
+ あ*い**う
34
+ [HTML]
35
+ <p>あ*い**う</p>
36
+
37
+
38
+ [Markdown]
39
+ あ**い***う
40
+ [HTML]
41
+ <p>あ<strong>い</strong>*う</p>
42
+
43
+ [Markdown]
44
+ あ***い****う
45
+ [HTML]
46
+ <p>あ<em><strong>い</strong></em>*う</p>
47
+
48
+ [Markdown]
49
+ **あ*い**う*
50
+ [HTML]
51
+ <p><strong>あ*い</strong>う*</p>
52
+
53
+ [Markdown]
54
+ *あ**い*う**
55
+ [HTML]
56
+ <p><em>あ**い</em>う**</p>
57
+
58
+
59
+ [Markdown]
60
+ ん*あ**い*う**
61
+ [HTML]
62
+ <p>ん<em>あ**い</em>う**</p>
63
+
64
+
65
+ [Markdown]
66
+ ***か*
67
+ [HTML]
68
+ <p>**<em>か</em></p>
69
+
70
+ [Markdown]
71
+ か***き*
72
+ [HTML]
73
+ <p>か**<em>き</em></p>
74
+
75
+
76
+
77
+ [Markdown]
78
+ ***さ*し***す*
79
+ [HTML]
80
+ <p><strong><em>さ</em>し</strong><em>す</em></p>
81
+
82
+
83
+ [Markdown]
84
+ *a**b**c**d**e*
85
+ [HTML]
86
+ <p><em>a<strong>b</strong>c<strong>d</strong>e</em></p>
87
+
88
+
89
+ [Markdown]
90
+ *aa**
91
+ [HTML commomark: <p><em>aa</em>*</p>]
92
+ <p>*aa**</p>
93
+
94
+ [Markdown]
95
+ a*aa**
96
+ [HTML]
97
+ <p>a*aa**</p>
98
+
99
+ [Markdown]
100
+ *ee***
101
+ [HTML]
102
+ <p><em>ee</em>**</p>
103
+
104
+
105
+ [Markdown]
106
+ *aa***e*
107
+ [HTML]
108
+ <p><em>aa</em>*<em>e</em></p>
109
+
110
+
111
+ [Markdown]
112
+ **a*****b**
113
+ [HTML]
114
+ <p><strong>a</strong>*<strong>b</strong></p>
115
+
116
+
117
+ [Markdown]
118
+ *ee**ee***
119
+ [HTML]
120
+ <p><em>ee<strong>ee</strong></em></p>
121
+
122
+
123
+ [Markdown]
124
+ **a*b**c***d*e**f*
125
+ [HTML]
126
+ <p><strong>a*b</strong>c<strong><em>d</em>e</strong>f*</p>
127
+
128
+ [Markdown]
129
+ *a**a***b***c**d*e
130
+ [HTML]
131
+ <p><em>a<strong>a</strong></em>b<em><strong>c</strong>d</em>e</p>
132
+
133
+ [Markdown]
134
+ a[*](https://example.com)*b
135
+ [HTML]
136
+ <p>a<a href="https://example.com">*</a>*b</p>
137
+
138
+ [Markdown]
139
+ a[*](https://example*.com)*b*
140
+ [HTML]
141
+ <p>a<a href="https://example*.com">*</a><em>b</em></p>
@@ -174,3 +174,32 @@ HTMLは*「Hyper[Text] <b>Markup</b> Language」*
174
174
  <ul>
175
175
  <li>HTMLは<em>「Hyper[Text] Markup Language」</em></li>
176
176
  </ul>
177
+
178
+ [Markdown]
179
+ HTMLは*「Hyper[Text](https://example.com/) Markup Language」*
180
+ [HTML]
181
+ <p>HTMLは<em>「Hyper<a href="https://example.com/">Text</a> Markup Language」</em></p>
182
+
183
+ [Markdown]
184
+ HTMLは[*HyperText Markup Language*](https://example.com/)
185
+ [HTML]
186
+ <p>HTMLは<a href="https://example.com/"><em>HyperText Markup Language</em></a></p>
187
+
188
+ [Markdown]
189
+ HTMLは[*「HyperText Markup Language」*](https://example.com/)
190
+ [HTML]
191
+ <p>HTMLは<a href="https://example.com/"><em>「HyperText Markup Language」</em></a></p>
192
+
193
+ [Markdown]
194
+ HTMLは[*「HyperText Markup Language」*][]です。
195
+
196
+ [*「HyperText Markup Language」*]: https://example.com/
197
+ [HTML]
198
+ <p>HTMLは<a href="https://example.com/"><em>「HyperText Markup Language」</em></a>です。</p>
199
+
200
+ [Markdown]
201
+ - HTMLは*「Hyper[Text](https://example.com/) Markup Language」*
202
+ [HTML]
203
+ <ul>
204
+ <li>HTMLは<em>「Hyper<a href="https://example.com/">Text</a> Markup Language」</em></li>
205
+ </ul>
@@ -48,6 +48,11 @@ HTMLは\\\**「HyperText Markup Language」**の略です。
48
48
  [HTML]
49
49
  <p>HTMLは\**「HyperText Markup Language」**の略です。</p>
50
50
 
51
+ [Markdown]
52
+ HTMLは\\\\**「HyperText Markup Language」**の略です。
53
+ [HTML]
54
+ <p>HTMLは\\<strong>「HyperText Markup Language」</strong>の略です。</p>
55
+
51
56
 
52
57
  [Markdown]
53
58
  HTMLは`**`は**「HyperText Markup Language」**の略です。
@@ -170,3 +175,46 @@ HTMLは**「Hyper[Text] <b>Markup</b> Language」**
170
175
  <ul>
171
176
  <li>HTMLは<strong>「Hyper[Text] Markup Language」</strong></li>
172
177
  </ul>
178
+
179
+
180
+ [Markdown]
181
+ HTMLは**「Hyper[Text](https://example.com/) Markup Language」**
182
+ [HTML]
183
+ <p>HTMLは<strong>「Hyper<a href="https://example.com/">Text</a> Markup Language」</strong></p>
184
+
185
+ [Markdown]
186
+ HTMLは[**HyperText Markup Language**](https://example.com/)
187
+ [HTML]
188
+ <p>HTMLは<a href="https://example.com/"><strong>HyperText Markup Language</strong></a></p>
189
+
190
+ [Markdown]
191
+ HTMLは[**「HyperText Markup Language」**](https://example.com/)
192
+ [HTML]
193
+ <p>HTMLは<a href="https://example.com/"><strong>「HyperText Markup Language」</strong></a></p>
194
+
195
+ [Markdown]
196
+ HTMLは[**「HyperText Markup Language」**][]です。
197
+
198
+ [**「HyperText Markup Language」**]: https://example.com/
199
+ [HTML]
200
+ <p>HTMLは<a href="https://example.com/"><strong>「HyperText Markup Language」</strong></a>です。</p>
201
+
202
+ [Markdown]
203
+ - HTMLは**「Hyper[Text](https://example.com/) Markup Language」**
204
+ [HTML]
205
+ <ul>
206
+ <li>HTMLは<strong>「Hyper<a href="https://example.com/">Text</a> Markup Language」</strong></li>
207
+ </ul>
208
+
209
+ [Markdown]
210
+ aaa><aaa
211
+ [HTML]
212
+ <p>aaa&gt;&lt;aaa</p>
213
+
214
+
215
+ [Markdown]
216
+ aaa&lt;/&gt;aaa
217
+ [HTML]
218
+ <p>aaa&lt;/&gt;aaa</p>
219
+
220
+
package/test/test.js CHANGED
@@ -13,10 +13,8 @@ const check = (ms, example) => {
13
13
  const mdWithHtml = mdit({html: true}).use(mditStrongJa)
14
14
  let n = 1
15
15
  while (n < ms.length) {
16
- //if (n !== 13) { n++; continue }
17
- //if (n !== 2) { n++; continue }
16
+ //if (n != 1 ) { n++; continue }
18
17
  const m = ms[n].markdown
19
-
20
18
  console.log('Test [' + n + ', HTML: false] >>>')
21
19
  const h = md.render(m)
22
20
  try {
@@ -34,7 +32,6 @@ const check = (ms, example) => {
34
32
  console.log('Input: ' + ms[n].markdown + '\nConvert: ' + hh + 'Correct: ' + ms[n].htmlWithHtmlTrue)
35
33
  }
36
34
  }
37
-
38
35
  n++
39
36
  }
40
37
  }
@@ -42,12 +39,13 @@ const check = (ms, example) => {
42
39
  const examples = {
43
40
  strong: __dirname + '/example-strong.txt',
44
41
  em: __dirname + '/example-em.txt',
42
+ complex: __dirname + '/example-complex.txt',
45
43
  }
46
44
 
47
45
  for (let example in examples) {
48
46
  const exampleCont = fs.readFileSync(examples[example], 'utf-8').trim()
49
47
  let ms = [];
50
- let ms0 = exampleCont.split(/\n*\[Markdown\]\n/)
48
+ let ms0 = exampleCont.split(/\n*\[Markdown[^\]]*?\]\n/)
51
49
  let n = 1
52
50
  while (n < ms0.length) {
53
51
  let mhs = ms0[n].split(/\n+\[HTML[^\]]*?\]\n/)