@peaceroad/markdown-it-strong-ja 0.7.0 → 0.7.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/index.js CHANGED
@@ -3,39 +3,39 @@ import { patchScanDelims } from './src/token-core.js'
3
3
  import { registerTokenCompat } from './src/token-compat.js'
4
4
  import { registerTokenPostprocess } from './src/token-postprocess.js'
5
5
 
6
- const buildNoLinkKey = (opt) => {
6
+ const buildNoLinkCacheKey = (opt) => {
7
7
  const mode = resolveMode(opt)
8
8
  const mditAttrs = opt && opt.mditAttrs === false ? '0' : '1'
9
9
  const mdBreaks = opt && opt.mdBreaks === true ? '1' : '0'
10
10
  return `${mode}|${mditAttrs}|${mdBreaks}`
11
11
  }
12
12
 
13
- const getNoLinkMd = (md, opt) => {
13
+ const getNoLinkMdInstance = (md, opt) => {
14
14
  const baseOpt = opt || md.__strongJaTokenOpt || { mode: 'japanese' }
15
- const key = buildNoLinkKey(baseOpt)
15
+ const key = buildNoLinkCacheKey(baseOpt)
16
16
  if (!md.__strongJaTokenNoLinkCache) {
17
17
  md.__strongJaTokenNoLinkCache = new Map()
18
18
  }
19
19
  const cache = md.__strongJaTokenNoLinkCache
20
20
  if (cache.has(key)) return cache.get(key)
21
21
  const noLink = new md.constructor(md.options)
22
- tokenEngine(noLink, { ...baseOpt, _skipPostprocess: true })
22
+ mditStrongJa(noLink, { ...baseOpt, _skipPostprocess: true })
23
23
  noLink.inline.ruler.disable(['link'])
24
24
  cache.set(key, noLink)
25
25
  return noLink
26
26
  }
27
27
 
28
- const tokenEngine = (md, option) => {
28
+ const mditStrongJa = (md, option) => {
29
29
  if (option && typeof option.engine === 'string' && option.engine !== 'token') {
30
30
  throw new Error('mditStrongJa: legacy engine was removed; use token (default)')
31
31
  }
32
32
  const opt = {
33
- mditAttrs: true,
34
- mdBreaks: md.options.breaks,
35
- mode: 'japanese',
36
- coreRulesBeforePostprocess: [],
37
- postprocess: true,
38
- patchCorePush: true
33
+ mditAttrs: true, // assume markdown-it-attrs integration by default
34
+ mdBreaks: md.options.breaks, // inherit md.options.breaks for compat handling
35
+ mode: 'japanese', // 'japanese' | 'aggressive' | 'compatible' (pairing behavior)
36
+ coreRulesBeforePostprocess: [], // e.g. ['cjk_breaks'] to keep rules ahead of postprocess
37
+ postprocess: true, // enable link/ref reconstruction pass
38
+ patchCorePush: true // keep restore-softbreaks after late cjk_breaks
39
39
  }
40
40
  if (option) Object.assign(opt, option)
41
41
  opt.hasCjkBreaks = hasCjkBreaksRule(md)
@@ -45,7 +45,7 @@ const tokenEngine = (md, option) => {
45
45
  registerTokenCompat(md, opt)
46
46
 
47
47
  if (!opt._skipPostprocess) {
48
- registerTokenPostprocess(md, opt, getNoLinkMd)
48
+ registerTokenPostprocess(md, opt, getNoLinkMdInstance)
49
49
  const rawCoreRules = opt.coreRulesBeforePostprocess
50
50
  const hasCoreRuleConfig = Array.isArray(rawCoreRules)
51
51
  ? rawCoreRules.length > 0
@@ -59,4 +59,4 @@ const tokenEngine = (md, option) => {
59
59
  return md
60
60
  }
61
61
 
62
- export default tokenEngine
62
+ 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.7.0",
4
+ "version": "0.7.1",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "files": [
@@ -43,7 +43,6 @@ const registerTokenCompat = (md, baseOpt) => {
43
43
  md.__strongJaTokenSoftbreakSpacingRegistered = true
44
44
  const normalizeSoftbreakSpacing = (state) => {
45
45
  if (!state) return
46
- const opt = getRuntimeOpt(state, baseOpt)
47
46
  if (baseOpt.hasCjkBreaks !== true && state.md) {
48
47
  baseOpt.hasCjkBreaks = hasCjkBreaksRule(state.md)
49
48
  }
@@ -193,7 +193,7 @@ const fixTailAfterLinkStrongClose = (tokens, md, env) => {
193
193
  return false
194
194
  }
195
195
 
196
- const registerTokenPostprocess = (md, baseOpt, getNoLinkMd) => {
196
+ const registerTokenPostprocess = (md, baseOpt, getNoLinkMdInstance) => {
197
197
  if (md.__strongJaTokenPostprocessRegistered) return
198
198
  md.__strongJaTokenPostprocessRegistered = true
199
199
  md.core.ruler.after('inline', 'strong_ja_token_postprocess', (state) => {
@@ -288,7 +288,7 @@ const registerTokenPostprocess = (md, baseOpt, getNoLinkMd) => {
288
288
  if (shouldReparseSegment(children, brokenRefStart, closeIdx)) {
289
289
  const originalMap = getMapFromTokenRange(children, brokenRefStart, closeIdx)
290
290
  const raw = buildRawFromTokens(children, brokenRefStart, closeIdx)
291
- const noLink = getNoLinkMd(md, opt)
291
+ const noLink = getNoLinkMdInstance(md, opt)
292
292
  const parsed = parseInlineWithFixes(noLink, raw, state.env)
293
293
  if (parsed && parsed.length > 0) {
294
294
  if (originalMap) {