@peaceroad/markdown-it-strong-ja 0.3.5 → 0.3.6

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
@@ -2,22 +2,24 @@
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
- Notice: this is slightly different from the commonmark processing.
6
-
7
5
  ## Use
8
6
 
9
7
  ```js
10
8
  import mdit from 'markdown-it'
11
9
  import mditStrongJa from '@peaceroad/markdown-it-strong-ja'
12
- const md = mdit().use(mditStrongJa)
10
+ import mditAttrs from 'markdown-it-attrs'
11
+ const md = mdit().use(mditStrongJa).use(mditAttrs)
13
12
 
14
13
  md.render('HTMLは**「HyperText Markup Language」**の略です。')
15
14
  // <p>HTMLは<strong>「HyperText Markup Language」</strong>の略です。</p>
16
15
 
16
+
17
17
  md.render('HTMLは*「HyperText Markup Language」*の略です。')
18
18
  // <p>HTMLは<em>「HyperText Markup Language」</em>の略です。</p>
19
19
  ```
20
20
 
21
+ Notice. Basically, it is assumed that you will use markdown-it-attrs in conjunction with this. If you do not use it, please use `use(mditStrongJa, {mditAttrs: false})`.
22
+
21
23
  ## Example
22
24
 
23
25
  The following examples is for strong. The process for em is roughly the same.
@@ -150,4 +152,33 @@ a****b
150
152
  a****
151
153
  [HTML]
152
154
  <p>a****</p>
153
- ~~~
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
@@ -2,44 +2,91 @@ const hasBackslash = (state, start) => {
2
2
  let slashNum = 0
3
3
  let i = start - 1
4
4
  while(i >= 0) {
5
- /// if (state.src.charCodeAt(i) === 0x2A) { i--; continue }
6
5
  if (state.src.charCodeAt(i) === 0x5C) { slashNum++; i--; continue }
7
6
  break
8
7
  }
9
8
  return slashNum % 2 === 1 ? true : false
10
9
  }
11
10
 
12
- const setToken = (state, inlines) => {
11
+ const setToken = (state, inlines, opt) => {
13
12
  let i = 0
13
+ let attrsIsText = {
14
+ val: false,
15
+ tag: '',
16
+ }
14
17
  while (i < inlines.length) {
15
18
  let type = inlines[i].type
19
+ //console.log(i, type)
16
20
  const tag = type.replace(/(?:_open|_close)$/, '')
17
21
 
18
22
  if (/_open$/.test(type)) {
19
23
  const startToken = state.push(type, tag, 1)
20
24
  startToken.markup = tag === 'strong' ? '**' : '*'
25
+ attrsIsText = {
26
+ val: true,
27
+ tag: tag,
28
+ }
21
29
  }
22
30
 
23
31
  if (type === 'html_inline') {
24
32
  type = 'text'
25
33
  }
26
34
  if (type === 'text') {
27
- const content = state.src.slice(inlines[i].s, inlines[i].e + 1)
28
- if (/^\**$/.test(content)) {
35
+ let content = state.src.slice(inlines[i].s, inlines[i].e + 1)
36
+ //console.log('content: ' + content)
37
+ if (/^\*+$/.test(content)) {
29
38
  //console.log('asterisk process::')
30
39
  const asteriskToken = state.push(type, '', 0)
31
40
  asteriskToken.content = content
32
41
  i++
33
42
  continue
34
43
  }
44
+ if (opt.mditAttrs && attrsIsText.val && i + 1 < inlines.length) {
45
+ const hasImmediatelyAfterAsteriskClose = inlines[i+1].type === attrsIsText.tag + '_close'
46
+ //console.log(hasImmediatelyAfterAsteriskClose, inlines[i+1].type, /^[\s\S]*{[^{}\n!@#%^&*()]+?}$/.test(content))
47
+ if (hasImmediatelyAfterAsteriskClose && /{[^{}\n!@#%^&*()]+?}$/.test(content)) {
48
+ const attrsToken = state.push(type, '', 0)
49
+
50
+ const hasBackslashBeforeCurlyAttribute = content.match(/(\\+){/)
51
+ if (hasBackslashBeforeCurlyAttribute) {
52
+ if (hasBackslashBeforeCurlyAttribute[1].length === 1) {
53
+ attrsToken.content = content.replace(/\\{/, '{')
54
+ } else {
55
+ let backSlashNum = Math.floor(hasBackslashBeforeCurlyAttribute[1].length / 2)
56
+ let k = 0
57
+ let backSlash = ''
58
+ while (k < backSlashNum) {
59
+ backSlash += '\\'
60
+ k++
61
+ }
62
+ //console.log(backSlashNum, backSlash)
63
+ attrsToken.content = content.replace(/\\+{/, backSlash + '{')
64
+ }
65
+ } else {
66
+ attrsToken.content = content
67
+ }
68
+ attrsIsText.val = false
69
+ i++
70
+ continue
71
+ }
72
+ }
35
73
 
36
74
  const childTokens = state.md.parseInline(content, state.env)
75
+ //console.log(childTokens)
76
+ //console.log(childTokens[0].children)
37
77
  if (childTokens[0] && childTokens[0].children) {
38
- //console.log(state.tokens)
39
- //console.log(state.tokens[state.tokens.length - 1])
40
- state.tokens[state.tokens.length - 1].children = childTokens[0].children
41
- childTokens[0].children.forEach(t => {
42
- //console.log('t.type: ' + t.type + ', t.tag: ' + t.tag + ', t.nesting: ' + t.nesting)
78
+ let j = 0
79
+ while (j < childTokens[0].children.length) {
80
+ const t = childTokens[0].children[j]
81
+ if (t.type === 'softbreak') {
82
+ t.type = 'text'
83
+ t.tag = ''
84
+ t.content = '\n'
85
+ }
86
+ if (!opt.mditAttrs && t.tag === 'br') {
87
+ t.tag = ''
88
+ t.content = '\n'
89
+ }
43
90
  const token = state.push(t.type, t.tag, t.nesting)
44
91
  token.attrs = t.attrs
45
92
  token.map = t.map
@@ -51,13 +98,18 @@ const setToken = (state, inlines) => {
51
98
  token.meta = t.meta
52
99
  token.block = t.block
53
100
  token.hidden = t.hidden
54
- })
101
+ j++
102
+ }
55
103
  }
56
104
  }
57
105
 
58
106
  if (/_close$/.test(type)) {
59
107
  const closeToken = state.push(type, tag, -1)
60
108
  closeToken.markup = tag === 'strong' ? '**' : '*'
109
+ attrsIsText = {
110
+ val: false,
111
+ tag: '',
112
+ }
61
113
  }
62
114
 
63
115
  i++
@@ -101,6 +153,7 @@ const createInlines = (state, start, max, opt) => {
101
153
  let noMark = ''
102
154
  let textStart = n
103
155
  while (n < max) {
156
+ //console.log('n: ' + n + ', state.src[n]: ' + state.src[n] + ', noMark: ' + noMark)
104
157
  let nextSymbolPos = -1;
105
158
  [nextSymbolPos, noMark] = hasNextSymbol(state, n, max, 0x60, noMark) // '`'
106
159
  if (nextSymbolPos !== -1) {
@@ -129,7 +182,9 @@ const createInlines = (state, start, max, opt) => {
129
182
  while (i < max) {
130
183
  if (state.src.charCodeAt(i) === 0x3E && !hasBackslash(state, i)) { // '>'
131
184
  if (noMark.length !== 0) {
185
+ // Add the text before the tag to inlines
132
186
  inlinesPush(inlines, textStart, n - 1, n - textStart, 'text')
187
+ noMark = ''
133
188
  }
134
189
  let tag = state.src.slice(n + 1, i)
135
190
  let tagType = ''
@@ -149,9 +204,20 @@ const createInlines = (state, start, max, opt) => {
149
204
  continue
150
205
  }
151
206
  }
207
+
152
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
+ }*/
153
217
  if (n !== 0) {
218
+ //Add text before asterisk to inlines
154
219
  inlinesPush(inlines, textStart, n - 1, n - textStart, 'text')
220
+ noMark = ''
155
221
  }
156
222
  if (n === max - 1) {
157
223
  inlinesPush(inlines, n, n, 1 , '')
@@ -171,6 +237,7 @@ const createInlines = (state, start, max, opt) => {
171
237
  n = i
172
238
  continue
173
239
  }
240
+
174
241
  noMark += state.src[n]
175
242
  if (n === max - 1) {
176
243
  inlinesPush(inlines, textStart, n, n - textStart + 1, 'text')
@@ -200,16 +267,17 @@ const marksPush = (marks, nest, s, e, len, outsideLen, type) => {
200
267
  }
201
268
  }
202
269
 
203
- const setStrong = (inlines, marks, n, memo) => {
270
+ const setStrong = (state, inlines, marks, n, memo, opt) => {
204
271
  let i = n + 1
205
272
  let j = 0
206
273
  let nest = 0
207
274
  let insideTagsIsClose = 1
275
+ let prevHtmlTags = {...memo.htmlTags}
208
276
  while (i < inlines.length) {
209
277
  if (inlines[i].len === 0) { i++; continue }
210
278
  if (memo.html) {
211
279
  if (inlines[i].type === 'html_inline') {
212
- insideTagsIsClose = isJumpTag(inlines, i, memo)
280
+ insideTagsIsClose = isJumpTag(inlines, i, memo, prevHtmlTags)
213
281
  //console.log('insideTagsIsClose: ' + insideTagsIsClose )
214
282
  if (insideTagsIsClose === -1) return n, nest, memo
215
283
  if (insideTagsIsClose === 0) { i++; continue }
@@ -240,9 +308,11 @@ const setStrong = (inlines, marks, n, memo) => {
240
308
  }
241
309
 
242
310
  //console.log('memo.html: ' + memo.html + 'insideTagsIsClose: ' + insideTagsIsClose + 'inlines[i].len: ' + inlines[i].len)
243
- if (memo.html && !insideTagsIsClose && inlines[i].len !== 1) {
244
- i++; continue
311
+ //if (memo.html && !insideTagsIsClose && inlines[i].len !== 1) {
312
+ if (memo.html && inlines[i].len < 2) {
313
+ i++; continue;
245
314
  }
315
+
246
316
  let strongNum = Math.trunc(Math.min(inlines[n].len, inlines[i].len) / 2)
247
317
 
248
318
  if (inlines[i].len > 1) {
@@ -266,13 +336,13 @@ const setStrong = (inlines, marks, n, memo) => {
266
336
  if ((inlines[n].len > 0 && inlines[i] === 1) || (inlines[n].len === 1 && inlines[i].len > 0)) {
267
337
  //console.log('check em that warp strong.')
268
338
  nest++
269
- n, nest, memo = setEm(inlines, marks, n, memo, nest)
339
+ n, nest, memo = setEm(state, inlines, marks, n, memo, opt, nest)
270
340
  if (memo.hasEmThatWrapStrong) {
271
341
  //console.log('set em that wrap strong.')
272
342
  let k = 0
273
343
  while (k < strongNum) {
274
- marks[marks.length - 2 - k * 2 - 1].nest += 1
275
- marks[marks.length - 2 - k * 2].nest += 1
344
+ marks[marks.length - 2 - k * 2 - 1].nest += 1
345
+ marks[marks.length - 2 - k * 2].nest += 1
276
346
  k++
277
347
  }
278
348
  }
@@ -283,49 +353,56 @@ const setStrong = (inlines, marks, n, memo) => {
283
353
  return n, nest, memo
284
354
  }
285
355
 
286
- const isJumpTag = (inlines, n, memo) => {
356
+ const isJumpTag = (inlines, n, memo, prevHtmlTags) => {
287
357
  //console.log(n, 'before::memo.htmlTags: ' + JSON.stringify(memo.htmlTags))
288
- const hasSet = Object.keys(memo.htmlTags).some(tag => {
289
- if (tag === inlines[n].tag[0]) {
290
- if (inlines[n].tag[1] === 'open') {
291
- memo.htmlTags[tag]++ }
292
- else {
293
- memo.htmlTags[tag]--
294
- }
295
- return true
296
- }
297
- return false
298
- })
299
- if (!hasSet && !memo.htmlTags[inlines[n].tag[0]]) {
300
- if (inlines[n].tag[1] === 'close') {
301
- memo.htmlTags = {}
302
- return -1
303
- }
304
- memo.htmlTags[inlines[n].tag[0]] = 1
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
361
+ }
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
305
366
  }
306
- //console.log(n, 'after::memo.htmlTags: ' + JSON.stringify(memo.htmlTags))
367
+ if (inlines[n].tag[1] === 'close') {
368
+ memo.htmlTags[inlines[n].tag[0]] -= 1
369
+ }
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]]) {
374
+ return -1
375
+ }
376
+ //console.log(n, 'after::memo.htmlTags: ' + JSON.stringify(memo.htmlTags))
307
377
  const closeAllTags = Object.values(memo.htmlTags).every(val => val === 0)
308
378
  //console.log('closeAllTags: ' + closeAllTags)
309
379
  if (closeAllTags) return 1
380
+ // if (inlines[n].tag[1] === 'close') return -1
310
381
  //memo.htmlTags = {}
311
382
  return 0
312
383
  }
313
384
 
314
- const setEm = (inlines, marks, n, memo, sNest) => {
385
+ const setEm = (state, inlines, marks, n, memo, opt, sNest) => {
315
386
  let i = n + 1
316
387
  let nest = 0
317
388
  let strongPNum = 0
318
- let insideTagsIsClose = 1
389
+ let insideTagsIsClose = 1 //true
390
+ let prevHtmlTags = {...memo.htmlTags}
391
+ //console.log('memo.prevHtmlTags: ' + JSON.stringify(memo.prevHtmlTags))
319
392
  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]))
320
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)
321
396
  if (memo.isEm && memo.html) {
322
397
  if (inlines[i].type === 'html_inline') {
323
- insideTagsIsClose = isJumpTag(inlines, i, memo)
324
- //console.log('insideTagsIsClose: ' + insideTagsIsClose )
398
+ insideTagsIsClose = isJumpTag(inlines, i, memo, prevHtmlTags)
399
+ //console.log('insideTagsIsClose: ' + insideTagsIsClose)
325
400
  if (insideTagsIsClose === -1) return n, nest, memo
326
401
  if (insideTagsIsClose === 0) { i++; continue }
327
402
  }
328
403
  }
404
+
405
+
329
406
  if (inlines[i].type !== '') { i++; continue }
330
407
 
331
408
  const emNum = Math.min(inlines[n].len, inlines[i].len)
@@ -333,7 +410,23 @@ const setEm = (inlines, marks, n, memo, sNest) => {
333
410
  //console.log('n: ' + n + ' [em]: inlines[n].len: ' + inlines[n].len + ', i: ' + i, ', inlines[i].len: ' + inlines[i].len + ', isEm: ' + memo.isEm)
334
411
  //console.log(marks)
335
412
 
336
- if (memo.isEm && inlines[i].len === 2) {
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) {
421
+ const hasMarkersAtStartAndEnd = (i) => {
422
+ let flag = memo.inlineMarkStart
423
+ if (!flag) return false
424
+ inlines.length - 1 === i ? flag = true : flag = false
425
+ if (!flag) return false
426
+ inlines[i].len > 1 ? flag = true : flag = false
427
+ return flag
428
+ }
429
+ if (memo.isEm && !curlyProcess && inlines[i].len === 2 && !hasMarkersAtStartAndEnd(i)) {
337
430
  strongPNum++
338
431
  i++
339
432
  continue
@@ -348,12 +441,12 @@ const setEm = (inlines, marks, n, memo, sNest) => {
348
441
  if (nest === -1) return n, nest, memo
349
442
 
350
443
  if (emNum === 1) {
351
- //console.log(n, i, 'insideTagsIsClose: ' + insideTagsIsClose)
352
- if (memo.html && !insideTagsIsClose && inlines[i].len !== 2) {
444
+ //console.log(n, i, 'insideTagsIsClose: ' + insideTagsIsClose, !insideTagsIsClose, inlines[i].len)
445
+ if (memo.html && inlines[i].len < 1) {
353
446
  i++; continue;
354
447
  }
355
- //console.log('n: ' + n + ' [em]: normal push, nest: ' + nest)
356
- //console.log('strongPNum: ' + strongPNum)
448
+
449
+ //console.log('n: ' + n + ' [em]: Normal push, nest: ' + nest, ', strongPNum: ' + strongPNum)
357
450
  //console.log(inlines[n].ep, inlines[n].sp, inlines[n].s)
358
451
 
359
452
  marksPush(marks, nest, inlines[n].ep, inlines[n].ep, 1, inlines[n].len - 1, 'em_open')
@@ -367,7 +460,6 @@ const setEm = (inlines, marks, n, memo, sNest) => {
367
460
  marksPush(marks, nest, inlines[i].ep, inlines[i].ep, 1, inlines[i].len - 1, 'em_close')
368
461
  inlines[i].sp = inlines[i].ep - 1
369
462
  inlines[i].ep -= 1
370
-
371
463
  }
372
464
  inlines[i].len -= 1
373
465
  //console.log(marks)
@@ -382,9 +474,7 @@ const setEm = (inlines, marks, n, memo, sNest) => {
382
474
 
383
475
  const setText = (inlines, marks, n, nest) => {
384
476
  //console.log('n: ' + n + ' [text]: inlines[n].len: ' + inlines[n].len)
385
- //marksPush(marks, -1, inlines[n].sp + 1, inlines[n].ep, inlines[n].len, -1, 'text')
386
477
  marksPush(marks, nest, inlines[n].sp, inlines[n].ep, inlines[n].len, -1, 'text')
387
- //inlines[n].sp += 1
388
478
  inlines[n].len = 0
389
479
  }
390
480
 
@@ -434,7 +524,7 @@ const checkNest = (inlines, marks, n, i) => {
434
524
  return nest
435
525
  }
436
526
 
437
- const createMarks = (inlines, start, end, memo) => {
527
+ const createMarks = (state, inlines, start, end, memo, opt) => {
438
528
  let marks = []
439
529
  let n = start
440
530
  while (n < end) {
@@ -442,11 +532,11 @@ const createMarks = (inlines, start, end, memo) => {
442
532
  memo.isEm = inlines[n].len === 1 ? true : false
443
533
  memo.wrapEm = 0
444
534
  let nest = 0
445
- //console.log('n: ' + n + ' ----- inlines.length: ' + inlines.length + ', memo.isEm: ' + memo.isEm)
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)
446
536
  if (!memo.isEm) {
447
- n, nest, memo = setStrong(inlines, marks, n, memo)
537
+ n, nest, memo = setStrong(state, inlines, marks, n, memo, opt)
448
538
  }
449
- n, nest, memo = setEm(inlines, marks, n, memo)
539
+ n, nest, memo = setEm(state, inlines, marks, n, memo, opt)
450
540
  if (inlines[n].len !== 0) setText(inlines, marks, n, nest)
451
541
  //console.log(marks)
452
542
  n++
@@ -487,17 +577,29 @@ const strongJa = (state, silent, opt) => {
487
577
  const start = state.pos
488
578
  let max = state.posMax
489
579
  let attributesSrc
490
- if (opt.hasCurlyAttributes) {
491
- attributesSrc = state.src.match(/( *){.*?}$/)
492
- if (attributesSrc) {
580
+ if (start > max) return false
581
+ if (state.src.charCodeAt(start) !== 0x2A) return false
582
+ if (hasBackslash(state, start)) return false
583
+
584
+ if (opt.mditAttrs) {
585
+ attributesSrc = state.src.match(/((\n)? *){([^{}\n!@#%^&*()]+?)} *$/)
586
+ if (attributesSrc && attributesSrc[3] !== '.') {
493
587
  max = state.src.slice(0, attributesSrc.index).length
588
+ if (attributesSrc[2] === '\n') {
589
+ max = state.src.slice(0, attributesSrc.index - 1).length
590
+ }
591
+ if(hasBackslash(state, attributesSrc.index) && attributesSrc[2] === '' && attributesSrc[1].length === 0) {
592
+ max = state.posMax
593
+ }
594
+ } else {
595
+ let endCurlyKet = state.src.match(/(\n *){([^{}\n!@#%^&*()]*?)}.*(} *?)$/)
596
+ if (endCurlyKet) {
597
+ max -= endCurlyKet[3].length
598
+ }
494
599
  }
495
600
  }
496
- if (start > max) return false
497
- if (state.src.charCodeAt(start) !== 0x2A) return false
498
601
 
499
- if (hasBackslash(state, start)) return false
500
- //console.log('state.src.length: ' + state.src.length + ', start: ' + start + ', state.src: ' + state.src)
602
+ //console.log('state.src.length(max): ' + state.src.length + (state.src.length === max ? '' : '(' + max + ')') + ', start: ' + start + ', state.src: ' + state.src)
501
603
  let inlines = createInlines(state, start, max, opt)
502
604
  //console.log('inlines: ')
503
605
  //console.log(inlines)
@@ -511,7 +613,8 @@ const strongJa = (state, silent, opt) => {
511
613
  inlineMarkStart: state.src.charCodeAt(0) === 0x2A ? true : false,
512
614
  inlineMarkEnd: state.src.charCodeAt(max - 1) === 0x2A ? true : false,
513
615
  }
514
- let marks = createMarks(inlines, 0, inlines.length, memo)
616
+
617
+ let marks = createMarks(state, inlines, 0, inlines.length, memo, opt)
515
618
  //console.log('marks: ')
516
619
  //console.log(marks)
517
620
 
@@ -519,10 +622,16 @@ const strongJa = (state, silent, opt) => {
519
622
  //console.log('fix inlines:')
520
623
  //console.log(inlines)
521
624
 
522
- setToken(state, inlines)
625
+ setToken(state, inlines, opt)
626
+
627
+ //console.log ('End process:: max:' + max + ', state.posMax: ' + state.posMax + ', opt.mditAttrs: ' + opt.mditAttrs)
523
628
 
524
- if (attributesSrc) {
525
- //console.log('attributesSrc[1].length: ' + attributesSrc[1].length)
629
+ if (opt.mditAttrs && max !== state.posMax) {
630
+ if (!attributesSrc) {
631
+ state.pos = max
632
+ return true
633
+ }
634
+ //console.log('start: ' + start + ', attributesSrc[0]::' + attributesSrc[0] + ', attributesSrc[1].length: ' + attributesSrc[1].length)
526
635
  if (attributesSrc[1].length > 1) {
527
636
  state.pos = max + attributesSrc[1].length
528
637
  } else {
@@ -531,17 +640,15 @@ const strongJa = (state, silent, opt) => {
531
640
  } else {
532
641
  state.pos = max + 1
533
642
  }
643
+ //console.log(state.tokens)
534
644
  return true
535
645
  }
536
646
 
537
647
  const mditStrongJa = (md, option) => {
538
648
  const opt = {
539
- dollarMath: true,
540
- hasCurlyAttributes: false,
649
+ dollarMath: true, //inline math $...$
650
+ mditAttrs: true, //markdown-it-attrs
541
651
  }
542
- opt.hasCurlyAttributes = md.core.ruler.__rules__.filter(rule => {
543
- rule.name === 'curly_attributes' // markdown-it-attrs
544
- })
545
652
  if (option !== undefined) {
546
653
  for (let o in option) {
547
654
  opt[o] = option[o]
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.5",
4
+ "version": "0.3.6",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
@@ -11,6 +11,7 @@
11
11
  "author": "peaceroad <peaceroad@gmail.com>",
12
12
  "license": "MIT",
13
13
  "devDependencies": {
14
+ "@sup39/markdown-it-cjk-breaks": "^1.2.0",
14
15
  "markdown-it": "^14.1.0",
15
16
  "markdown-it-attrs": "^4.2.0"
16
17
  }
@@ -85,11 +85,10 @@ HTMLは**「*HyperText* Markup *Language*」**の略です。
85
85
  [HTML]
86
86
  <p><em>a<strong>b</strong>c<strong>d</strong>e</em></p>
87
87
 
88
-
89
88
  [Markdown]
90
89
  *aa**
91
- [HTML commomark: <p><em>aa</em>*</p>]
92
- <p>*aa**</p>
90
+ [HTML]
91
+ <p><em>aa</em>*</p>
93
92
 
94
93
  [Markdown]
95
94
  a*aa**
@@ -185,13 +184,12 @@ a**b**c {.style}
185
184
  [HTML]
186
185
  <p class="style">a<strong>b</strong>c</p>
187
186
 
188
-
189
187
  [Markdown]
190
188
  z*a<span>b*c</span>d*e
191
189
  [HTML]
192
190
  <p>z<em>a&lt;span&gt;b</em>c&lt;/span&gt;d*e</p>
193
191
  [HTML:true]
194
- <p>z<em>a<span>b*c</span>d</em>e</p>
192
+ <p>z<em>a<span>b</em>c</span>d*e</p>
195
193
 
196
194
  [Markdown]
197
195
  a<span>b*c</span>d*e*f
@@ -218,9 +216,8 @@ aa<span>b*ef*</span>cc
218
216
  a*a<span>b*ef*</span>c*c
219
217
  [HTML:false]
220
218
  <p>a<em>a&lt;span&gt;b</em>ef<em>&lt;/span&gt;c</em>c</p>
221
- [HTML:true, commonmark: <p>a<em>a<span>b</em>ef*</span>c*c</p>]
222
- <p>a<em>a<span>b<em>ef</em></span>c</em>c</p>
223
-
219
+ [HTML:true]
220
+ <p>a<em>a<span>b</em>ef*</span>c*c</p>
224
221
 
225
222
  [Markdown]
226
223
  a***a<span>b</span>c***c
@@ -235,7 +232,7 @@ a***a<span>b***e</span>cc
235
232
  [HTML:false]
236
233
  <p>a<em><strong>a&lt;span&gt;b</strong></em>e&lt;/span&gt;cc</p>
237
234
  [HTML:true]
238
- <p>a***a<span>b***e</span>cc</p>
235
+ <p>a<em><strong>a<span>b</strong></em>e</span>cc</p>
239
236
 
240
237
  [Markdown]
241
238
  aa<span>b*e<s>f</s>*</span>cc