@peaceroad/markdown-it-strong-ja 0.3.6 → 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/README.md CHANGED
@@ -153,32 +153,3 @@ a****
153
153
  [HTML]
154
154
  <p>a****</p>
155
155
  ~~~
156
-
157
- ---
158
-
159
- Warning. Commonmark converts it as follows, but the current plugin cannot convert it. (It converts it based on the first *. I don't think it's that bad in terms of appearance...)
160
-
161
- ~~~
162
- [Markdown]
163
- z*<>*a*b
164
- [HTML:false]
165
- <p>z*&lt;&gt;<em>a</em>b</p>
166
- [HTML:true]
167
- <p>z*&lt;&gt;<em>a</em>b</p>
168
-
169
- [Markdown]
170
- z*<span>*a*b
171
- [HTML:false]
172
- <p>z*&lt;span&gt;<em>a</em>b</p>
173
- [HTML:true]
174
- <p>z*<span><em>a</em>b</p>
175
-
176
- [Markdown]
177
- z*<span>*a*b</span>
178
- [HTML:false]
179
- <p>z*&lt;span&gt;<em>a</em>b&lt;/span&gt;</p>
180
- [HTML:true]
181
- <p>z*<span><em>a</em>b</span></p>
182
- ~~~
183
-
184
- ---
package/index.js CHANGED
@@ -1,14 +1,21 @@
1
+ const REG_ASTERISKS = /^\*+$/
2
+ const REG_ATTRS = /{[^{}\n!@#%^&*()]+?}$/
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
5
+
1
6
  const hasBackslash = (state, start) => {
2
7
  let slashNum = 0
3
8
  let i = start - 1
9
+ const src = state.src
4
10
  while(i >= 0) {
5
- if (state.src.charCodeAt(i) === 0x5C) { slashNum++; i--; continue }
11
+ if (src.charCodeAt(i) === 0x5C) { slashNum++; i--; continue }
6
12
  break
7
13
  }
8
- return slashNum % 2 === 1 ? true : false
14
+ return slashNum % 2 === 1
9
15
  }
10
16
 
11
17
  const setToken = (state, inlines, opt) => {
18
+ const src = state.src
12
19
  let i = 0
13
20
  let attrsIsText = {
14
21
  val: false,
@@ -32,9 +39,9 @@ const setToken = (state, inlines, opt) => {
32
39
  type = 'text'
33
40
  }
34
41
  if (type === 'text') {
35
- let content = state.src.slice(inlines[i].s, inlines[i].e + 1)
42
+ let content = src.slice(inlines[i].s, inlines[i].e + 1)
36
43
  //console.log('content: ' + content)
37
- if (/^\*+$/.test(content)) {
44
+ if (REG_ASTERISKS.test(content)) {
38
45
  //console.log('asterisk process::')
39
46
  const asteriskToken = state.push(type, '', 0)
40
47
  asteriskToken.content = content
@@ -44,7 +51,7 @@ const setToken = (state, inlines, opt) => {
44
51
  if (opt.mditAttrs && attrsIsText.val && i + 1 < inlines.length) {
45
52
  const hasImmediatelyAfterAsteriskClose = inlines[i+1].type === attrsIsText.tag + '_close'
46
53
  //console.log(hasImmediatelyAfterAsteriskClose, inlines[i+1].type, /^[\s\S]*{[^{}\n!@#%^&*()]+?}$/.test(content))
47
- if (hasImmediatelyAfterAsteriskClose && /{[^{}\n!@#%^&*()]+?}$/.test(content)) {
54
+ if (hasImmediatelyAfterAsteriskClose && REG_ATTRS.test(content)) {
48
55
  const attrsToken = state.push(type, '', 0)
49
56
 
50
57
  const hasBackslashBeforeCurlyAttribute = content.match(/(\\+){/)
@@ -116,7 +123,7 @@ const setToken = (state, inlines, opt) => {
116
123
  }
117
124
  }
118
125
 
119
- const inlinesPush = (inlines, s, e, len, type, tag, tagType) => {
126
+ const pushInlines = (inlines, s, e, len, type, tag, tagType) => {
120
127
  const inline = {
121
128
  s: s,
122
129
  sp: s,
@@ -124,6 +131,7 @@ const inlinesPush = (inlines, s, e, len, type, tag, tagType) => {
124
131
  ep: e,
125
132
  len: len,
126
133
  type: type,
134
+ check: type === 'text' ? true : false,
127
135
  }
128
136
  if (tag) inline.tag = [tag, tagType]
129
137
  inlines.push(inline)
@@ -131,13 +139,14 @@ const inlinesPush = (inlines, s, e, len, type, tag, tagType) => {
131
139
 
132
140
  const hasNextSymbol = (state, n, max, symbol, noMark) => {
133
141
  let nextSymbolPos = -1
134
- if (state.src.charCodeAt(n) === symbol && !hasBackslash(state, n)) {
142
+ const src = state.src
143
+ if (src.charCodeAt(n) === symbol && !hasBackslash(state, n)) {
135
144
  let i = n + 1
136
145
  let tempNoMark = noMark
137
146
  while (i < max) {
138
- tempNoMark += state.src[i]
139
- if (state.src.charCodeAt(i) === symbol && !hasBackslash(state, i)) {
140
- noMark += state.src.substring(n, i + 1)
147
+ tempNoMark += src[i]
148
+ if (src.charCodeAt(i) === symbol && !hasBackslash(state, i)) {
149
+ noMark += src.substring(n, i + 1)
141
150
  nextSymbolPos = i
142
151
  break
143
152
  }
@@ -148,27 +157,29 @@ const hasNextSymbol = (state, n, max, symbol, noMark) => {
148
157
  }
149
158
 
150
159
  const createInlines = (state, start, max, opt) => {
160
+ const src = state.src
161
+ const srcLen = max;
151
162
  let n = start
152
163
  let inlines = []
153
164
  let noMark = ''
154
165
  let textStart = n
155
- while (n < max) {
166
+ while (n < srcLen) {
156
167
  //console.log('n: ' + n + ', state.src[n]: ' + state.src[n] + ', noMark: ' + noMark)
157
168
  let nextSymbolPos = -1;
158
- [nextSymbolPos, noMark] = hasNextSymbol(state, n, max, 0x60, noMark) // '`'
169
+ [nextSymbolPos, noMark] = hasNextSymbol(state, n, srcLen, 0x60, noMark) // '`'
159
170
  if (nextSymbolPos !== -1) {
160
- if (nextSymbolPos === max - 1) {
161
- inlinesPush(inlines, textStart, nextSymbolPos, nextSymbolPos - textStart + 1, 'text')
171
+ if (nextSymbolPos === srcLen - 1) {
172
+ pushInlines(inlines, textStart, nextSymbolPos, nextSymbolPos - textStart + 1, 'text')
162
173
  break
163
174
  }
164
175
  n = nextSymbolPos + 1
165
176
  continue
166
177
  }
167
178
  if (opt.dollarMath) {
168
- [nextSymbolPos, noMark] = hasNextSymbol(state, n, max, 0x24, noMark) // '$'
179
+ [nextSymbolPos, noMark] = hasNextSymbol(state, n, srcLen, 0x24, noMark) // '$'
169
180
  if (nextSymbolPos !== -1) {
170
- if (nextSymbolPos === max - 1) {
171
- inlinesPush(inlines, textStart, nextSymbolPos, nextSymbolPos - textStart + 1, 'text')
181
+ if (nextSymbolPos === srcLen - 1) {
182
+ pushInlines(inlines, textStart, nextSymbolPos, nextSymbolPos - textStart + 1, 'text')
172
183
  break
173
184
  }
174
185
  n = nextSymbolPos + 1
@@ -177,16 +188,15 @@ const createInlines = (state, start, max, opt) => {
177
188
  }
178
189
 
179
190
  if (state.md.options.html) {
180
- if (state.src.charCodeAt(n) === 0x3C && !hasBackslash(state, n)) { // '<'
191
+ if (src.charCodeAt(n) === 0x3C && !hasBackslash(state, n)) { // '<'
181
192
  let i = n + 1
182
- while (i < max) {
183
- if (state.src.charCodeAt(i) === 0x3E && !hasBackslash(state, i)) { // '>'
193
+ while (i < srcLen) {
194
+ if (src.charCodeAt(i) === 0x3E && !hasBackslash(state, i)) { // '>'
184
195
  if (noMark.length !== 0) {
185
- // Add the text before the tag to inlines
186
- inlinesPush(inlines, textStart, n - 1, n - textStart, 'text')
196
+ pushInlines(inlines, textStart, n - 1, n - textStart, 'text')
187
197
  noMark = ''
188
198
  }
189
- let tag = state.src.slice(n + 1, i)
199
+ let tag = src.slice(n + 1, i)
190
200
  let tagType = ''
191
201
  if (/^\//.test(tag)) {
192
202
  tag = tag.slice(1)
@@ -194,7 +204,7 @@ const createInlines = (state, start, max, opt) => {
194
204
  } else {
195
205
  tagType = 'open'
196
206
  }
197
- inlinesPush(inlines, n, i, i - n + 1, 'html_inline', tag, tagType)
207
+ pushInlines(inlines, n, i, i - n + 1, 'html_inline', tag, tagType)
198
208
  textStart = i + 1
199
209
  break
200
210
  }
@@ -205,32 +215,23 @@ const createInlines = (state, start, max, opt) => {
205
215
  }
206
216
  }
207
217
 
208
- if (state.src.charCodeAt(n) === 0x2A && !hasBackslash(state, n)) { // '*'
209
- /*
210
- if (/[!-)+-/:-@[-`{-~]/.test(state.src[n + 1])) {
211
- inlinesPush(inlines, textStart, n, n - textStart + 1, 'text')
212
- noMark = ''
213
- n++
214
- textStart = n
215
- continue
216
- }*/
217
- if (n !== 0) {
218
- //Add text before asterisk to inlines
219
- inlinesPush(inlines, textStart, n - 1, n - textStart, 'text')
218
+ if (src.charCodeAt(n) === 0x2A && !hasBackslash(state, n)) { // '*'
219
+ if (n !== 0 && noMark.length !== 0) {
220
+ pushInlines(inlines, textStart, n - 1, n - textStart, 'text')
220
221
  noMark = ''
221
222
  }
222
- if (n === max - 1) {
223
- inlinesPush(inlines, n, n, 1 , '')
223
+ if (n === srcLen - 1) {
224
+ pushInlines(inlines, n, n, 1 , '')
224
225
  break
225
226
  }
226
227
  let i = n + 1
227
- while (i < max) {
228
- if (state.src.charCodeAt(i) === 0x2A) {
229
- if (i === max - 1) inlinesPush(inlines, n, i, i - n + 1 , '')
228
+ while (i < srcLen) {
229
+ if (src.charCodeAt(i) === 0x2A) {
230
+ if (i === srcLen - 1) pushInlines(inlines, n, i, i - n + 1 , '')
230
231
  i++
231
232
  continue
232
233
  }
233
- inlinesPush(inlines, n, i - 1, i - n, '')
234
+ pushInlines(inlines, n, i - 1, i - n, '')
234
235
  textStart = i
235
236
  break
236
237
  }
@@ -238,9 +239,9 @@ const createInlines = (state, start, max, opt) => {
238
239
  continue
239
240
  }
240
241
 
241
- noMark += state.src[n]
242
- if (n === max - 1) {
243
- inlinesPush(inlines, textStart, n, n - textStart + 1, 'text')
242
+ noMark += src[n]
243
+ if (n === srcLen - 1) {
244
+ pushInlines(inlines, textStart, n, n - textStart + 1, 'text')
244
245
  break
245
246
  }
246
247
  n++
@@ -248,176 +249,202 @@ const createInlines = (state, start, max, opt) => {
248
249
  return inlines
249
250
  }
250
251
 
251
- const marksPush = (marks, nest, s, e, len, outsideLen, type) => {
252
- //console.log('before marks:')
253
- //console.log(marks)
254
- const np = {
255
- nest: nest,
256
- s: s,
257
- e: e,
258
- len: len,
259
- oLen: outsideLen,
260
- type: type,
261
- }
262
- let i = marks.findIndex(o => o.s > s)
263
- if (i === -1) {
264
- marks.push(np)
265
- } else {
266
- marks.splice(i, 0, np)
252
+ const pushMark = (marks, opts) => {
253
+ //binary search
254
+ let left = 0, right = marks.length
255
+ while (left < right) {
256
+ const mid = (left + right) >> 1
257
+ if (marks[mid].s > opts.s) {
258
+ right = mid
259
+ } else {
260
+ left = mid + 1
261
+ }
267
262
  }
263
+ marks.splice(left, 0, { ...opts });
268
264
  }
269
265
 
270
266
  const setStrong = (state, inlines, marks, n, memo, opt) => {
271
267
  let i = n + 1
272
268
  let j = 0
273
269
  let nest = 0
274
- let insideTagsIsClose = 1
275
- let prevHtmlTags = {...memo.htmlTags}
270
+ let insideTagsIsClose = 1 // 1: closed, 0: open still, -1: error
276
271
  while (i < inlines.length) {
277
- if (inlines[i].len === 0) { i++; continue }
278
- if (memo.html) {
279
- if (inlines[i].type === 'html_inline') {
280
- insideTagsIsClose = isJumpTag(inlines, i, memo, prevHtmlTags)
281
- //console.log('insideTagsIsClose: ' + insideTagsIsClose )
282
- if (insideTagsIsClose === -1) return n, nest, memo
283
- if (insideTagsIsClose === 0) { i++; continue }
284
- }
272
+ //console.log('[strong] i: ' + i + ', inlines[i].len: ' + inlines[i].len + ', inlines[i].type: ' + inlines[i].type)
273
+ if (inlines[i].len === 0 || inlines[i].check) { i++; continue }
274
+ if (inlines[i].type === 'html_inline') {
275
+ inlines[i].check = true
276
+ insideTagsIsClose = checkInsideTags(inlines, i, memo)
277
+ //console.log(' nest: ' + nest + ', insideTagsIsClose: ' + insideTagsIsClose )
278
+ if (insideTagsIsClose === -1) return n, nest
279
+ if (insideTagsIsClose === 0) { i++; continue }
285
280
  }
286
281
  if (inlines[i].type !== '') { i++; continue }
287
282
 
288
- //console.log('n: ' + n + ' [strong]: inlines[n].len: ' + inlines[n].len + ', i: ' + i + ', inlines[i].len: ' + inlines[i].len)
289
-
290
283
  nest = checkNest(inlines, marks, n, i)
291
- //console.log('n: ' + n + ' [strong]: nest: ' + nest)
292
- if (nest === -1) return n, nest, memo
284
+ //console.log(' check nest: ' + nest)
285
+ if (nest === -1) return n, nest
286
+
293
287
  if (inlines[i].len === 1 && inlines[n].len > 2) {
294
- //console.log('n: ' + n + ' [strong]: check em inside strong: ' + nest)
295
- marksPush(marks, nest, inlines[n].ep, inlines[n].ep, 1, inlines[n].len - 1, 'em_open')
296
- marksPush(marks, nest, inlines[i].sp, inlines[i].ep, 1, inlines[i].len - 1, 'em_close')
288
+ //console.log(' check em inside strong:: i: ' + i)
289
+ pushMark(marks, {
290
+ nest: nest,
291
+ s: inlines[n].ep,
292
+ e: inlines[n].ep,
293
+ len: 1,
294
+ oLen: inlines[n].len - 1,
295
+ type: 'em_open'
296
+ })
297
+ pushMark(marks, {
298
+ nest: nest,
299
+ s: inlines[i].sp,
300
+ e: inlines[i].ep,
301
+ len: 1,
302
+ oLen: inlines[i].len - 1,
303
+ type: 'em_close'
304
+ })
297
305
  inlines[n].len -= 1
298
306
  inlines[n].ep -= 1
299
- inlines[i].len = 0
300
- inlines[i].sp += 1
301
- if (i++ < inlines.length) {
302
- i++
303
- nest++
304
- } else {
305
- return n, nest, memo
307
+ inlines[i].len -= 1
308
+ if (inlines[i].len > 0) inlines[i].sp += 1
309
+ if (insideTagsIsClose === 1) {
310
+ n, nest = setEm(state, inlines, marks, n, memo, opt)
306
311
  }
307
- if (i > inlines.length - 1) return n, nest, memo
308
- }
309
-
310
- //console.log('memo.html: ' + memo.html + 'insideTagsIsClose: ' + insideTagsIsClose + 'inlines[i].len: ' + inlines[i].len)
311
- //if (memo.html && !insideTagsIsClose && inlines[i].len !== 1) {
312
- if (memo.html && inlines[i].len < 2) {
313
- i++; continue;
312
+ //console.log(marks)
314
313
  }
315
-
314
+ //console.log(' check len:: inlines[n].len: ' + inlines[n].len + ', inlines[i].len: ' + inlines[i].len)
316
315
  let strongNum = Math.trunc(Math.min(inlines[n].len, inlines[i].len) / 2)
317
316
 
318
317
  if (inlines[i].len > 1) {
319
- //console.log('n: ' + n + ' [strong]: normal push, nest: ' + nest)
318
+ //console.log(' hasPunctuationOrNonJapanese: ' + hasPunctuationOrNonJapanese(state, inlines, n, i) + ', memo.inlineMarkEnd: ' + memo.inlineMarkEnd)
319
+
320
+ if (hasPunctuationOrNonJapanese(state, inlines, n, i)) {
321
+ if (memo.inlineMarkEnd) {
322
+ //console.log('check nest em.')
323
+ //console.log('~~~~~~~~~~~~~~~~~')
324
+ marks.push(...createMarks(state, inlines, i, inlines.length - 1, memo, opt))
325
+ //console.log('~~~~~~~~~~~~~~~~~')
326
+ if (inlines[i].len === 0) { i++; continue }
327
+ } else {
328
+ return n, nest
329
+ }
330
+ }
331
+ //console.log(' ===> strong normal push. n: ' + n + ', i: ' + i + ' , nest: ' + nest + ',strongNum: ' + strongNum)
332
+
320
333
  j = 0
321
334
  while (j < strongNum) {
322
- //console.log('j: ' + j + ', inlines[i].sp: ' + inlines[i].sp)
323
- marksPush(marks, nest + strongNum - 1 - j , inlines[n].ep - 1, inlines[n].ep, 2, inlines[n].len - 2,'strong_open')
335
+ //console.log(' - j: ' + j + ', inlines[i].sp: ' + inlines[i].sp)
336
+ pushMark(marks, {
337
+ nest: nest + strongNum - 1 - j,
338
+ s: inlines[n].ep - 1,
339
+ e: inlines[n].ep,
340
+ len: 2,
341
+ oLen: inlines[n].len - 2,
342
+ type: 'strong_open'
343
+ })
324
344
  inlines[n].ep -= 2
325
345
  inlines[n].len -= 2
326
- marksPush(marks, nest + strongNum - 1 - j, inlines[i].sp, inlines[i].sp + 1, 2, inlines[i].len - 2,'strong_close')
346
+ pushMark(marks, {
347
+ nest: nest + strongNum - 1 - j,
348
+ s: inlines[i].sp,
349
+ e: inlines[i].sp + 1,
350
+ len: 2,
351
+ oLen: inlines[i].len - 2,
352
+ type: 'strong_close'
353
+ })
327
354
  inlines[i].sp += 2
328
355
  inlines[i].len -= 2
329
- //console.log(marks)
330
356
  j++
331
357
  }
332
- if (inlines[n].len === 0) return n, nest, memo
358
+ if (inlines[n].len === 0) return n, nest
333
359
  }
334
360
 
335
- //console.log('len: ', inlines[n].len, inlines[i].len)
336
- if ((inlines[n].len > 0 && inlines[i] === 1) || (inlines[n].len === 1 && inlines[i].len > 0)) {
337
- //console.log('check em that warp strong.')
361
+ if (inlines[n].len === 1 && inlines[i].len > 0) {
362
+ //console.log(' check em that warp strong.')
338
363
  nest++
339
- n, nest, memo = setEm(state, inlines, marks, n, memo, opt, nest)
340
- if (memo.hasEmThatWrapStrong) {
341
- //console.log('set em that wrap strong.')
342
- let k = 0
343
- while (k < strongNum) {
344
- marks[marks.length - 2 - k * 2 - 1].nest += 1
345
- marks[marks.length - 2 - k * 2].nest += 1
346
- k++
347
- }
348
- }
364
+ n, nest = setEm(state, inlines, marks, n, memo, opt, nest)
349
365
  }
350
- if (inlines[n].len === 0) return n, nest, memo
366
+
351
367
  i++
352
368
  }
353
- return n, nest, memo
369
+
370
+ if (n == 0 && memo.inlineMarkEnd) {
371
+ //console.log('check nest em(inlineMarkEnd).')
372
+ //console.log('===============================')
373
+ marks.push(...createMarks(state, inlines, n + 1 , inlines.length - 1, memo, opt))
374
+ //console.log(marks)
375
+ //console.log('===============================')
376
+ }
377
+ return n, nest
354
378
  }
355
379
 
356
- const isJumpTag = (inlines, n, memo, prevHtmlTags) => {
357
- //console.log(n, 'before::memo.htmlTags: ' + JSON.stringify(memo.htmlTags))
358
- if (inlines[n].tag === undefined) return 0
359
- if (memo.htmlTags[inlines[n].tag[0]] === undefined) {
360
- memo.htmlTags[inlines[n].tag[0]] = 0
380
+ const checkInsideTags = (inlines, i, memo) => {
381
+ //console.log('isJumTag before::memo.htmlTags: ' + JSON.stringify(memo.htmlTags))
382
+ if (inlines[i].tag === undefined) return 0
383
+ const tagName = inlines[i].tag[0].toLowerCase()
384
+ if (memo.htmlTags[tagName] === undefined) {
385
+ memo.htmlTags[tagName] = 0
361
386
  }
362
- //console.log('prevHtmlTags: ' + JSON.stringify(prevHtmlTags))
363
- //console.log('memo.htmlTags: ' + JSON.stringify(memo.htmlTags) + ', inlines[n].tag[1]: ' + inlines[n].tag[1])
364
- if (inlines[n].tag[1] === 'open') {
365
- memo.htmlTags[inlines[n].tag[0]] += 1
387
+ //console.log('memo.htmlTags: ' + JSON.stringify(memo.htmlTags) + ', inlines[i]: ' + JSON.stringify(inlines[i]) + ', inlines[i]')
388
+ if (inlines[i].tag[1] === 'open') {
389
+ memo.htmlTags[tagName] += 1
366
390
  }
367
- if (inlines[n].tag[1] === 'close') {
368
- memo.htmlTags[inlines[n].tag[0]] -= 1
391
+ if (inlines[i].tag[1] === 'close') {
392
+ memo.htmlTags[tagName] -= 1
369
393
  }
370
- //console.log('prevHtmlTags: ' + JSON.stringify(prevHtmlTags))
371
- //console.log('memo.htmlTags: ' + JSON.stringify(memo.htmlTags))
372
- if (prevHtmlTags[inlines[n].tag[0]] === undefined) prevHtmlTags[inlines[n].tag[0]] = 0
373
- if (memo.htmlTags[inlines[n].tag[0]] < prevHtmlTags[inlines[n].tag[0]]) {
394
+ //console.log(' i: ' + i + ', tagName: ' + tagName + ', memo.htmlTags[tagName]: ' + memo.htmlTags[tagName] + ', prevHtmlTags[tagName]: ' + prevHtmlTags[tagName])
395
+ if (memo.htmlTags[tagName] < 0) {
374
396
  return -1
375
397
  }
376
- //console.log(n, 'after::memo.htmlTags: ' + JSON.stringify(memo.htmlTags))
398
+ //console.log('isJumTag after::memo.htmlTags: ' + JSON.stringify(memo.htmlTags))
377
399
  const closeAllTags = Object.values(memo.htmlTags).every(val => val === 0)
378
- //console.log('closeAllTags: ' + closeAllTags)
379
400
  if (closeAllTags) return 1
380
- // if (inlines[n].tag[1] === 'close') return -1
381
- //memo.htmlTags = {}
382
401
  return 0
383
402
  }
384
403
 
404
+ const isPunctuation = (ch) => {
405
+ return REG_PUNCTUATION.test(ch)
406
+ }
407
+ const isJapanese = (ch) => {
408
+ return REG_JAPANESE.test(ch)
409
+ }
410
+
411
+ const hasPunctuationOrNonJapanese = (state, inlines, n, i) => {
412
+ const src = state.src
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
423
+ }
424
+
385
425
  const setEm = (state, inlines, marks, n, memo, opt, sNest) => {
386
426
  let i = n + 1
387
427
  let nest = 0
388
428
  let strongPNum = 0
389
- let insideTagsIsClose = 1 //true
390
- let prevHtmlTags = {...memo.htmlTags}
391
- //console.log('memo.prevHtmlTags: ' + JSON.stringify(memo.prevHtmlTags))
429
+ let insideTagsIsClose = 1
392
430
  while (i < inlines.length) {
393
- //console.log('i: ' + i + ', src: ' + state.src.slice(inlines[i].sp, inlines[i].ep + 1) + ', inlines[i]: ' + JSON.stringify(inlines[i]))
394
- if (inlines[i].len === 0) { i++; continue }
395
- //console.log(' memo.isEm: ' + memo.isEm + ', memo.html: ' + memo.html + ', inlines[i].type: ' + inlines[i].type)
396
- if (memo.isEm && memo.html) {
397
- if (inlines[i].type === 'html_inline') {
398
- insideTagsIsClose = isJumpTag(inlines, i, memo, prevHtmlTags)
399
- //console.log('insideTagsIsClose: ' + insideTagsIsClose)
400
- if (insideTagsIsClose === -1) return n, nest, memo
401
- if (insideTagsIsClose === 0) { i++; continue }
402
- }
431
+ //console.log('[em] i: ' + i + ', src: ' + state.src.slice(inlines[i].sp, inlines[i].ep + 1) + ', inlines[i]: ' + JSON.stringify(inlines[i]))
432
+ //console.log(inlines[i].type, JSON.stringify(memo.htmlTags))
433
+ if (inlines[i].len === 0 || inlines[i].check) { i++; continue }
434
+ if (!sNest && inlines[i].type === 'html_inline') {
435
+ inlines.check = true
436
+ insideTagsIsClose = checkInsideTags(inlines, i, memo)
437
+ //console.log(' i: ' + i + ', insideTagsIsClose: ' + insideTagsIsClose)
438
+ if (insideTagsIsClose === -1) return n, nest
439
+ if (insideTagsIsClose === 0) { i++; continue }
403
440
  }
404
-
405
-
406
441
  if (inlines[i].type !== '') { i++; continue }
407
442
 
408
443
  const emNum = Math.min(inlines[n].len, inlines[i].len)
409
- if (memo.isEm && emNum !== 1) return n, sNest, memo
410
- //console.log('n: ' + n + ' [em]: inlines[n].len: ' + inlines[n].len + ', i: ' + i, ', inlines[i].len: ' + inlines[i].len + ', isEm: ' + memo.isEm)
411
- //console.log(marks)
412
444
 
413
- let curlyProcess = false
414
- if (opt.mditAttrs) {
415
- const checkText = state.src.slice(inlines[i-1].sp, inlines[i-1].ep + 1)
416
- if (/{[^{}\n!@#%^&*()]+?}$/.test(checkText)) {
417
- curlyProcess = true
418
- }
419
- }
420
- //if (memo.isEm && !curlyProcess && inlines[i].len === 2 && !memo.inlineMarkStart) {
445
+ //console.log('sNest: ' + sNest + ', emNum: ' + emNum)
446
+ if (!sNest && emNum !== 1) return n, sNest, memo
447
+
421
448
  const hasMarkersAtStartAndEnd = (i) => {
422
449
  let flag = memo.inlineMarkStart
423
450
  if (!flag) return false
@@ -426,7 +453,7 @@ const setEm = (state, inlines, marks, n, memo, opt, sNest) => {
426
453
  inlines[i].len > 1 ? flag = true : flag = false
427
454
  return flag
428
455
  }
429
- if (memo.isEm && !curlyProcess && inlines[i].len === 2 && !hasMarkersAtStartAndEnd(i)) {
456
+ if (!sNest && inlines[i].len === 2 && !hasMarkersAtStartAndEnd(i)) {
430
457
  strongPNum++
431
458
  i++
432
459
  continue
@@ -437,44 +464,83 @@ const setEm = (state, inlines, marks, n, memo, opt, sNest) => {
437
464
  } else {
438
465
  nest = checkNest(inlines, marks, n, i)
439
466
  }
440
- //console.log('n: ' + n + ' [em]: nest: ' + nest)
441
- if (nest === -1) return n, nest, memo
467
+ //console.log(' nest: ' + nest + ', emNum: ' + emNum)
468
+ if (nest === -1) return n, nest
442
469
 
443
470
  if (emNum === 1) {
444
- //console.log(n, i, 'insideTagsIsClose: ' + insideTagsIsClose, !insideTagsIsClose, inlines[i].len)
445
- if (memo.html && inlines[i].len < 1) {
471
+ //console.log(' hasPunctuationOrNonJapanese: ' + hasPunctuationOrNonJapanese(state, inlines, n, i) + ', memo.inlineMarkEnd: ' + memo.inlineMarkEnd)
472
+ if (hasPunctuationOrNonJapanese(state, inlines, n, i)) {
473
+ if (memo.inlineMarkEnd) {
474
+ //console.log('check nest em.')
475
+ //console.log('~~~~~~~~~~~~~~~~~')
476
+ marks.push(...createMarks(state, inlines, i, inlines.length - 1, memo, opt))
477
+ //console.log('~~~~~~~~~~~~~~~~~')
478
+
479
+ if (inlines[i].len === 0) { i++; continue }
480
+ } else {
481
+ return n, nest
482
+ }
483
+ }
484
+ //console.log('inlines[i].len: ' + inlines[i].len)
485
+ if (inlines[i].len < 1) { // memo.html
446
486
  i++; continue;
447
487
  }
448
488
 
449
- //console.log('n: ' + n + ' [em]: Normal push, nest: ' + nest, ', strongPNum: ' + strongPNum)
489
+ //console.log(' ===> em Normal push. n: ' + n + ', i: ' + i + ', nest: ' + nest, ', strongPNum: ' + strongPNum)
450
490
  //console.log(inlines[n].ep, inlines[n].sp, inlines[n].s)
451
-
452
- marksPush(marks, nest, inlines[n].ep, inlines[n].ep, 1, inlines[n].len - 1, 'em_open')
491
+ pushMark(marks, {
492
+ nest: nest,
493
+ s: inlines[n].ep,
494
+ e: inlines[n].ep,
495
+ len: 1,
496
+ oLen: inlines[n].len - 1,
497
+ type: 'em_open'
498
+ })
453
499
  inlines[n].ep -= 1
454
500
  inlines[n].len -= 1
455
501
 
456
502
  if (strongPNum % 2 === 0 || inlines[i].len < 2) {
457
- marksPush(marks, nest, inlines[i].sp, inlines[i].sp, 1, inlines[i].len - 1, 'em_close')
503
+ pushMark(marks, {
504
+ nest: nest,
505
+ s: inlines[i].sp,
506
+ e: inlines[i].sp,
507
+ len: 1,
508
+ oLen: inlines[i].len - 1,
509
+ type: 'em_close'
510
+ })
458
511
  inlines[i].sp += 1
459
512
  } else {
460
- marksPush(marks, nest, inlines[i].ep, inlines[i].ep, 1, inlines[i].len - 1, 'em_close')
513
+ pushMark(marks, {
514
+ nest: nest,
515
+ s: inlines[i].ep,
516
+ e: inlines[i].ep,
517
+ len: 1,
518
+ oLen: inlines[i].len - 1,
519
+ type: 'em_close'
520
+ })
461
521
  inlines[i].sp = inlines[i].ep - 1
462
522
  inlines[i].ep -= 1
463
523
  }
464
524
  inlines[i].len -= 1
465
525
  //console.log(marks)
466
- if (!memo.isEm) memo.hasEmThatWrapStrong = true
467
- if (inlines[n].len === 0) return n, nest, memo
526
+ if (inlines[n].len === 0) return n, nest
468
527
  }
469
528
 
470
529
  i++
471
530
  }
472
- return n, nest, memo
531
+ return n, nest
473
532
  }
474
533
 
475
534
  const setText = (inlines, marks, n, nest) => {
476
535
  //console.log('n: ' + n + ' [text]: inlines[n].len: ' + inlines[n].len)
477
- marksPush(marks, nest, inlines[n].sp, inlines[n].ep, inlines[n].len, -1, 'text')
536
+ pushMark(marks, {
537
+ nest: nest,
538
+ s: inlines[n].sp,
539
+ e: inlines[n].ep,
540
+ len: inlines[n].len,
541
+ oLen: -1,
542
+ type: 'text'
543
+ })
478
544
  inlines[n].len = 0
479
545
  }
480
546
 
@@ -503,7 +569,6 @@ const checkNest = (inlines, marks, n, i) => {
503
569
  if (parentCloseN < marks.length) {
504
570
  while (parentCloseN < marks.length) {
505
571
  if (marks[parentCloseN].nest === parentNest) break
506
- //if (marks.length - 1 == parentCloseN) break
507
572
  parentCloseN++
508
573
  }
509
574
  //console.log('parentCloseN: ' + parentCloseN)
@@ -528,71 +593,66 @@ const createMarks = (state, inlines, start, end, memo, opt) => {
528
593
  let marks = []
529
594
  let n = start
530
595
  while (n < end) {
531
- if (inlines[n].type !== '' || inlines[n].len === 0) { n++; continue }
532
- memo.isEm = inlines[n].len === 1 ? true : false
533
- memo.wrapEm = 0
596
+ if (inlines[n].type !== '') { n++; continue }
534
597
  let nest = 0
535
- //console.log('n: ' + n + ' ----- inlines:: src: ' + state.src.slice(inlines[n].sp, inlines[n].ep + 1) + ', inlines[n].sp: ' + inlines[n].sp + ', inlines.length: ' + inlines.length + ', memo.isEm: ' + memo.isEm)
536
- if (!memo.isEm) {
537
- n, nest, memo = setStrong(state, inlines, marks, n, memo, opt)
598
+ //console.log('n: ' + n + ' ----- inlines:: src: ' + state.src.slice(inlines[n].sp, inlines[n].ep + 1) + ', inlines[n].sp: ' + inlines[n].sp + ', inlines[n].len: ' + inlines[n].len + ', memo.isEm: ' + memo.isEm)
599
+ if (inlines[n].len > 1) {
600
+ n, nest = setStrong(state, inlines, marks, n, memo, opt)
601
+ }
602
+ if (inlines[n].len !== 0) {
603
+ n, nest = setEm(state, inlines, marks, n, memo, opt)
604
+ }
605
+ if (inlines[n].len !== 0) {
606
+ setText(inlines, marks, n, nest)
538
607
  }
539
- n, nest, memo = setEm(state, inlines, marks, n, memo, opt)
540
- if (inlines[n].len !== 0) setText(inlines, marks, n, nest)
541
- //console.log(marks)
542
608
  n++
543
609
  }
544
610
  return marks
545
611
  }
546
612
 
547
- const fixInlines = (inlines, marks) => {
548
- let n = 0
549
- while (n < inlines.length) {
550
- if (inlines[n].type !== '') { n++; continue }
551
- let i = 0
552
- //console.log('n: ' + n + ', inlines[n].s: ' + inlines[n].s + ', inlines[n].e: ' + inlines[n].e)
553
- while (i < marks.length) {
554
- //console.log(marks[i].type, marks[i].s, inlines[n].e, marks[i].e, inlines[n].e)
555
- //console.log(marks[i].s >= inlines[n].s , marks[i].e <= inlines[n].e)
556
- if (marks[i].s >= inlines[n].s && marks[i].e <= inlines[n].e) {
557
- //console.log('n: ' + n + ', i: ' + i + ', marks[i].type: ' + marks[i].type)
558
- inlines.splice(n + i + 1, 0, marks[i])
559
- i++
560
- continue
613
+
614
+ const mergeInlinesAndMarks = (inlines, marks) => {
615
+ marks.sort((a, b) => a.s - b.s)
616
+ const merged = []
617
+ let markIndex = 0
618
+ for (const token of inlines) {
619
+ if (token.type === '') {
620
+ while (markIndex < marks.length && marks[markIndex].s >= token.s && marks[markIndex].e <= token.e) {
621
+ merged.push(marks[markIndex])
622
+ markIndex++
561
623
  }
562
- break
563
- }
564
- if (marks.length) {
565
- marks.splice(0, i)
566
- inlines.splice(n, 1)
567
- n += i
568
624
  } else {
569
- //if (inlines[n].type === '') inlines[n].type = 'text'
570
- n++
625
+ merged.push(token)
571
626
  }
572
627
  }
628
+ while (markIndex < marks.length) {
629
+ merged.push(marks[markIndex++])
630
+ }
631
+ return merged
573
632
  }
574
633
 
575
634
  const strongJa = (state, silent, opt) => {
576
635
  if (silent) return false
577
636
  const start = state.pos
578
637
  let max = state.posMax
638
+ const src = state.src
579
639
  let attributesSrc
580
640
  if (start > max) return false
581
- if (state.src.charCodeAt(start) !== 0x2A) return false
641
+ if (src.charCodeAt(start) !== 0x2A) return false
582
642
  if (hasBackslash(state, start)) return false
583
643
 
584
644
  if (opt.mditAttrs) {
585
- attributesSrc = state.src.match(/((\n)? *){([^{}\n!@#%^&*()]+?)} *$/)
645
+ attributesSrc = src.match(/((\n)? *){([^{}\n!@#%^&*()]+?)} *$/)
586
646
  if (attributesSrc && attributesSrc[3] !== '.') {
587
- max = state.src.slice(0, attributesSrc.index).length
647
+ max = src.slice(0, attributesSrc.index).length
588
648
  if (attributesSrc[2] === '\n') {
589
- max = state.src.slice(0, attributesSrc.index - 1).length
649
+ max = src.slice(0, attributesSrc.index - 1).length
590
650
  }
591
651
  if(hasBackslash(state, attributesSrc.index) && attributesSrc[2] === '' && attributesSrc[1].length === 0) {
592
652
  max = state.posMax
593
653
  }
594
654
  } else {
595
- let endCurlyKet = state.src.match(/(\n *){([^{}\n!@#%^&*()]*?)}.*(} *?)$/)
655
+ let endCurlyKet = src.match(/(\n *){([^{}\n!@#%^&*()]*?)}.*(} *?)$/)
596
656
  if (endCurlyKet) {
597
657
  max -= endCurlyKet[3].length
598
658
  }
@@ -605,20 +665,17 @@ const strongJa = (state, silent, opt) => {
605
665
  //console.log(inlines)
606
666
 
607
667
  const memo = {
608
- isEm: false,
609
- hasEmThatWrapStrong: false,
610
- noSetStrongEnd: false,
611
668
  html: state.md.options.html,
612
669
  htmlTags: {},
613
- inlineMarkStart: state.src.charCodeAt(0) === 0x2A ? true : false,
614
- inlineMarkEnd: state.src.charCodeAt(max - 1) === 0x2A ? true : false,
670
+ inlineMarkStart: src.charCodeAt(0) === 0x2A ? true : false,
671
+ inlineMarkEnd: src.charCodeAt(max - 1) === 0x2A ? true : false,
615
672
  }
616
673
 
617
674
  let marks = createMarks(state, inlines, 0, inlines.length, memo, opt)
618
675
  //console.log('marks: ')
619
676
  //console.log(marks)
620
677
 
621
- fixInlines(inlines, marks)
678
+ inlines = mergeInlinesAndMarks(inlines, marks)
622
679
  //console.log('fix inlines:')
623
680
  //console.log(inlines)
624
681
 
@@ -638,7 +695,7 @@ const strongJa = (state, silent, opt) => {
638
695
  state.pos = max
639
696
  }
640
697
  } else {
641
- state.pos = max + 1
698
+ state.pos = max
642
699
  }
643
700
  //console.log(state.tokens)
644
701
  return true
@@ -649,13 +706,10 @@ const mditStrongJa = (md, option) => {
649
706
  dollarMath: true, //inline math $...$
650
707
  mditAttrs: true, //markdown-it-attrs
651
708
  }
652
- if (option !== undefined) {
653
- for (let o in option) {
654
- opt[o] = option[o]
655
- }
656
- }
709
+ if (option) Object.assign(opt, option)
710
+
657
711
  md.inline.ruler.before('emphasis', 'strong_ja', (state, silent) => {
658
712
  return strongJa(state, silent, opt)
659
713
  })
660
714
  }
661
- export default mditStrongJa
715
+ 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.3.6",
4
+ "version": "0.4.1",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
@@ -215,10 +215,25 @@ aa<span>b*ef*</span>cc
215
215
  [Markdown]
216
216
  a*a<span>b*ef*</span>c*c
217
217
  [HTML:false]
218
- <p>a<em>a&lt;span&gt;b</em>ef<em>&lt;/span&gt;c</em>c</p>
218
+ <p>a<em>a&lt;span&gt;b</em>ef*&lt;/span&gt;c*c</p>
219
219
  [HTML:true]
220
220
  <p>a<em>a<span>b</em>ef*</span>c*c</p>
221
221
 
222
+ [Markdown]
223
+ a*a<span>b*ef*e</span>c*c
224
+ [HTML:false]
225
+ <p>a<em>a&lt;span&gt;b</em>ef<em>e&lt;/span&gt;c</em>c</p>
226
+ [HTML:true]
227
+ <p>a<em>a<span>b</em>ef<em>e</span>c</em>c</p>
228
+
229
+ [Markdown]
230
+ **eee*z<span>a*b</span>*
231
+ [HTML:false]
232
+ <p>*<em>eee<em>z&lt;span&gt;a</em>b&lt;/span&gt;</em></p>
233
+ [HTML:true]
234
+ <p>*<em>eee<em>z<span>a</em>b</span></em></p>
235
+
236
+
222
237
  [Markdown]
223
238
  a***a<span>b</span>c***c
224
239
  [HTML:false]
@@ -226,7 +241,6 @@ a***a<span>b</span>c***c
226
241
  [HTML:true]
227
242
  <p>a<em><strong>a<span>b</span>c</strong></em>c</p>
228
243
 
229
-
230
244
  [Markdown]
231
245
  a***a<span>b***e</span>cc
232
246
  [HTML:false]
@@ -361,3 +375,132 @@ b<span>c</span>*
361
375
  <p>**&lt;br&gt;</p>
362
376
  [HTML:true]
363
377
  <p>**<br></p>
378
+
379
+
380
+ [Markdown]
381
+ a*b<>c*d*e
382
+ [HTML:false]
383
+ <p>a<em>b&lt;&gt;c</em>d*e</p>
384
+ [HTML:true]
385
+ <p>a<em>b&lt;&gt;c</em>d*e</p>
386
+
387
+ [Markdown]
388
+ z*<>*a*b
389
+ [HTML:false]
390
+ <p>z*&lt;&gt;<em>a</em>b</p>
391
+ [HTML:true]
392
+ <p>z*&lt;&gt;<em>a</em>b</p>
393
+
394
+ [Markdown]
395
+ z*<span>*a*b
396
+ [HTML:false]
397
+ <p>z*&lt;span&gt;<em>a</em>b</p>
398
+ [HTML:true]
399
+ <p>z*<span><em>a</em>b</p>
400
+
401
+ [Markdown]
402
+ z*<span>*a*b</span>
403
+ [HTML:false]
404
+ <p>z*&lt;span&gt;<em>a</em>b&lt;/span&gt;</p>
405
+ [HTML:true]
406
+ <p>z*<span><em>a</em>b</span></p>
407
+
408
+ [Markdown]
409
+ *z<span>*a*b</span>
410
+ [HTML:false]
411
+ <p>*z&lt;span&gt;<em>a</em>b&lt;/span&gt;</p>
412
+ [HTML:true]
413
+ <p>*z<span><em>a</em>b</span></p>
414
+
415
+ [Markdown]
416
+ **eee*z<span>*a*b</span>*
417
+ [HTML:false]
418
+ <p>**eee<em>z&lt;span&gt;<em>a</em>b&lt;/span&gt;</em></p>
419
+ [HTML:true]
420
+ <p>**eee<em>z<span><em>a</em>b</span></em></p>
421
+
422
+
423
+ [Markdown]
424
+ ***eee*z<span>*a*b</span>**
425
+ [HTML:false]
426
+ <p><strong><em>eee</em>z&lt;span&gt;<em>a</em>b&lt;/span&gt;</strong></p>
427
+ [HTML:true]
428
+ <p><strong><em>eee</em>z<span><em>a</em>b</span></strong></p>
429
+
430
+
431
+ [Markdown]
432
+ ***a*b<span>c</span>**
433
+ [HTML:false]
434
+ <p><strong><em>a</em>b&lt;span&gt;c&lt;/span&gt;</strong></p>
435
+ [HTML:true]
436
+ <p><strong><em>a</em>b<span>c</span></strong></p>
437
+
438
+
439
+ [Markdown]
440
+ ***<sPan>aa*bb</spaN>cc**
441
+ [HTML:false]
442
+ <p><strong><em>&lt;sPan&gt;aa</em>bb&lt;/spaN&gt;cc</strong></p>
443
+ [HTML:true]
444
+ <p><strong><em><sPan>aa</em>bb</spaN>cc</strong></p>
445
+
446
+
447
+ [Markdown]
448
+ e*z<span>*a*b*
449
+ [HTML:false]
450
+ <p>e<em>z&lt;span&gt;<em>a</em>b</em></p>
451
+ [HTML:true]
452
+ <p>e<em>z<span><em>a</em>b</em></p>
453
+
454
+ [Markdown]
455
+ **e<span>**e**e**
456
+ [HTML:false]
457
+ <p><strong>e&lt;span&gt;<strong>e</strong>e</strong></p>
458
+ [HTML:true]
459
+ <p><strong>e<span><strong>e</strong>e</strong></p>
460
+
461
+ [Markdown]
462
+ e*z<span> *a*b*
463
+ [HTML:false]
464
+ <p>e<em>z&lt;span&gt; <em>a</em>b</em></p>
465
+ [HTML:true]
466
+ <p>e<em>z<span> <em>a</em>b</em></p>
467
+
468
+
469
+ [Markdown]
470
+ ***eee*z<span>a*b</span>**
471
+ [HTML:false]
472
+ <p><em><em><em>eee</em>z&lt;span&gt;a</em>b&lt;/span&gt;</em>*</p>
473
+ [HTML:true]
474
+ <p><em><em><em>eee</em>z<span>a</em>b</span></em>*</p>
475
+
476
+ [Markdown]
477
+ ***<sPan>a</spaN>b**
478
+ [HTML:false]
479
+ <p>*<strong>&lt;sPan&gt;a&lt;/spaN&gt;b</strong></p>
480
+ [HTML:true]
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>
@@ -216,10 +216,24 @@ aa<span>b*ef*</span>cc
216
216
  [Markdown]
217
217
  a*a<span>b*ef*</span>c*c
218
218
  [HTML:false]
219
- <p>a<em>a&lt;span&gt;b</em>ef<em>&lt;/span&gt;c</em>c</p>
219
+ <p>a<em>a&lt;span&gt;b</em>ef*&lt;/span&gt;c*c</p>
220
220
  [HTML:true]
221
221
  <p>a<em>a<span>b</em>ef*</span>c*c</p>
222
222
 
223
+ [Markdown]
224
+ a*a<span>b*ef*e</span>c*c
225
+ [HTML:false]
226
+ <p>a<em>a&lt;span&gt;b</em>ef<em>e&lt;/span&gt;c</em>c</p>
227
+ [HTML:true]
228
+ <p>a<em>a<span>b</em>ef<em>e</span>c</em>c</p>
229
+
230
+ [Markdown]
231
+ **eee*z<span>a*b</span>*
232
+ [HTML:false]
233
+ <p>*<em>eee<em>z&lt;span&gt;a</em>b&lt;/span&gt;</em></p>
234
+ [HTML:true]
235
+ <p>*<em>eee<em>z<span>a</em>b</span></em></p>
236
+
223
237
  [Markdown]
224
238
  a***a<span>b</span>c***c
225
239
  [HTML:false]
@@ -390,4 +404,109 @@ z*<span>*a*b</span>
390
404
  [HTML:false]
391
405
  <p>z*&lt;span&gt;<em>a</em>b&lt;/span&gt;</p>
392
406
  [HTML:true]
393
- <p>z*<span><em>a</em>b</span></p>
407
+ <p>z*<span><em>a</em>b</span></p>
408
+
409
+ [Markdown]
410
+ *z<span>*a*b</span>
411
+ [HTML:false]
412
+ <p>*z&lt;span&gt;<em>a</em>b&lt;/span&gt;</p>
413
+ [HTML:true]
414
+ <p>*z<span><em>a</em>b</span></p>
415
+
416
+ [Markdown]
417
+ **eee*z<span>*a*b</span>*
418
+ [HTML:false]
419
+ <p>**eee<em>z&lt;span&gt;<em>a</em>b&lt;/span&gt;</em></p>
420
+ [HTML:true]
421
+ <p>**eee<em>z<span><em>a</em>b</span></em></p>
422
+
423
+ [Markdown]
424
+ ***eee*z<span>*a*b</span>**
425
+ [HTML:false]
426
+ <p><strong><em>eee</em>z&lt;span&gt;<em>a</em>b&lt;/span&gt;</strong></p>
427
+ [HTML:true]
428
+ <p><strong><em>eee</em>z<span><em>a</em>b</span></strong></p>
429
+
430
+
431
+ [Markdown]
432
+ ***a*b<span>c</span>**
433
+ [HTML:false]
434
+ <p><strong><em>a</em>b&lt;span&gt;c&lt;/span&gt;</strong></p>
435
+ [HTML:true]
436
+ <p><strong><em>a</em>b<span>c</span></strong></p>
437
+
438
+ [Markdown]
439
+ ***<sPan>aa*bb</spaN>cc**
440
+ [HTML:false]
441
+ <p><strong><em>&lt;sPan&gt;aa</em>bb&lt;/spaN&gt;cc</strong></p>
442
+ [HTML:true]
443
+ <p><strong><em><sPan>aa</em>bb</spaN>cc</strong></p>
444
+
445
+ [Markdown]
446
+ e*z<span>*a*b*
447
+ [HTML:false]
448
+ <p>e<em>z&lt;span&gt;<em>a</em>b</em></p>
449
+ [HTML:true]
450
+ <p>e<em>z<span><em>a</em>b</em></p>
451
+
452
+ [Markdown]
453
+ **e<span>**e**e**
454
+ [HTML:false]
455
+ <p><strong>e&lt;span&gt;<strong>e</strong>e</strong></p>
456
+ [HTML:true]
457
+ <p><strong>e<span><strong>e</strong>e</strong></p>
458
+
459
+ [Markdown]
460
+ e*z<span> *a*b*
461
+ [HTML:false]
462
+ <p>e<em>z&lt;span&gt; <em>a</em>b</em></p>
463
+ [HTML:true]
464
+ <p>e<em>z<span> <em>a</em>b</em></p>
465
+
466
+
467
+
468
+ [Markdown]
469
+ ***eee*z<span>a*b</span>**
470
+ [HTML:false]
471
+ <p><em><em><em>eee</em>z&lt;span&gt;a</em>b&lt;/span&gt;</em>*</p>
472
+ [HTML:true]
473
+ <p><em><em><em>eee</em>z<span>a</em>b</span></em>*</p>
474
+
475
+ [Markdown]
476
+ ***<sPan>a</spaN>b**
477
+ [HTML:false]
478
+ <p>*<strong>&lt;sPan&gt;a&lt;/spaN&gt;b</strong></p>
479
+ [HTML:true]
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 !== 62) { n++; continue }
26
+ //if (n !== 81) { n++; continue }
27
27
  const m = ms[n].markdown
28
28
  let h = ''
29
29
  if (example === 'withLineBreak') {
@@ -35,7 +35,7 @@ const check = (ms, example, allPass, useAttrs) => {
35
35
  assert.strictEqual(h, ms[n].html)
36
36
  } catch(e) {
37
37
  console.log('Test [' + n + ', HTML: false, useAttrs: ' + useAttrs + '] >>>')
38
- console.log('Input: ' + ms[n].markdown + '\nConvert: ' + h + 'Correct: ' + ms[n].html)
38
+ console.log('Input: ' + ms[n].markdown + '\nOutput: ' + h + 'Correct: ' + ms[n].html)
39
39
  allPass = false
40
40
  }
41
41
  if (ms[n].htmlWithHtmlTrue) {
@@ -49,7 +49,7 @@ const check = (ms, example, allPass, useAttrs) => {
49
49
  assert.strictEqual(hh, ms[n].htmlWithHtmlTrue)
50
50
  } catch(e) {
51
51
  console.log('Test [' + n + ', HTML: true, useAttrs: ' + useAttrs + '] >>>')
52
- console.log('Input: ' + ms[n].markdown + '\nConvert: ' + hh + 'Correct: ' + ms[n].htmlWithHtmlTrue)
52
+ console.log('Input: ' + ms[n].markdown + '\nOutput: ' + hh + 'Correct: ' + ms[n].htmlWithHtmlTrue)
53
53
  allPass = false
54
54
  }
55
55
  }
@@ -58,7 +58,6 @@ const check = (ms, example, allPass, useAttrs) => {
58
58
  return allPass
59
59
  }
60
60
 
61
-
62
61
  const examples = {
63
62
  strong: __dirname + '/example-strong.txt',
64
63
  em: __dirname + '/example-em.txt',