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