@peaceroad/markdown-it-strong-ja 0.8.0 → 0.8.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.
@@ -34,14 +34,6 @@ const isJapaneseChar = (ch) => {
34
34
  return REG_JAPANESE.test(String.fromCharCode(code))
35
35
  }
36
36
 
37
- const getInlineWrapperBase = (type) => {
38
- if (!type || typeof type !== 'string') return ''
39
- if (type === 'link_open' || type === 'link_close') return ''
40
- if (type.endsWith('_open')) return type.slice(0, -5)
41
- if (type.endsWith('_close')) return type.slice(0, -6)
42
- return ''
43
- }
44
-
45
37
  const hasCjkBreaksRule = (md) => {
46
38
  if (!md || !md.core || !md.core.ruler || !Array.isArray(md.core.ruler.__rules__)) return false
47
39
  if (md.__strongJaHasCjkBreaks === true) return true
@@ -108,8 +100,34 @@ const deriveModeInfo = (opt) => {
108
100
  return opt
109
101
  }
110
102
 
103
+ const deriveOptionInfo = (opt) => {
104
+ if (!opt || typeof opt !== 'object') return opt
105
+ deriveModeInfo(opt)
106
+ const rawPostprocess = opt.postprocess
107
+ const rawCoreRules = opt.coreRulesBeforePostprocess
108
+ if (opt.__strongJaPlanPostprocessRaw === rawPostprocess &&
109
+ opt.__strongJaPlanCoreRulesRaw === rawCoreRules &&
110
+ typeof opt.__strongJaPostprocessActive === 'boolean' &&
111
+ typeof opt.__strongJaIsCompatibleMode === 'boolean' &&
112
+ typeof opt.__strongJaIsJapaneseMode === 'boolean' &&
113
+ typeof opt.__strongJaStrictAsciiCodeGuard === 'boolean' &&
114
+ typeof opt.__strongJaStrictAsciiStrongGuard === 'boolean' &&
115
+ Array.isArray(opt.__strongJaNormalizedCoreRulesBeforePostprocess)) {
116
+ return opt
117
+ }
118
+ opt.__strongJaPlanPostprocessRaw = rawPostprocess
119
+ opt.__strongJaPlanCoreRulesRaw = rawCoreRules
120
+ opt.__strongJaIsCompatibleMode = (opt.__strongJaModeFlags & MODE_FLAG_COMPATIBLE) !== 0
121
+ opt.__strongJaPostprocessActive = rawPostprocess !== false && !opt.__strongJaIsCompatibleMode
122
+ opt.__strongJaIsJapaneseMode = (opt.__strongJaModeFlags & MODE_FLAG_JAPANESE_ANY) !== 0
123
+ opt.__strongJaStrictAsciiCodeGuard = (opt.__strongJaModeFlags & MODE_FLAG_JAPANESE_PLUS) !== 0
124
+ opt.__strongJaStrictAsciiStrongGuard = (opt.__strongJaModeFlags & MODE_FLAG_AGGRESSIVE) === 0
125
+ opt.__strongJaNormalizedCoreRulesBeforePostprocess = normalizeCoreRulesBeforePostprocess(rawCoreRules)
126
+ return opt
127
+ }
128
+
111
129
  const getRuntimeOpt = (state, baseOpt) => {
112
- if (!state || !state.env || !state.env.__strongJaTokenOpt) return deriveModeInfo(baseOpt)
130
+ if (!state || !state.env || !state.env.__strongJaTokenOpt) return deriveOptionInfo(baseOpt)
113
131
  const override = state.env.__strongJaTokenOpt
114
132
  if (state.__strongJaTokenRuntimeOpt &&
115
133
  state.__strongJaTokenRuntimeBase === baseOpt &&
@@ -117,12 +135,22 @@ const getRuntimeOpt = (state, baseOpt) => {
117
135
  return state.__strongJaTokenRuntimeOpt
118
136
  }
119
137
  const merged = { ...baseOpt, ...override }
120
- state.__strongJaTokenRuntimeOpt = deriveModeInfo(merged)
138
+ state.__strongJaTokenRuntimeOpt = deriveOptionInfo(merged)
121
139
  state.__strongJaTokenRuntimeBase = baseOpt
122
140
  state.__strongJaTokenRuntimeOverride = override
123
141
  return state.__strongJaTokenRuntimeOpt
124
142
  }
125
143
 
144
+ const getReferenceCount = (state) => {
145
+ if (!state) return 0
146
+ let referenceCount = state.__strongJaReferenceCount
147
+ if (referenceCount !== undefined) return referenceCount
148
+ const references = state.env && state.env.references
149
+ referenceCount = references ? Object.keys(references).length : 0
150
+ state.__strongJaReferenceCount = referenceCount
151
+ return referenceCount
152
+ }
153
+
126
154
  function normalizeCoreRulesBeforePostprocess(value) {
127
155
  if (!value) return []
128
156
  const list = Array.isArray(value) ? value : [value]
@@ -191,18 +219,19 @@ export {
191
219
  CHAR_IDEOGRAPHIC_SPACE,
192
220
  REG_ATTRS,
193
221
  isJapaneseChar,
194
- getInlineWrapperBase,
195
222
  hasCjkBreaksRule,
196
223
  isCjkBreaksRuleName,
197
224
  resolveMode,
198
225
  getModeFlags,
199
226
  deriveModeInfo,
227
+ deriveOptionInfo,
200
228
  MODE_FLAG_COMPATIBLE,
201
229
  MODE_FLAG_AGGRESSIVE,
202
230
  MODE_FLAG_JAPANESE_BASE,
203
231
  MODE_FLAG_JAPANESE_PLUS,
204
- MODE_FLAG_JAPANESE_ANY,
205
- getRuntimeOpt,
232
+ MODE_FLAG_JAPANESE_ANY,
233
+ getRuntimeOpt,
234
+ getReferenceCount,
206
235
  normalizeCoreRulesBeforePostprocess,
207
236
  ensureCoreRuleOrder,
208
237
  moveRuleBefore,