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

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/index.js CHANGED
@@ -85,32 +85,39 @@ const hasNextSymbol = (state, n, max, symbol, noMark) => {
85
85
  while (i < max) {
86
86
  tempNoMark += state.src[i]
87
87
  if (state.src.charCodeAt(i) === symbol && !hasBackslash(state, i)) {
88
- noMark += state.src[n]
88
+ noMark += state.src.substring(n, i + 1)
89
89
  nextSymbolPos = i
90
90
  break
91
91
  }
92
92
  i++
93
93
  }
94
94
  }
95
- return nextSymbolPos
95
+ return [nextSymbolPos, noMark]
96
96
  }
97
97
 
98
98
  const createInlines = (state, start, max, opt) => {
99
99
  let n = start
100
100
  let inlines = []
101
101
  let noMark = ''
102
- let isInStartMark = true
103
102
  let textStart = n
104
-
105
103
  while (n < max) {
106
- let nextSymbolPos = hasNextSymbol(state, n, max, 0x60, noMark) // '`'
104
+ let nextSymbolPos = -1;
105
+ [nextSymbolPos, noMark] = hasNextSymbol(state, n, max, 0x60, noMark) // '`'
107
106
  if (nextSymbolPos !== -1) {
107
+ if (nextSymbolPos === max - 1) {
108
+ inlinesPush(inlines, textStart, nextSymbolPos, nextSymbolPos - textStart + 1, 'text')
109
+ break
110
+ }
108
111
  n = nextSymbolPos + 1
109
112
  continue
110
113
  }
111
114
  if (opt.dollarMath) {
112
- nextSymbolPos = hasNextSymbol(state, n, max, 0x24, noMark) // '$'
115
+ [nextSymbolPos, noMark] = hasNextSymbol(state, n, max, 0x24, noMark) // '$'
113
116
  if (nextSymbolPos !== -1) {
117
+ if (nextSymbolPos === max - 1) {
118
+ inlinesPush(inlines, textStart, nextSymbolPos, nextSymbolPos - textStart + 1, 'text')
119
+ break
120
+ }
114
121
  n = nextSymbolPos + 1
115
122
  continue
116
123
  }
@@ -142,9 +149,8 @@ const createInlines = (state, start, max, opt) => {
142
149
  continue
143
150
  }
144
151
  }
145
-
146
152
  if (state.src.charCodeAt(n) === 0x2A && !hasBackslash(state, n)) { // '*'
147
- if (!isInStartMark) {
153
+ if (n !== 0) {
148
154
  inlinesPush(inlines, textStart, n - 1, n - textStart, 'text')
149
155
  }
150
156
  if (n === max - 1) {
@@ -165,10 +171,8 @@ const createInlines = (state, start, max, opt) => {
165
171
  n = i
166
172
  continue
167
173
  }
168
- isInStartMark = false
169
174
  noMark += state.src[n]
170
- //console.log('noMark: ' + noMark)
171
- if (n === max - 1 || max < 3) {
175
+ if (n === max - 1) {
172
176
  inlinesPush(inlines, textStart, n, n - textStart + 1, 'text')
173
177
  break
174
178
  }
@@ -482,11 +486,8 @@ const strongJa = (state, silent, opt) => {
482
486
  if (silent) return false
483
487
  const start = state.pos
484
488
  let max = state.posMax
485
- const hasCurlyAttributes = state.md.core.ruler.__rules__.filter(rule => {
486
- rule.name === 'curly_attributes' // markdown-it-attrs
487
- })
488
489
  let attributesSrc
489
- if (hasCurlyAttributes) {
490
+ if (opt.hasCurlyAttributes) {
490
491
  attributesSrc = state.src.match(/( *){.*?}$/)
491
492
  if (attributesSrc) {
492
493
  max = state.src.slice(0, attributesSrc.index).length
@@ -536,7 +537,11 @@ const strongJa = (state, silent, opt) => {
536
537
  const mditStrongJa = (md, option) => {
537
538
  const opt = {
538
539
  dollarMath: true,
540
+ hasCurlyAttributes: false,
539
541
  }
542
+ opt.hasCurlyAttributes = md.core.ruler.__rules__.filter(rule => {
543
+ rule.name === 'curly_attributes' // markdown-it-attrs
544
+ })
540
545
  if (option !== undefined) {
541
546
  for (let o in option) {
542
547
  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.4",
4
+ "version": "0.3.5",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
@@ -336,3 +336,31 @@ b<span>c</span>*
336
336
  <p>*<em><em><span>a</span></em>b</em></p>
337
337
 
338
338
 
339
+ [Markdown]
340
+ *`a`*
341
+ [HTML]
342
+ <p><em><code>a</code></em></p>
343
+
344
+ [Markdown]
345
+ **z`a`b**
346
+ [HTML]
347
+ <p><strong>z<code>a</code>b</strong></p>
348
+
349
+ [Markdown]
350
+ **`a`
351
+ [HTML]
352
+ <p>**<code>a</code></p>
353
+
354
+ [Markdown]
355
+ **<b>a</b>**
356
+ [HTML:false]
357
+ <p><strong>&lt;b&gt;a&lt;/b&gt;</strong></p>
358
+ [HTML:true]
359
+ <p><strong><b>a</b></strong></p>
360
+
361
+ [Markdown]
362
+ **<br>
363
+ [HTML:false]
364
+ <p>**&lt;br&gt;</p>
365
+ [HTML:true]
366
+ <p>**<br></p>
package/test/test.js CHANGED
@@ -15,7 +15,7 @@ const check = (ms, example) => {
15
15
  let n = 1
16
16
  while (n < ms.length) {
17
17
  //if (n !== 23 ) { n++; continue }
18
- //if (n !== 36 ) { n++; continue }
18
+ //if (n !== 59 ) { n++; continue }
19
19
  const m = ms[n].markdown
20
20
  console.log('Test [' + n + ', HTML: false] >>>')
21
21
  const h = md.render(m)