@peaceroad/markdown-it-strong-ja 0.8.0 → 0.9.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 +15 -3
- package/index.js +31 -22
- package/package.json +8 -6
- package/src/token-compat.js +13 -18
- package/src/token-core.js +189 -76
- package/src/token-link-utils.js +386 -193
- package/src/token-postprocess/broken-ref.js +482 -0
- package/src/token-postprocess/guards.js +217 -198
- package/src/token-postprocess/orchestrator.js +295 -385
- package/src/token-utils.js +73 -27
package/src/token-utils.js
CHANGED
|
@@ -8,6 +8,7 @@ const MODE_FLAG_AGGRESSIVE = 1 << 1
|
|
|
8
8
|
const MODE_FLAG_JAPANESE_BASE = 1 << 2
|
|
9
9
|
const MODE_FLAG_JAPANESE_PLUS = 1 << 3
|
|
10
10
|
const MODE_FLAG_JAPANESE_ANY = MODE_FLAG_JAPANESE_BASE | MODE_FLAG_JAPANESE_PLUS
|
|
11
|
+
const HAS_OWN = Object.prototype.hasOwnProperty
|
|
11
12
|
const REG_CJK_BREAKS_RULE_NAME = /(^|[_-])cjk_breaks([_-]|$)/
|
|
12
13
|
const VALID_CANONICAL_MODES = new Set([
|
|
13
14
|
'compatible',
|
|
@@ -34,14 +35,6 @@ const isJapaneseChar = (ch) => {
|
|
|
34
35
|
return REG_JAPANESE.test(String.fromCharCode(code))
|
|
35
36
|
}
|
|
36
37
|
|
|
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
38
|
const hasCjkBreaksRule = (md) => {
|
|
46
39
|
if (!md || !md.core || !md.core.ruler || !Array.isArray(md.core.ruler.__rules__)) return false
|
|
47
40
|
if (md.__strongJaHasCjkBreaks === true) return true
|
|
@@ -108,21 +101,72 @@ const deriveModeInfo = (opt) => {
|
|
|
108
101
|
return opt
|
|
109
102
|
}
|
|
110
103
|
|
|
111
|
-
const
|
|
112
|
-
if (!
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
104
|
+
const deriveOptionInfo = (opt) => {
|
|
105
|
+
if (!opt || typeof opt !== 'object') return opt
|
|
106
|
+
deriveModeInfo(opt)
|
|
107
|
+
const rawPostprocess = opt.postprocess
|
|
108
|
+
const rawCoreRules = opt.coreRulesBeforePostprocess
|
|
109
|
+
if (opt.__strongJaPlanPostprocessRaw === rawPostprocess &&
|
|
110
|
+
opt.__strongJaPlanCoreRulesRaw === rawCoreRules &&
|
|
111
|
+
typeof opt.__strongJaPostprocessActive === 'boolean' &&
|
|
112
|
+
typeof opt.__strongJaIsCompatibleMode === 'boolean' &&
|
|
113
|
+
typeof opt.__strongJaIsJapaneseMode === 'boolean' &&
|
|
114
|
+
typeof opt.__strongJaStrictAsciiCodeGuard === 'boolean' &&
|
|
115
|
+
typeof opt.__strongJaStrictAsciiStrongGuard === 'boolean' &&
|
|
116
|
+
Array.isArray(opt.__strongJaNormalizedCoreRulesBeforePostprocess)) {
|
|
117
|
+
return opt
|
|
118
|
+
}
|
|
119
|
+
opt.__strongJaPlanPostprocessRaw = rawPostprocess
|
|
120
|
+
opt.__strongJaPlanCoreRulesRaw = rawCoreRules
|
|
121
|
+
opt.__strongJaIsCompatibleMode = (opt.__strongJaModeFlags & MODE_FLAG_COMPATIBLE) !== 0
|
|
122
|
+
opt.__strongJaPostprocessActive = rawPostprocess !== false && !opt.__strongJaIsCompatibleMode
|
|
123
|
+
opt.__strongJaIsJapaneseMode = (opt.__strongJaModeFlags & MODE_FLAG_JAPANESE_ANY) !== 0
|
|
124
|
+
opt.__strongJaStrictAsciiCodeGuard = (opt.__strongJaModeFlags & MODE_FLAG_JAPANESE_PLUS) !== 0
|
|
125
|
+
opt.__strongJaStrictAsciiStrongGuard = (opt.__strongJaModeFlags & MODE_FLAG_AGGRESSIVE) === 0
|
|
126
|
+
opt.__strongJaNormalizedCoreRulesBeforePostprocess = normalizeCoreRulesBeforePostprocess(rawCoreRules)
|
|
127
|
+
return opt
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const hasRuntimeOverride = (override) => {
|
|
131
|
+
if (!override || typeof override !== 'object') return false
|
|
132
|
+
return (HAS_OWN.call(override, 'mode') && override.mode !== undefined) ||
|
|
133
|
+
(HAS_OWN.call(override, 'postprocess') && override.postprocess !== undefined)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const getRuntimeOpt = (state, baseOpt) => {
|
|
137
|
+
const override = state && state.env ? state.env.__strongJaTokenOpt : null
|
|
138
|
+
if (!hasRuntimeOverride(override)) return deriveOptionInfo(baseOpt)
|
|
139
|
+
if (state.__strongJaTokenRuntimeOpt &&
|
|
140
|
+
state.__strongJaTokenRuntimeBase === baseOpt &&
|
|
141
|
+
state.__strongJaTokenRuntimeOverride === override) {
|
|
142
|
+
return state.__strongJaTokenRuntimeOpt
|
|
143
|
+
}
|
|
144
|
+
const merged = baseOpt && typeof baseOpt === 'object' ? { ...baseOpt } : {}
|
|
145
|
+
if (HAS_OWN.call(override, 'mode') && override.mode !== undefined) merged.mode = override.mode
|
|
146
|
+
if (HAS_OWN.call(override, 'postprocess') && override.postprocess !== undefined) merged.postprocess = override.postprocess
|
|
147
|
+
state.__strongJaTokenRuntimeOpt = deriveOptionInfo(merged)
|
|
148
|
+
state.__strongJaTokenRuntimeBase = baseOpt
|
|
149
|
+
state.__strongJaTokenRuntimeOverride = override
|
|
150
|
+
return state.__strongJaTokenRuntimeOpt
|
|
151
|
+
}
|
|
125
152
|
|
|
153
|
+
const getReferenceCount = (state) => {
|
|
154
|
+
if (!state) return 0
|
|
155
|
+
let referenceCount = state.__strongJaReferenceCount
|
|
156
|
+
if (referenceCount !== undefined) return referenceCount
|
|
157
|
+
const references = state.env && state.env.references
|
|
158
|
+
if (!references) {
|
|
159
|
+
state.__strongJaReferenceCount = 0
|
|
160
|
+
return 0
|
|
161
|
+
}
|
|
162
|
+
referenceCount = 0
|
|
163
|
+
for (const key in references) {
|
|
164
|
+
if (HAS_OWN.call(references, key)) referenceCount++
|
|
165
|
+
}
|
|
166
|
+
state.__strongJaReferenceCount = referenceCount
|
|
167
|
+
return referenceCount
|
|
168
|
+
}
|
|
169
|
+
|
|
126
170
|
function normalizeCoreRulesBeforePostprocess(value) {
|
|
127
171
|
if (!value) return []
|
|
128
172
|
const list = Array.isArray(value) ? value : [value]
|
|
@@ -191,18 +235,20 @@ export {
|
|
|
191
235
|
CHAR_IDEOGRAPHIC_SPACE,
|
|
192
236
|
REG_ATTRS,
|
|
193
237
|
isJapaneseChar,
|
|
194
|
-
getInlineWrapperBase,
|
|
195
238
|
hasCjkBreaksRule,
|
|
196
239
|
isCjkBreaksRuleName,
|
|
197
240
|
resolveMode,
|
|
198
241
|
getModeFlags,
|
|
199
|
-
deriveModeInfo,
|
|
200
|
-
|
|
242
|
+
deriveModeInfo,
|
|
243
|
+
deriveOptionInfo,
|
|
244
|
+
hasRuntimeOverride,
|
|
245
|
+
MODE_FLAG_COMPATIBLE,
|
|
201
246
|
MODE_FLAG_AGGRESSIVE,
|
|
202
247
|
MODE_FLAG_JAPANESE_BASE,
|
|
203
248
|
MODE_FLAG_JAPANESE_PLUS,
|
|
204
|
-
MODE_FLAG_JAPANESE_ANY,
|
|
205
|
-
getRuntimeOpt,
|
|
249
|
+
MODE_FLAG_JAPANESE_ANY,
|
|
250
|
+
getRuntimeOpt,
|
|
251
|
+
getReferenceCount,
|
|
206
252
|
normalizeCoreRulesBeforePostprocess,
|
|
207
253
|
ensureCoreRuleOrder,
|
|
208
254
|
moveRuleBefore,
|