polytypo 1.22.1 → 1.23.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/dist/chunk-244KRDWN.cjs +34 -0
- package/dist/{chunk-UNXIWWE7.cjs.map → chunk-244KRDWN.cjs.map} +1 -1
- package/dist/chunk-2XOMOXCW.cjs +38 -0
- package/dist/{chunk-OEKUKIMI.cjs.map → chunk-2XOMOXCW.cjs.map} +1 -1
- package/dist/{chunk-2QD7JARJ.js → chunk-4ZRAFD6S.js} +3 -3
- package/dist/{chunk-PREUPLPO.js → chunk-6242RKS3.js} +108 -6
- package/dist/chunk-6242RKS3.js.map +1 -0
- package/dist/{chunk-BF6OL3QM.cjs → chunk-6MZWJX7B.cjs} +110 -8
- package/dist/chunk-6MZWJX7B.cjs.map +1 -0
- package/dist/{chunk-PRG3GQNV.js → chunk-6Q3KRZQ5.js} +4 -4
- package/dist/{chunk-N2QFEDI2.js → chunk-75YYV3FW.js} +3 -3
- package/dist/chunk-CVJVASBB.cjs +36 -0
- package/dist/{chunk-FSDQXTM5.cjs.map → chunk-CVJVASBB.cjs.map} +1 -1
- package/dist/{chunk-MEVOJV7I.js → chunk-FLLMLWN5.js} +2 -2
- package/dist/{chunk-PLDK525W.cjs → chunk-GL273L36.cjs} +6 -6
- package/dist/{chunk-PLDK525W.cjs.map → chunk-GL273L36.cjs.map} +1 -1
- package/dist/{chunk-6S7AKBQZ.cjs → chunk-JTYWNFN4.cjs} +3 -3
- package/dist/{chunk-6S7AKBQZ.cjs.map → chunk-JTYWNFN4.cjs.map} +1 -1
- package/dist/{chunk-JWOUHTOD.cjs → chunk-QDLVXAHK.cjs} +1 -1
- package/dist/{chunk-JWOUHTOD.cjs.map → chunk-QDLVXAHK.cjs.map} +1 -1
- package/dist/{chunk-44KKUSOQ.js → chunk-QTUPLKGX.js} +2 -2
- package/dist/{chunk-IQ7T2HFZ.js → chunk-SLAQTVNN.js} +2 -2
- package/dist/{chunk-D6CWTH54.js → chunk-YXUADCFN.js} +1 -1
- package/dist/{chunk-D6CWTH54.js.map → chunk-YXUADCFN.js.map} +1 -1
- package/dist/{chunk-OY3D5CRP.cjs → chunk-ZAYI4P5G.cjs} +23 -23
- package/dist/{chunk-OY3D5CRP.cjs.map → chunk-ZAYI4P5G.cjs.map} +1 -1
- package/dist/html.cjs +9 -9
- package/dist/html.js +4 -4
- package/dist/index.cjs +17 -17
- package/dist/index.js +7 -7
- package/dist/markdown.cjs +10 -10
- package/dist/markdown.js +5 -5
- package/dist/text.cjs +8 -8
- package/dist/text.js +3 -3
- package/dist/yaml.cjs +9 -9
- package/dist/yaml.js +4 -4
- package/package.json +1 -1
- package/dist/chunk-BF6OL3QM.cjs.map +0 -1
- package/dist/chunk-FSDQXTM5.cjs +0 -36
- package/dist/chunk-OEKUKIMI.cjs +0 -38
- package/dist/chunk-PREUPLPO.js.map +0 -1
- package/dist/chunk-UNXIWWE7.cjs +0 -34
- /package/dist/{chunk-2QD7JARJ.js.map → chunk-4ZRAFD6S.js.map} +0 -0
- /package/dist/{chunk-PRG3GQNV.js.map → chunk-6Q3KRZQ5.js.map} +0 -0
- /package/dist/{chunk-N2QFEDI2.js.map → chunk-75YYV3FW.js.map} +0 -0
- /package/dist/{chunk-MEVOJV7I.js.map → chunk-FLLMLWN5.js.map} +0 -0
- /package/dist/{chunk-44KKUSOQ.js.map → chunk-QTUPLKGX.js.map} +0 -0
- /package/dist/{chunk-IQ7T2HFZ.js.map → chunk-SLAQTVNN.js.map} +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk6MZWJX7Bcjs = require('./chunk-6MZWJX7B.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkQDLVXAHKcjs = require('./chunk-QDLVXAHK.cjs');
|
|
12
|
+
|
|
13
|
+
// src/engine/html-pipeline.ts
|
|
14
|
+
function runHtmlPipeline(input, options) {
|
|
15
|
+
const narrowTarget = _chunkQDLVXAHKcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
16
|
+
const planned = _chunkQDLVXAHKcjs.planRules.call(void 0, options.rules);
|
|
17
|
+
const locale = _chunkQDLVXAHKcjs.getLocaleData.call(void 0, options.locale);
|
|
18
|
+
_chunkQDLVXAHKcjs.assertNoProtect.call(void 0, options.protect, "html");
|
|
19
|
+
const spans = _chunk6MZWJX7Bcjs.htmlSpans.call(void 0, input);
|
|
20
|
+
return _chunkQDLVXAHKcjs.runOverSpans.call(void 0, input, spans, planned, locale, "html", narrowTarget);
|
|
21
|
+
}
|
|
22
|
+
function analyzeHtmlPipeline(input, options) {
|
|
23
|
+
const narrowTarget = _chunkQDLVXAHKcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
24
|
+
const planned = _chunkQDLVXAHKcjs.planRules.call(void 0, options.rules);
|
|
25
|
+
const locale = _chunkQDLVXAHKcjs.getLocaleData.call(void 0, options.locale);
|
|
26
|
+
_chunkQDLVXAHKcjs.assertNoProtect.call(void 0, options.protect, "html");
|
|
27
|
+
return _chunkQDLVXAHKcjs.analyzeOverSpans.call(void 0, input, _chunk6MZWJX7Bcjs.htmlSpans.call(void 0, input), planned, locale, "html", narrowTarget);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
exports.runHtmlPipeline = runHtmlPipeline; exports.analyzeHtmlPipeline = analyzeHtmlPipeline;
|
|
34
|
+
//# sourceMappingURL=chunk-244KRDWN.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-244KRDWN.cjs","../src/engine/html-pipeline.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACMO,SAAS,eAAA,CAAgB,KAAA,EAAe,OAAA,EAAmC;AAChF,EAAA,MAAM,aAAA,EAAe,mDAAA,OAAoB,CAAQ,UAAU,CAAA;AAC3D,EAAA,MAAM,QAAA,EAAU,yCAAA,OAAU,CAAQ,KAAK,CAAA;AACvC,EAAA,MAAM,OAAA,EAAS,6CAAA,OAAc,CAAQ,MAAM,CAAA;AAC3C,EAAA,+CAAA,OAAgB,CAAQ,OAAA,EAAS,MAAM,CAAA;AACvC,EAAA,MAAM,MAAA,EAAQ,yCAAA,KAAe,CAAA;AAC7B,EAAA,OAAO,4CAAA,KAAa,EAAO,KAAA,EAAO,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAQ,YAAY,CAAA;AACzE;AAGO,SAAS,mBAAA,CAAoB,KAAA,EAAe,OAAA,EAAqC;AACtF,EAAA,MAAM,aAAA,EAAe,mDAAA,OAAoB,CAAQ,UAAU,CAAA;AAC3D,EAAA,MAAM,QAAA,EAAU,yCAAA,OAAU,CAAQ,KAAK,CAAA;AACvC,EAAA,MAAM,OAAA,EAAS,6CAAA,OAAc,CAAQ,MAAM,CAAA;AAC3C,EAAA,+CAAA,OAAgB,CAAQ,OAAA,EAAS,MAAM,CAAA;AACvC,EAAA,OAAO,gDAAA,KAAiB,EAAO,yCAAA,KAAe,CAAA,EAAG,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAQ,YAAY,CAAA;AACxF;ADNA;AACA;AACE;AACA;AACF,6FAAC","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-244KRDWN.cjs","sourcesContent":[null,"import { htmlSpans } from \"../modes/html.js\";\nimport type { Options } from \"../types.js\";\nimport { getLocaleData } from \"./locale.js\";\nimport { resolveNarrowTarget } from \"./narrow-target.js\";\nimport { assertNoProtect } from \"./protect.js\";\nimport { planRules } from \"./rule-runner.js\";\nimport { analyzeOverSpans, runOverSpans } from \"./span-runner.js\";\nimport type { Change } from \"./origin.js\";\n\n/**\n * `html` mode only. Imports `parse5` (via `../modes/html.js`) and nothing from\n * `../modes/markdown.js` or the Micromark/MDX stack — this is what makes `polytypo/html`'s\n * module graph exclude the Markdown parser (AUDIT_REMEDIATION_AND_RELEASE_PLAN.md 5.1).\n *\n * Validation order — `planRules` before `getLocaleData` before parsing — mirrors the pre-Stage-5\n * aggregate `runPipeline` exactly (an unknown-rule error must win over an unknown-locale error,\n * and both must win over a parse failure, since that is public, tested behaviour).\n */\nexport function runHtmlPipeline(input: string, options: Partial<Options>): string {\n const narrowTarget = resolveNarrowTarget(options.narrowNbsp);\n const planned = planRules(options.rules);\n const locale = getLocaleData(options.locale);\n assertNoProtect(options.protect, \"html\");\n const spans = htmlSpans(input);\n return runOverSpans(input, spans, planned, locale, \"html\", narrowTarget);\n}\n\n/** analyze.md §1, `html` mode: offsets are into the document, not into a span (analyze.md §6). */\nexport function analyzeHtmlPipeline(input: string, options: Partial<Options>): Change[] {\n const narrowTarget = resolveNarrowTarget(options.narrowNbsp);\n const planned = planRules(options.rules);\n const locale = getLocaleData(options.locale);\n assertNoProtect(options.protect, \"html\");\n return analyzeOverSpans(input, htmlSpans(input), planned, locale, \"html\", narrowTarget);\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkQDLVXAHKcjs = require('./chunk-QDLVXAHK.cjs');
|
|
13
|
+
|
|
14
|
+
// src/engine/text-pipeline.ts
|
|
15
|
+
function runTextPipeline(input, options) {
|
|
16
|
+
const narrowTarget = _chunkQDLVXAHKcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
17
|
+
const planned = _chunkQDLVXAHKcjs.planRules.call(void 0, options.rules);
|
|
18
|
+
const locale = _chunkQDLVXAHKcjs.getLocaleData.call(void 0, options.locale);
|
|
19
|
+
const holes = _chunkQDLVXAHKcjs.resolveProtect.call(void 0, options.protect, _chunkQDLVXAHKcjs.toCodePoints.call(void 0, input).length);
|
|
20
|
+
if (holes.length > 0) return _chunkQDLVXAHKcjs.runProtected.call(void 0, input, holes, planned, locale, narrowTarget);
|
|
21
|
+
return _chunkQDLVXAHKcjs.fromCodePoints.call(void 0, _chunkQDLVXAHKcjs.runRules.call(void 0, _chunkQDLVXAHKcjs.toCodePoints.call(void 0, input), planned, locale, "text", narrowTarget));
|
|
22
|
+
}
|
|
23
|
+
function analyzeTextPipeline(input, options) {
|
|
24
|
+
const narrowTarget = _chunkQDLVXAHKcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
25
|
+
const planned = _chunkQDLVXAHKcjs.planRules.call(void 0, options.rules);
|
|
26
|
+
const locale = _chunkQDLVXAHKcjs.getLocaleData.call(void 0, options.locale);
|
|
27
|
+
const cp = _chunkQDLVXAHKcjs.toCodePoints.call(void 0, input);
|
|
28
|
+
const holes = _chunkQDLVXAHKcjs.resolveProtect.call(void 0, options.protect, cp.length);
|
|
29
|
+
if (holes.length > 0) return _chunkQDLVXAHKcjs.analyzeProtected.call(void 0, input, holes, planned, locale, narrowTarget);
|
|
30
|
+
const origin = cp.map((_value, index) => index);
|
|
31
|
+
return _chunkQDLVXAHKcjs.runRulesRecording.call(void 0, cp, planned, locale, "text", narrowTarget, origin, cp.length);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
exports.runTextPipeline = runTextPipeline; exports.analyzeTextPipeline = analyzeTextPipeline;
|
|
38
|
+
//# sourceMappingURL=chunk-2XOMOXCW.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-
|
|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AO,gDAAA,KAAiB,EAAO,KAAA,EAAO,OAAA,EAAS,MAAA,EAAQ,YAAY,CAAA;AACzF,EAAA,MAAM,OAAA,EAAS,EAAA,CAAG,GAAA,CAAI,CAAC,MAAA,EAAQ,KAAA,EAAA,GAAU,KAAK,CAAA;AAC9C,EAAA,OAAO,iDAAA,EAAkB,EAAI,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAQ,YAAA,EAAc,MAAA,EAAQ,EAAA,CAAG,MAAM,CAAA;AACvF;ADNA;AACA;AACE;AACA;AACF,6FAAC","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-2XOMOXCW.cjs","sourcesContent":[null,"import type { Options } from \"../types.js\";\nimport { fromCodePoints, toCodePoints } from \"./codepoints.js\";\nimport type { Change } from \"./origin.js\";\nimport { getLocaleData } from \"./locale.js\";\nimport { resolveNarrowTarget } from \"./narrow-target.js\";\nimport { planRules, runRules, runRulesRecording } from \"./rule-runner.js\";\nimport { analyzeProtected, resolveProtect, runProtected } from \"./protect.js\";\n\n/**\n * `text` mode only. Deliberately imports nothing from `../modes/html.js` or\n * `../modes/markdown.js` (or their parser dependencies) — this is what makes `polytypo/text`'s\n * module graph exclude `parse5` and the Micromark stack (AUDIT_REMEDIATION_AND_RELEASE_PLAN.md\n * 5.1).\n *\n * Validation order — `planRules` before `getLocaleData` — mirrors the pre-Stage-5 aggregate\n * `runPipeline` exactly (an unknown-rule error must win over an unknown-locale error when both\n * are present, since that is public, tested behaviour, not an implementation detail this\n * refactor was authorised to change).\n */\nexport function runTextPipeline(input: string, options: Partial<Options>): string {\n const narrowTarget = resolveNarrowTarget(options.narrowNbsp);\n const planned = planRules(options.rules);\n const locale = getLocaleData(options.locale);\n const holes = resolveProtect(options.protect, toCodePoints(input).length);\n if (holes.length > 0) return runProtected(input, holes, planned, locale, narrowTarget);\n return fromCodePoints(runRules(toCodePoints(input), planned, locale, \"text\", narrowTarget));\n}\n\n/** analyze.md §1: the same pipeline as `runTextPipeline`, reporting instead of applying. */\nexport function analyzeTextPipeline(input: string, options: Partial<Options>): Change[] {\n const narrowTarget = resolveNarrowTarget(options.narrowNbsp);\n const planned = planRules(options.rules);\n const locale = getLocaleData(options.locale);\n const cp = toCodePoints(input);\n const holes = resolveProtect(options.protect, cp.length);\n if (holes.length > 0) return analyzeProtected(input, holes, planned, locale, narrowTarget);\n const origin = cp.map((_value, index) => index);\n return runRulesRecording(cp, planned, locale, \"text\", narrowTarget, origin, cp.length);\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveYamlKeys,
|
|
3
3
|
yamlSpans
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-SLAQTVNN.js";
|
|
5
5
|
import {
|
|
6
6
|
analyzeOverSpans,
|
|
7
7
|
assertNoProtect,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
planRules,
|
|
10
10
|
resolveNarrowTarget,
|
|
11
11
|
runOverSpans
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-YXUADCFN.js";
|
|
13
13
|
|
|
14
14
|
// src/engine/yaml-pipeline.ts
|
|
15
15
|
function runYamlPipeline(input, options) {
|
|
@@ -33,4 +33,4 @@ export {
|
|
|
33
33
|
runYamlPipeline,
|
|
34
34
|
analyzeYamlPipeline
|
|
35
35
|
};
|
|
36
|
-
//# sourceMappingURL=chunk-
|
|
36
|
+
//# sourceMappingURL=chunk-4ZRAFD6S.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PolytypoError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YXUADCFN.js";
|
|
4
4
|
|
|
5
5
|
// src/modes/html.ts
|
|
6
6
|
import { parse, parseFragment } from "parse5";
|
|
@@ -104,12 +104,113 @@ function splitCharacterReferences(source, start, end) {
|
|
|
104
104
|
function isParent(node) {
|
|
105
105
|
return "childNodes" in node;
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function isLineBreakWhitespace(source, start, end) {
|
|
108
|
+
let hasLineBreak = false;
|
|
109
|
+
for (let i = start; i < end; i += 1) {
|
|
110
|
+
const c = source.charCodeAt(i);
|
|
111
|
+
if (c === 10 || c === 12 || c === 13) hasLineBreak = true;
|
|
112
|
+
else if (c !== 9 && c !== 32) return false;
|
|
113
|
+
}
|
|
114
|
+
return hasLineBreak;
|
|
115
|
+
}
|
|
116
|
+
var LESS_THAN = 60;
|
|
117
|
+
var SOLIDUS = 47;
|
|
118
|
+
var GREATER_THAN = 62;
|
|
119
|
+
var EQUALS = 61;
|
|
120
|
+
function isAsciiAlpha(unit) {
|
|
121
|
+
return unit >= 65 && unit <= 90 || unit >= 97 && unit <= 122;
|
|
122
|
+
}
|
|
123
|
+
function isTagSpace(unit) {
|
|
124
|
+
return unit === 9 || unit === 10 || unit === 12 || unit === 13 || unit === 32;
|
|
125
|
+
}
|
|
126
|
+
function tagEnd(source, at, limit) {
|
|
127
|
+
if (source.charCodeAt(at) !== LESS_THAN) return -1;
|
|
128
|
+
let i = at + 1;
|
|
129
|
+
if (i >= limit) return -1;
|
|
130
|
+
if (source.charCodeAt(i) === SOLIDUS) {
|
|
131
|
+
i += 1;
|
|
132
|
+
if (i >= limit) return -1;
|
|
133
|
+
if (source.charCodeAt(i) === GREATER_THAN) return i + 1;
|
|
134
|
+
}
|
|
135
|
+
if (!isAsciiAlpha(source.charCodeAt(i))) return -1;
|
|
136
|
+
while (i < limit) {
|
|
137
|
+
const c = source.charCodeAt(i);
|
|
138
|
+
if (isTagSpace(c) || c === SOLIDUS || c === GREATER_THAN) break;
|
|
139
|
+
i += 1;
|
|
140
|
+
}
|
|
141
|
+
while (i < limit) {
|
|
142
|
+
let c = source.charCodeAt(i);
|
|
143
|
+
if (isTagSpace(c) || c === SOLIDUS) {
|
|
144
|
+
i += 1;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (c === GREATER_THAN) return i + 1;
|
|
148
|
+
i += 1;
|
|
149
|
+
while (i < limit) {
|
|
150
|
+
c = source.charCodeAt(i);
|
|
151
|
+
if (isTagSpace(c) || c === SOLIDUS || c === GREATER_THAN || c === EQUALS) break;
|
|
152
|
+
i += 1;
|
|
153
|
+
}
|
|
154
|
+
while (i < limit && isTagSpace(source.charCodeAt(i))) i += 1;
|
|
155
|
+
if (i >= limit) return -1;
|
|
156
|
+
c = source.charCodeAt(i);
|
|
157
|
+
if (c === GREATER_THAN) return i + 1;
|
|
158
|
+
if (c !== EQUALS) continue;
|
|
159
|
+
i += 1;
|
|
160
|
+
while (i < limit && isTagSpace(source.charCodeAt(i))) i += 1;
|
|
161
|
+
if (i >= limit) return -1;
|
|
162
|
+
c = source.charCodeAt(i);
|
|
163
|
+
if (c === GREATER_THAN) return i + 1;
|
|
164
|
+
if (c === 34 || c === 39) {
|
|
165
|
+
const close = source.indexOf(c === 34 ? '"' : "'", i + 1);
|
|
166
|
+
if (close === -1 || close >= limit) return -1;
|
|
167
|
+
i = close + 1;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
while (i < limit) {
|
|
171
|
+
c = source.charCodeAt(i);
|
|
172
|
+
if (isTagSpace(c) || c === GREATER_THAN) break;
|
|
173
|
+
i += 1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return -1;
|
|
177
|
+
}
|
|
178
|
+
function textPieces(source, start, end) {
|
|
179
|
+
const pieces = [];
|
|
180
|
+
let cursor = start;
|
|
181
|
+
let i = start;
|
|
182
|
+
while (i < end) {
|
|
183
|
+
if (source.charCodeAt(i) === LESS_THAN) {
|
|
184
|
+
const stop = tagEnd(source, i, end);
|
|
185
|
+
if (stop > 0) {
|
|
186
|
+
if (i > cursor) pieces.push([cursor, i]);
|
|
187
|
+
cursor = stop;
|
|
188
|
+
i = stop;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
i += 1;
|
|
193
|
+
}
|
|
194
|
+
if (end > cursor) pieces.push([cursor, end]);
|
|
195
|
+
return pieces;
|
|
196
|
+
}
|
|
197
|
+
var TEXT_ONLY_PARENTS = /* @__PURE__ */ new Set([
|
|
198
|
+
"title",
|
|
199
|
+
"xmp",
|
|
200
|
+
"iframe",
|
|
201
|
+
"noembed",
|
|
202
|
+
"noframes",
|
|
203
|
+
"noscript",
|
|
204
|
+
"plaintext"
|
|
205
|
+
]);
|
|
206
|
+
function collect(node, source, spans, isTextOnly = false) {
|
|
108
207
|
if (node.nodeName === "#text") {
|
|
109
208
|
const location = node.sourceCodeLocation;
|
|
110
209
|
if (location === void 0 || location === null) return;
|
|
111
|
-
|
|
112
|
-
|
|
210
|
+
const pieces = isTextOnly ? [[location.startOffset, location.endOffset]] : textPieces(source, location.startOffset, location.endOffset);
|
|
211
|
+
for (const [from, to] of pieces) {
|
|
212
|
+
if (isLineBreakWhitespace(source, from, to)) continue;
|
|
213
|
+
for (const span of splitCharacterReferences(source, from, to)) spans.push(span);
|
|
113
214
|
}
|
|
114
215
|
return;
|
|
115
216
|
}
|
|
@@ -120,7 +221,8 @@ function collect(node, source, spans) {
|
|
|
120
221
|
return;
|
|
121
222
|
}
|
|
122
223
|
if (!isParent(node)) return;
|
|
123
|
-
|
|
224
|
+
const textOnly = "tagName" in node && TEXT_ONLY_PARENTS.has(node.tagName);
|
|
225
|
+
for (const child of node.childNodes) collect(child, source, spans, textOnly);
|
|
124
226
|
}
|
|
125
227
|
function htmlSpans(source) {
|
|
126
228
|
const document = wrapParserErrors("HTML", () => parse(source, { sourceCodeLocationInfo: true }));
|
|
@@ -144,4 +246,4 @@ export {
|
|
|
144
246
|
htmlSpans,
|
|
145
247
|
htmlFragmentSpans
|
|
146
248
|
};
|
|
147
|
-
//# sourceMappingURL=chunk-
|
|
249
|
+
//# sourceMappingURL=chunk-6242RKS3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/modes/html.ts","../src/modes/parse-error.ts"],"sourcesContent":["import { parse, parseFragment } from \"parse5\";\nimport type { DefaultTreeAdapterMap } from \"parse5\";\nimport { wrapParserErrors } from \"./parse-error.js\";\nimport type { Span } from \"./spans.js\";\n\ntype Node = DefaultTreeAdapterMap[\"node\"];\ntype ParentNode = DefaultTreeAdapterMap[\"parentNode\"];\n\n/**\n * spec/rules/modes.md 3.6, exhaustive and **closed**: extending it is a spec change, not an\n * implementation decision. `svg` and `math` are here because in MathML a quotation mark, a\n * hyphen and a prime are operators and identifiers — substituting a curly glyph changes what\n * the expression means. Everything not listed is processable, **including unknown and custom\n * elements**: guessing from a tag name is exactly the heuristic that diverges across runtimes.\n */\nconst SKIPPED_ELEMENTS: ReadonlySet<string> = new Set([\n \"code\",\n \"pre\",\n \"kbd\",\n \"samp\",\n \"var\",\n \"script\",\n \"style\",\n \"textarea\",\n \"svg\",\n \"math\",\n]);\n\nexport function isSkippedElement(tagName: string): boolean {\n return SKIPPED_ELEMENTS.has(tagName);\n}\n\nconst AMPERSAND = 0x26;\nconst SEMICOLON = 0x3b;\nconst HASH = 0x23;\nconst LOWER_X = 0x78;\nconst UPPER_X = 0x58;\n\n/** Longest named reference in the WHATWG table is 32 characters; the guard is a bound, not a rule. */\nconst MAX_REFERENCE_BODY = 34;\n\nfunction isAsciiDigit(unit: number): boolean {\n return unit >= 0x30 && unit <= 0x39;\n}\n\nfunction isAsciiHexDigit(unit: number): boolean {\n return isAsciiDigit(unit) || (unit >= 0x61 && unit <= 0x66) || (unit >= 0x41 && unit <= 0x46);\n}\n\nfunction isAsciiAlphanumeric(unit: number): boolean {\n return isAsciiDigit(unit) || (unit >= 0x61 && unit <= 0x7a) || (unit >= 0x41 && unit <= 0x5a);\n}\n\n/**\n * The end offset of a well-formed character reference starting at `at`, or -1. A bare `&` that a\n * parser would repair is deliberately **not** treated as a reference: it stays inside the span,\n * where no rule can emit or delete it, rather than manufacturing a boundary that suppresses\n * conversions around it.\n */\nfunction characterReferenceEnd(source: string, at: number, limit: number): number {\n if (source.charCodeAt(at) !== AMPERSAND) return -1;\n let i = at + 1;\n if (i >= limit) return -1;\n\n if (source.charCodeAt(i) === HASH) {\n i += 1;\n const unit = i < limit ? source.charCodeAt(i) : -1;\n const hex = unit === LOWER_X || unit === UPPER_X;\n if (hex) i += 1;\n const digitsAt = i;\n while (\n i < limit &&\n (hex ? isAsciiHexDigit(source.charCodeAt(i)) : isAsciiDigit(source.charCodeAt(i)))\n ) {\n i += 1;\n }\n if (i === digitsAt) return -1;\n return i < limit && source.charCodeAt(i) === SEMICOLON ? i + 1 : -1;\n }\n\n const nameAt = i;\n while (\n i < limit &&\n i - nameAt < MAX_REFERENCE_BODY &&\n isAsciiAlphanumeric(source.charCodeAt(i))\n ) {\n i += 1;\n }\n if (i === nameAt) return -1;\n return i < limit && source.charCodeAt(i) === SEMICOLON ? i + 1 : -1;\n}\n\n/**\n * modes.md 3.6: every character reference is skipped as an **opaque unit**, and a text node\n * containing one is split into spans around it. That is the only way ` ` survives as\n * ` ` instead of becoming a literal U+00A0 on the way out.\n */\nexport function splitCharacterReferences(source: string, start: number, end: number): Span[] {\n const spans: Span[] = [];\n let cursor = start;\n let i = start;\n while (i < end) {\n if (source.charCodeAt(i) === AMPERSAND) {\n const stop = characterReferenceEnd(source, i, end);\n if (stop > 0) {\n if (i > cursor) spans.push({ start: cursor, end: i });\n cursor = stop;\n i = stop;\n continue;\n }\n }\n i += 1;\n }\n if (end > cursor) spans.push({ start: cursor, end });\n return spans;\n}\n\nfunction isParent(node: Node): node is ParentNode {\n return \"childNodes\" in node;\n}\n\n/**\n * modes.md 3.6 (spec 1.23.0): a text node of only U+0009, U+000A, U+000C, U+000D and U+0020 that\n * holds a line break is not a span, so the gap around it carries the raw line break and 3.2\n * picks the line marker. Pretty-printed markup then reads as `text` mode reads the same lines.\n */\nfunction isLineBreakWhitespace(source: string, start: number, end: number): boolean {\n let hasLineBreak = false;\n for (let i = start; i < end; i += 1) {\n const c = source.charCodeAt(i);\n if (c === 0x0a || c === 0x0c || c === 0x0d) hasLineBreak = true;\n else if (c !== 0x09 && c !== 0x20) return false;\n }\n return hasLineBreak;\n}\n\nconst LESS_THAN = 0x3c;\nconst SOLIDUS = 0x2f;\nconst GREATER_THAN = 0x3e;\nconst EQUALS = 0x3d;\n\nfunction isAsciiAlpha(unit: number): boolean {\n return (unit >= 0x41 && unit <= 0x5a) || (unit >= 0x61 && unit <= 0x7a);\n}\n\nfunction isTagSpace(unit: number): boolean {\n return unit === 0x09 || unit === 0x0a || unit === 0x0c || unit === 0x0d || unit === 0x20;\n}\n\n/**\n * The offset just past the tag that starts at `at`, or -1 when no tag starts there. Follows the\n * HTML tokenizer: `<` plus a letter, `</` plus a letter, or `</>`. A quote opens a value only in\n * the before-attribute-value state, reached by an `=` that follows an attribute name; an `=` that\n * begins a name, or sits inside an unquoted value, is data.\n */\nfunction tagEnd(source: string, at: number, limit: number): number {\n if (source.charCodeAt(at) !== LESS_THAN) return -1;\n let i = at + 1;\n if (i >= limit) return -1;\n if (source.charCodeAt(i) === SOLIDUS) {\n i += 1;\n if (i >= limit) return -1;\n if (source.charCodeAt(i) === GREATER_THAN) return i + 1;\n }\n if (!isAsciiAlpha(source.charCodeAt(i))) return -1;\n // tag name\n while (i < limit) {\n const c = source.charCodeAt(i);\n if (isTagSpace(c) || c === SOLIDUS || c === GREATER_THAN) break;\n i += 1;\n }\n while (i < limit) {\n // before attribute name\n let c = source.charCodeAt(i);\n if (isTagSpace(c) || c === SOLIDUS) {\n i += 1;\n continue;\n }\n if (c === GREATER_THAN) return i + 1;\n // attribute name: an `=` first in the name is part of it\n i += 1;\n while (i < limit) {\n c = source.charCodeAt(i);\n if (isTagSpace(c) || c === SOLIDUS || c === GREATER_THAN || c === EQUALS) break;\n i += 1;\n }\n // after attribute name\n while (i < limit && isTagSpace(source.charCodeAt(i))) i += 1;\n if (i >= limit) return -1;\n c = source.charCodeAt(i);\n if (c === GREATER_THAN) return i + 1;\n if (c !== EQUALS) continue;\n // before attribute value\n i += 1;\n while (i < limit && isTagSpace(source.charCodeAt(i))) i += 1;\n if (i >= limit) return -1;\n c = source.charCodeAt(i);\n if (c === GREATER_THAN) return i + 1;\n if (c === 0x22 || c === 0x27) {\n const close = source.indexOf(c === 0x22 ? '\"' : \"'\", i + 1);\n if (close === -1 || close >= limit) return -1;\n i = close + 1;\n continue;\n }\n while (i < limit) {\n c = source.charCodeAt(i);\n if (isTagSpace(c) || c === GREATER_THAN) break;\n i += 1;\n }\n }\n return -1;\n}\n\n/**\n * modes.md 3.6 (spec 1.23.1): a tag the parser ignores is still a tag in the source, and parse5\n * merges the text on either side of it into one node. Splitting the run at every tag-shaped token\n * keeps the tag outside every span and puts it in the gap, where 3.2 chooses the marker.\n */\nfunction textPieces(source: string, start: number, end: number): Array<[number, number]> {\n const pieces: Array<[number, number]> = [];\n let cursor = start;\n let i = start;\n while (i < end) {\n if (source.charCodeAt(i) === LESS_THAN) {\n const stop = tagEnd(source, i, end);\n if (stop > 0) {\n if (i > cursor) pieces.push([cursor, i]);\n cursor = stop;\n i = stop;\n continue;\n }\n }\n i += 1;\n }\n if (end > cursor) pieces.push([cursor, end]);\n return pieces;\n}\n\n// Their text is character data, not markup: `<` begins no tag inside them (HTML tokenizer RCDATA,\n// RAWTEXT and PLAINTEXT states), so textPieces must not look for one.\nconst TEXT_ONLY_PARENTS = new Set([\n \"title\",\n \"xmp\",\n \"iframe\",\n \"noembed\",\n \"noframes\",\n \"noscript\",\n \"plaintext\",\n]);\n\nfunction collect(node: Node, source: string, spans: Span[], isTextOnly = false): void {\n if (node.nodeName === \"#text\") {\n const location = node.sourceCodeLocation;\n if (location === undefined || location === null) return;\n const pieces = isTextOnly\n ? ([[location.startOffset, location.endOffset]] as Array<[number, number]>)\n : textPieces(source, location.startOffset, location.endOffset);\n for (const [from, to] of pieces) {\n if (isLineBreakWhitespace(source, from, to)) continue;\n for (const span of splitCharacterReferences(source, from, to)) spans.push(span);\n }\n return;\n }\n\n // Comments, doctype and processing instructions never contribute a span (modes.md 3.6).\n if (node.nodeName === \"#comment\" || node.nodeName === \"#documentType\") return;\n\n if (\"tagName\" in node && isSkippedElement(node.tagName)) return;\n\n // A `template`'s children live in a separate document fragment; `template` is not skipped.\n if (node.nodeName === \"template\" && \"content\" in node) {\n collect(node.content, source, spans);\n return;\n }\n\n if (!isParent(node)) return;\n const textOnly = \"tagName\" in node && TEXT_ONLY_PARENTS.has(node.tagName);\n for (const child of node.childNodes) collect(child, source, spans, textOnly);\n}\n\n/**\n * Locate the processable spans of an HTML document. The tree is used only to find offsets and is\n * then discarded — modes.md 4 forbids reserialisation, which is what makes attribute quoting,\n * self-closing forms, entity spelling, tag case and malformed-input recovery preserved by\n * construction rather than by effort.\n */\nexport function htmlSpans(source: string): Span[] {\n const document = wrapParserErrors(\"HTML\", () => parse(source, { sourceCodeLocationInfo: true }));\n const spans: Span[] = [];\n collect(document, source, spans);\n return spans;\n}\n\n/** The same, for a fragment: used for HTML blocks embedded in markdown (modes.md 3.7). */\nexport function htmlFragmentSpans(source: string, offset: number): Span[] {\n const fragment = wrapParserErrors(\"HTML\", () =>\n parseFragment(source, { sourceCodeLocationInfo: true }),\n );\n const spans: Span[] = [];\n collect(fragment, source, spans);\n return offset === 0\n ? spans\n : spans.map((span) => ({ start: span.start + offset, end: span.end + offset }));\n}\n","import { PolytypoError } from \"../errors.js\";\n\ninterface PositionedError {\n readonly reason?: unknown;\n readonly place?: { readonly line?: unknown; readonly column?: unknown } | null;\n}\n\nfunction describe(error: unknown): string {\n if (typeof error !== \"object\" || error === null) return String(error);\n const positioned = error as PositionedError;\n const reason =\n typeof positioned.reason === \"string\" ? positioned.reason : (error as Error).message;\n const place = positioned.place;\n if (\n place !== null &&\n place !== undefined &&\n typeof place.line === \"number\" &&\n typeof place.column === \"number\"\n ) {\n return `${reason} (line ${place.line}, column ${place.column})`;\n }\n return reason;\n}\n\n/**\n * spec/rules/modes.md 3.7.2. **The parser's own error type must never escape.** A\n * `VFileMessage`, a `Nokogiri::SyntaxError` or a Python exception on the public surface puts a\n * dependency's type into the contract and is unreproducible in the other four runtimes; only the\n * code is contractual (ARCHITECTURE.md 4.6), while the message and the source position are\n * useful and are not.\n *\n * Reachable in exactly one place: `dialect: \"mdx\"`, because MDX embeds JavaScript. HTML parsing\n * is specified with total error recovery and every byte sequence is valid CommonMark, so neither\n * of the other two languages can fail. The wrapper is applied to all of them anyway — the\n * guarantee is that no parser type escapes, not that this particular parser is trusted.\n */\nexport function wrapParserErrors<T>(what: string, run: () => T): T {\n try {\n return run();\n } catch (error) {\n if (error instanceof PolytypoError) throw error;\n throw new PolytypoError(\n \"POLYTYPO_MALFORMED_INPUT\",\n `Input does not parse as ${what}: ${describe(error)}`,\n );\n }\n}\n"],"mappings":";;;;;AAAA,SAAS,OAAO,qBAAqB;;;ACOrC,SAAS,SAAS,OAAwB;AACxC,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO,OAAO,KAAK;AACpE,QAAM,aAAa;AACnB,QAAM,SACJ,OAAO,WAAW,WAAW,WAAW,WAAW,SAAU,MAAgB;AAC/E,QAAM,QAAQ,WAAW;AACzB,MACE,UAAU,QACV,UAAU,UACV,OAAO,MAAM,SAAS,YACtB,OAAO,MAAM,WAAW,UACxB;AACA,WAAO,GAAG,MAAM,UAAU,MAAM,IAAI,YAAY,MAAM,MAAM;AAAA,EAC9D;AACA,SAAO;AACT;AAcO,SAAS,iBAAoB,MAAc,KAAiB;AACjE,MAAI;AACF,WAAO,IAAI;AAAA,EACb,SAAS,OAAO;AACd,QAAI,iBAAiB,cAAe,OAAM;AAC1C,UAAM,IAAI;AAAA,MACR;AAAA,MACA,2BAA2B,IAAI,KAAK,SAAS,KAAK,CAAC;AAAA,IACrD;AAAA,EACF;AACF;;;AD/BA,IAAM,mBAAwC,oBAAI,IAAI;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,SAAS,iBAAiB,SAA0B;AAC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K,aAAa,cAAc,aAAa,MAAM;AACrD,YAAQ,KAAK,SAAS,QAAQ,KAAK;AACnC;AAAA,EACF;AAEA,MAAI,CAAC,SAAS,IAAI,EAAG;AACrB,QAAM,WAAW,aAAa,QAAQ,kBAAkB,IAAI,KAAK,OAAO;AACxE,aAAW,SAAS,KAAK,WAAY,SAAQ,OAAO,QAAQ,OAAO,QAAQ;AAC7E;AAQO,SAAS,UAAU,QAAwB;AAChD,QAAM,WAAW,iBAAiB,QAAQ,MAAM,MAAM,QAAQ,EAAE,wBAAwB,KAAK,CAAC,CAAC;AAC/F,QAAM,QAAgB,CAAC;AACvB,UAAQ,UAAU,QAAQ,KAAK;AAC/B,SAAO;AACT;AAGO,SAAS,kBAAkB,QAAgB,QAAwB;AACxE,QAAM,WAAW;AAAA,IAAiB;AAAA,IAAQ,MACxC,cAAc,QAAQ,EAAE,wBAAwB,KAAK,CAAC;AAAA,EACxD;AACA,QAAM,QAAgB,CAAC;AACvB,UAAQ,UAAU,QAAQ,KAAK;AAC/B,SAAO,WAAW,IACd,QACA,MAAM,IAAI,CAAC,UAAU,EAAE,OAAO,KAAK,QAAQ,QAAQ,KAAK,KAAK,MAAM,OAAO,EAAE;AAClF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkQDLVXAHKcjs = require('./chunk-QDLVXAHK.cjs');
|
|
4
4
|
|
|
5
5
|
// src/modes/html.ts
|
|
6
6
|
var _parse5 = require('parse5');
|
|
@@ -20,8 +20,8 @@ function wrapParserErrors(what, run) {
|
|
|
20
20
|
try {
|
|
21
21
|
return run();
|
|
22
22
|
} catch (error) {
|
|
23
|
-
if (error instanceof
|
|
24
|
-
throw new (0,
|
|
23
|
+
if (error instanceof _chunkQDLVXAHKcjs.PolytypoError) throw error;
|
|
24
|
+
throw new (0, _chunkQDLVXAHKcjs.PolytypoError)(
|
|
25
25
|
"POLYTYPO_MALFORMED_INPUT",
|
|
26
26
|
`Input does not parse as ${what}: ${describe(error)}`
|
|
27
27
|
);
|
|
@@ -104,12 +104,113 @@ function splitCharacterReferences(source, start, end) {
|
|
|
104
104
|
function isParent(node) {
|
|
105
105
|
return "childNodes" in node;
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
function isLineBreakWhitespace(source, start, end) {
|
|
108
|
+
let hasLineBreak = false;
|
|
109
|
+
for (let i = start; i < end; i += 1) {
|
|
110
|
+
const c = source.charCodeAt(i);
|
|
111
|
+
if (c === 10 || c === 12 || c === 13) hasLineBreak = true;
|
|
112
|
+
else if (c !== 9 && c !== 32) return false;
|
|
113
|
+
}
|
|
114
|
+
return hasLineBreak;
|
|
115
|
+
}
|
|
116
|
+
var LESS_THAN = 60;
|
|
117
|
+
var SOLIDUS = 47;
|
|
118
|
+
var GREATER_THAN = 62;
|
|
119
|
+
var EQUALS = 61;
|
|
120
|
+
function isAsciiAlpha(unit) {
|
|
121
|
+
return unit >= 65 && unit <= 90 || unit >= 97 && unit <= 122;
|
|
122
|
+
}
|
|
123
|
+
function isTagSpace(unit) {
|
|
124
|
+
return unit === 9 || unit === 10 || unit === 12 || unit === 13 || unit === 32;
|
|
125
|
+
}
|
|
126
|
+
function tagEnd(source, at, limit) {
|
|
127
|
+
if (source.charCodeAt(at) !== LESS_THAN) return -1;
|
|
128
|
+
let i = at + 1;
|
|
129
|
+
if (i >= limit) return -1;
|
|
130
|
+
if (source.charCodeAt(i) === SOLIDUS) {
|
|
131
|
+
i += 1;
|
|
132
|
+
if (i >= limit) return -1;
|
|
133
|
+
if (source.charCodeAt(i) === GREATER_THAN) return i + 1;
|
|
134
|
+
}
|
|
135
|
+
if (!isAsciiAlpha(source.charCodeAt(i))) return -1;
|
|
136
|
+
while (i < limit) {
|
|
137
|
+
const c = source.charCodeAt(i);
|
|
138
|
+
if (isTagSpace(c) || c === SOLIDUS || c === GREATER_THAN) break;
|
|
139
|
+
i += 1;
|
|
140
|
+
}
|
|
141
|
+
while (i < limit) {
|
|
142
|
+
let c = source.charCodeAt(i);
|
|
143
|
+
if (isTagSpace(c) || c === SOLIDUS) {
|
|
144
|
+
i += 1;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (c === GREATER_THAN) return i + 1;
|
|
148
|
+
i += 1;
|
|
149
|
+
while (i < limit) {
|
|
150
|
+
c = source.charCodeAt(i);
|
|
151
|
+
if (isTagSpace(c) || c === SOLIDUS || c === GREATER_THAN || c === EQUALS) break;
|
|
152
|
+
i += 1;
|
|
153
|
+
}
|
|
154
|
+
while (i < limit && isTagSpace(source.charCodeAt(i))) i += 1;
|
|
155
|
+
if (i >= limit) return -1;
|
|
156
|
+
c = source.charCodeAt(i);
|
|
157
|
+
if (c === GREATER_THAN) return i + 1;
|
|
158
|
+
if (c !== EQUALS) continue;
|
|
159
|
+
i += 1;
|
|
160
|
+
while (i < limit && isTagSpace(source.charCodeAt(i))) i += 1;
|
|
161
|
+
if (i >= limit) return -1;
|
|
162
|
+
c = source.charCodeAt(i);
|
|
163
|
+
if (c === GREATER_THAN) return i + 1;
|
|
164
|
+
if (c === 34 || c === 39) {
|
|
165
|
+
const close = source.indexOf(c === 34 ? '"' : "'", i + 1);
|
|
166
|
+
if (close === -1 || close >= limit) return -1;
|
|
167
|
+
i = close + 1;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
while (i < limit) {
|
|
171
|
+
c = source.charCodeAt(i);
|
|
172
|
+
if (isTagSpace(c) || c === GREATER_THAN) break;
|
|
173
|
+
i += 1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return -1;
|
|
177
|
+
}
|
|
178
|
+
function textPieces(source, start, end) {
|
|
179
|
+
const pieces = [];
|
|
180
|
+
let cursor = start;
|
|
181
|
+
let i = start;
|
|
182
|
+
while (i < end) {
|
|
183
|
+
if (source.charCodeAt(i) === LESS_THAN) {
|
|
184
|
+
const stop = tagEnd(source, i, end);
|
|
185
|
+
if (stop > 0) {
|
|
186
|
+
if (i > cursor) pieces.push([cursor, i]);
|
|
187
|
+
cursor = stop;
|
|
188
|
+
i = stop;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
i += 1;
|
|
193
|
+
}
|
|
194
|
+
if (end > cursor) pieces.push([cursor, end]);
|
|
195
|
+
return pieces;
|
|
196
|
+
}
|
|
197
|
+
var TEXT_ONLY_PARENTS = /* @__PURE__ */ new Set([
|
|
198
|
+
"title",
|
|
199
|
+
"xmp",
|
|
200
|
+
"iframe",
|
|
201
|
+
"noembed",
|
|
202
|
+
"noframes",
|
|
203
|
+
"noscript",
|
|
204
|
+
"plaintext"
|
|
205
|
+
]);
|
|
206
|
+
function collect(node, source, spans, isTextOnly = false) {
|
|
108
207
|
if (node.nodeName === "#text") {
|
|
109
208
|
const location = node.sourceCodeLocation;
|
|
110
209
|
if (location === void 0 || location === null) return;
|
|
111
|
-
|
|
112
|
-
|
|
210
|
+
const pieces = isTextOnly ? [[location.startOffset, location.endOffset]] : textPieces(source, location.startOffset, location.endOffset);
|
|
211
|
+
for (const [from, to] of pieces) {
|
|
212
|
+
if (isLineBreakWhitespace(source, from, to)) continue;
|
|
213
|
+
for (const span of splitCharacterReferences(source, from, to)) spans.push(span);
|
|
113
214
|
}
|
|
114
215
|
return;
|
|
115
216
|
}
|
|
@@ -120,7 +221,8 @@ function collect(node, source, spans) {
|
|
|
120
221
|
return;
|
|
121
222
|
}
|
|
122
223
|
if (!isParent(node)) return;
|
|
123
|
-
|
|
224
|
+
const textOnly = "tagName" in node && TEXT_ONLY_PARENTS.has(node.tagName);
|
|
225
|
+
for (const child of node.childNodes) collect(child, source, spans, textOnly);
|
|
124
226
|
}
|
|
125
227
|
function htmlSpans(source) {
|
|
126
228
|
const document = wrapParserErrors("HTML", () => _parse5.parse.call(void 0, source, { sourceCodeLocationInfo: true }));
|
|
@@ -144,4 +246,4 @@ function htmlFragmentSpans(source, offset) {
|
|
|
144
246
|
|
|
145
247
|
|
|
146
248
|
exports.wrapParserErrors = wrapParserErrors; exports.isSkippedElement = isSkippedElement; exports.htmlSpans = htmlSpans; exports.htmlFragmentSpans = htmlFragmentSpans;
|
|
147
|
-
//# sourceMappingURL=chunk-
|
|
249
|
+
//# sourceMappingURL=chunk-6MZWJX7B.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-6MZWJX7B.cjs","../src/modes/html.ts","../src/modes/parse-error.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,gCAAqC;ADMrC;AACA;AEAA,SAAS,QAAA,CAAS,KAAA,EAAwB;AACxC,EAAA,GAAA,CAAI,OAAO,MAAA,IAAU,SAAA,GAAY,MAAA,IAAU,IAAA,EAAM,OAAO,MAAA,CAAO,KAAK,CAAA;AACpE,EAAA,MAAM,WAAA,EAAa,KAAA;AACnB,EAAA,MAAM,OAAA,EACJ,OAAO,UAAA,CAAW,OAAA,IAAW,SAAA,EAAW,UAAA,CAAW,OAAA,EAAU,KAAA,CAAgB,OAAA;AAC/E,EAAA,MAAM,MAAA,EAAQ,UAAA,CAAW,KAAA;AACzB,EAAA,GAAA,CACE,MAAA,IAAU,KAAA,GACV,MAAA,IAAU,KAAA,EAAA,GACV,OAAO,KAAA,CAAM,KAAA,IAAS,SAAA,GACtB,OAAO,KAAA,CAAM,OAAA,IAAW,QAAA,EACxB;AACA,IAAA,OAAO,CAAA,EAAA;AACT,EAAA;AACO,EAAA;AACT;AAcgB;AACV,EAAA;AACK,IAAA;AACA,EAAA;AACH,IAAA;AACE,IAAA;AACJ,MAAA;AACA,MAAA;AACF,IAAA;AACF,EAAA;AACF;AFjBY;AACA;ACfN;AACJ,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACD;AA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AA;AACA,MAAA;AACC,MAAA;AACP,IAAA;AACF,EAAA;AACO,EAAA;AACT;AAOS;AACD,EAAA;AACF,EAAA;AACI,EAAA;AACD,EAAA;AACD,IAAA;AACI,MAAA;AACF,MAAA;AACE,QAAA;AACJ,QAAA;AACI,QAAA;AACJ,QAAA;AACF,MAAA;AACF,IAAA;AACK,IAAA;AACP,EAAA;AACU,EAAA;AACH,EAAA;AACT;AAIM;AACJ,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACD;AAEQ;AACE,EAAA;AACD,IAAA;AACF,IAAA;AACE,IAAA;AAGN,IAAA;AACM,MAAA;AACJ,MAAA;AACF,IAAA;AACA,IAAA;AACF,EAAA;AAGS,EAAA;AAEL,EAAA;AAGK,EAAA;AACC,IAAA;AACR,IAAA;AACF,EAAA;AAEK,EAAA;AACC,EAAA;AACN,EAAA;AACF;AAQgB;AACR,EAAA;AACA,EAAA;AACE,EAAA;AACD,EAAA;AACT;AAGgB;AACR,EAAA;AAA4B,IAAA;AAChC,IAAA;AACF,EAAA;AACM,EAAA;AACE,EAAA;AACD,EAAA;AAGT;AD9DY;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-6MZWJX7B.cjs","sourcesContent":[null,"import { parse, parseFragment } from \"parse5\";\nimport type { DefaultTreeAdapterMap } from \"parse5\";\nimport { wrapParserErrors } from \"./parse-error.js\";\nimport type { Span } from \"./spans.js\";\n\ntype Node = DefaultTreeAdapterMap[\"node\"];\ntype ParentNode = DefaultTreeAdapterMap[\"parentNode\"];\n\n/**\n * spec/rules/modes.md 3.6, exhaustive and **closed**: extending it is a spec change, not an\n * implementation decision. `svg` and `math` are here because in MathML a quotation mark, a\n * hyphen and a prime are operators and identifiers — substituting a curly glyph changes what\n * the expression means. Everything not listed is processable, **including unknown and custom\n * elements**: guessing from a tag name is exactly the heuristic that diverges across runtimes.\n */\nconst SKIPPED_ELEMENTS: ReadonlySet<string> = new Set([\n \"code\",\n \"pre\",\n \"kbd\",\n \"samp\",\n \"var\",\n \"script\",\n \"style\",\n \"textarea\",\n \"svg\",\n \"math\",\n]);\n\nexport function isSkippedElement(tagName: string): boolean {\n return SKIPPED_ELEMENTS.has(tagName);\n}\n\nconst AMPERSAND = 0x26;\nconst SEMICOLON = 0x3b;\nconst HASH = 0x23;\nconst LOWER_X = 0x78;\nconst UPPER_X = 0x58;\n\n/** Longest named reference in the WHATWG table is 32 characters; the guard is a bound, not a rule. */\nconst MAX_REFERENCE_BODY = 34;\n\nfunction isAsciiDigit(unit: number): boolean {\n return unit >= 0x30 && unit <= 0x39;\n}\n\nfunction isAsciiHexDigit(unit: number): boolean {\n return isAsciiDigit(unit) || (unit >= 0x61 && unit <= 0x66) || (unit >= 0x41 && unit <= 0x46);\n}\n\nfunction isAsciiAlphanumeric(unit: number): boolean {\n return isAsciiDigit(unit) || (unit >= 0x61 && unit <= 0x7a) || (unit >= 0x41 && unit <= 0x5a);\n}\n\n/**\n * The end offset of a well-formed character reference starting at `at`, or -1. A bare `&` that a\n * parser would repair is deliberately **not** treated as a reference: it stays inside the span,\n * where no rule can emit or delete it, rather than manufacturing a boundary that suppresses\n * conversions around it.\n */\nfunction characterReferenceEnd(source: string, at: number, limit: number): number {\n if (source.charCodeAt(at) !== AMPERSAND) return -1;\n let i = at + 1;\n if (i >= limit) return -1;\n\n if (source.charCodeAt(i) === HASH) {\n i += 1;\n const unit = i < limit ? source.charCodeAt(i) : -1;\n const hex = unit === LOWER_X || unit === UPPER_X;\n if (hex) i += 1;\n const digitsAt = i;\n while (\n i < limit &&\n (hex ? isAsciiHexDigit(source.charCodeAt(i)) : isAsciiDigit(source.charCodeAt(i)))\n ) {\n i += 1;\n }\n if (i === digitsAt) return -1;\n return i < limit && source.charCodeAt(i) === SEMICOLON ? i + 1 : -1;\n }\n\n const nameAt = i;\n while (\n i < limit &&\n i - nameAt < MAX_REFERENCE_BODY &&\n isAsciiAlphanumeric(source.charCodeAt(i))\n ) {\n i += 1;\n }\n if (i === nameAt) return -1;\n return i < limit && source.charCodeAt(i) === SEMICOLON ? i + 1 : -1;\n}\n\n/**\n * modes.md 3.6: every character reference is skipped as an **opaque unit**, and a text node\n * containing one is split into spans around it. That is the only way ` ` survives as\n * ` ` instead of becoming a literal U+00A0 on the way out.\n */\nexport function splitCharacterReferences(source: string, start: number, end: number): Span[] {\n const spans: Span[] = [];\n let cursor = start;\n let i = start;\n while (i < end) {\n if (source.charCodeAt(i) === AMPERSAND) {\n const stop = characterReferenceEnd(source, i, end);\n if (stop > 0) {\n if (i > cursor) spans.push({ start: cursor, end: i });\n cursor = stop;\n i = stop;\n continue;\n }\n }\n i += 1;\n }\n if (end > cursor) spans.push({ start: cursor, end });\n return spans;\n}\n\nfunction isParent(node: Node): node is ParentNode {\n return \"childNodes\" in node;\n}\n\n/**\n * modes.md 3.6 (spec 1.23.0): a text node of only U+0009, U+000A, U+000C, U+000D and U+0020 that\n * holds a line break is not a span, so the gap around it carries the raw line break and 3.2\n * picks the line marker. Pretty-printed markup then reads as `text` mode reads the same lines.\n */\nfunction isLineBreakWhitespace(source: string, start: number, end: number): boolean {\n let hasLineBreak = false;\n for (let i = start; i < end; i += 1) {\n const c = source.charCodeAt(i);\n if (c === 0x0a || c === 0x0c || c === 0x0d) hasLineBreak = true;\n else if (c !== 0x09 && c !== 0x20) return false;\n }\n return hasLineBreak;\n}\n\nconst LESS_THAN = 0x3c;\nconst SOLIDUS = 0x2f;\nconst GREATER_THAN = 0x3e;\nconst EQUALS = 0x3d;\n\nfunction isAsciiAlpha(unit: number): boolean {\n return (unit >= 0x41 && unit <= 0x5a) || (unit >= 0x61 && unit <= 0x7a);\n}\n\nfunction isTagSpace(unit: number): boolean {\n return unit === 0x09 || unit === 0x0a || unit === 0x0c || unit === 0x0d || unit === 0x20;\n}\n\n/**\n * The offset just past the tag that starts at `at`, or -1 when no tag starts there. Follows the\n * HTML tokenizer: `<` plus a letter, `</` plus a letter, or `</>`. A quote opens a value only in\n * the before-attribute-value state, reached by an `=` that follows an attribute name; an `=` that\n * begins a name, or sits inside an unquoted value, is data.\n */\nfunction tagEnd(source: string, at: number, limit: number): number {\n if (source.charCodeAt(at) !== LESS_THAN) return -1;\n let i = at + 1;\n if (i >= limit) return -1;\n if (source.charCodeAt(i) === SOLIDUS) {\n i += 1;\n if (i >= limit) return -1;\n if (source.charCodeAt(i) === GREATER_THAN) return i + 1;\n }\n if (!isAsciiAlpha(source.charCodeAt(i))) return -1;\n // tag name\n while (i < limit) {\n const c = source.charCodeAt(i);\n if (isTagSpace(c) || c === SOLIDUS || c === GREATER_THAN) break;\n i += 1;\n }\n while (i < limit) {\n // before attribute name\n let c = source.charCodeAt(i);\n if (isTagSpace(c) || c === SOLIDUS) {\n i += 1;\n continue;\n }\n if (c === GREATER_THAN) return i + 1;\n // attribute name: an `=` first in the name is part of it\n i += 1;\n while (i < limit) {\n c = source.charCodeAt(i);\n if (isTagSpace(c) || c === SOLIDUS || c === GREATER_THAN || c === EQUALS) break;\n i += 1;\n }\n // after attribute name\n while (i < limit && isTagSpace(source.charCodeAt(i))) i += 1;\n if (i >= limit) return -1;\n c = source.charCodeAt(i);\n if (c === GREATER_THAN) return i + 1;\n if (c !== EQUALS) continue;\n // before attribute value\n i += 1;\n while (i < limit && isTagSpace(source.charCodeAt(i))) i += 1;\n if (i >= limit) return -1;\n c = source.charCodeAt(i);\n if (c === GREATER_THAN) return i + 1;\n if (c === 0x22 || c === 0x27) {\n const close = source.indexOf(c === 0x22 ? '\"' : \"'\", i + 1);\n if (close === -1 || close >= limit) return -1;\n i = close + 1;\n continue;\n }\n while (i < limit) {\n c = source.charCodeAt(i);\n if (isTagSpace(c) || c === GREATER_THAN) break;\n i += 1;\n }\n }\n return -1;\n}\n\n/**\n * modes.md 3.6 (spec 1.23.1): a tag the parser ignores is still a tag in the source, and parse5\n * merges the text on either side of it into one node. Splitting the run at every tag-shaped token\n * keeps the tag outside every span and puts it in the gap, where 3.2 chooses the marker.\n */\nfunction textPieces(source: string, start: number, end: number): Array<[number, number]> {\n const pieces: Array<[number, number]> = [];\n let cursor = start;\n let i = start;\n while (i < end) {\n if (source.charCodeAt(i) === LESS_THAN) {\n const stop = tagEnd(source, i, end);\n if (stop > 0) {\n if (i > cursor) pieces.push([cursor, i]);\n cursor = stop;\n i = stop;\n continue;\n }\n }\n i += 1;\n }\n if (end > cursor) pieces.push([cursor, end]);\n return pieces;\n}\n\n// Their text is character data, not markup: `<` begins no tag inside them (HTML tokenizer RCDATA,\n// RAWTEXT and PLAINTEXT states), so textPieces must not look for one.\nconst TEXT_ONLY_PARENTS = new Set([\n \"title\",\n \"xmp\",\n \"iframe\",\n \"noembed\",\n \"noframes\",\n \"noscript\",\n \"plaintext\",\n]);\n\nfunction collect(node: Node, source: string, spans: Span[], isTextOnly = false): void {\n if (node.nodeName === \"#text\") {\n const location = node.sourceCodeLocation;\n if (location === undefined || location === null) return;\n const pieces = isTextOnly\n ? ([[location.startOffset, location.endOffset]] as Array<[number, number]>)\n : textPieces(source, location.startOffset, location.endOffset);\n for (const [from, to] of pieces) {\n if (isLineBreakWhitespace(source, from, to)) continue;\n for (const span of splitCharacterReferences(source, from, to)) spans.push(span);\n }\n return;\n }\n\n // Comments, doctype and processing instructions never contribute a span (modes.md 3.6).\n if (node.nodeName === \"#comment\" || node.nodeName === \"#documentType\") return;\n\n if (\"tagName\" in node && isSkippedElement(node.tagName)) return;\n\n // A `template`'s children live in a separate document fragment; `template` is not skipped.\n if (node.nodeName === \"template\" && \"content\" in node) {\n collect(node.content, source, spans);\n return;\n }\n\n if (!isParent(node)) return;\n const textOnly = \"tagName\" in node && TEXT_ONLY_PARENTS.has(node.tagName);\n for (const child of node.childNodes) collect(child, source, spans, textOnly);\n}\n\n/**\n * Locate the processable spans of an HTML document. The tree is used only to find offsets and is\n * then discarded — modes.md 4 forbids reserialisation, which is what makes attribute quoting,\n * self-closing forms, entity spelling, tag case and malformed-input recovery preserved by\n * construction rather than by effort.\n */\nexport function htmlSpans(source: string): Span[] {\n const document = wrapParserErrors(\"HTML\", () => parse(source, { sourceCodeLocationInfo: true }));\n const spans: Span[] = [];\n collect(document, source, spans);\n return spans;\n}\n\n/** The same, for a fragment: used for HTML blocks embedded in markdown (modes.md 3.7). */\nexport function htmlFragmentSpans(source: string, offset: number): Span[] {\n const fragment = wrapParserErrors(\"HTML\", () =>\n parseFragment(source, { sourceCodeLocationInfo: true }),\n );\n const spans: Span[] = [];\n collect(fragment, source, spans);\n return offset === 0\n ? spans\n : spans.map((span) => ({ start: span.start + offset, end: span.end + offset }));\n}\n","import { PolytypoError } from \"../errors.js\";\n\ninterface PositionedError {\n readonly reason?: unknown;\n readonly place?: { readonly line?: unknown; readonly column?: unknown } | null;\n}\n\nfunction describe(error: unknown): string {\n if (typeof error !== \"object\" || error === null) return String(error);\n const positioned = error as PositionedError;\n const reason =\n typeof positioned.reason === \"string\" ? positioned.reason : (error as Error).message;\n const place = positioned.place;\n if (\n place !== null &&\n place !== undefined &&\n typeof place.line === \"number\" &&\n typeof place.column === \"number\"\n ) {\n return `${reason} (line ${place.line}, column ${place.column})`;\n }\n return reason;\n}\n\n/**\n * spec/rules/modes.md 3.7.2. **The parser's own error type must never escape.** A\n * `VFileMessage`, a `Nokogiri::SyntaxError` or a Python exception on the public surface puts a\n * dependency's type into the contract and is unreproducible in the other four runtimes; only the\n * code is contractual (ARCHITECTURE.md 4.6), while the message and the source position are\n * useful and are not.\n *\n * Reachable in exactly one place: `dialect: \"mdx\"`, because MDX embeds JavaScript. HTML parsing\n * is specified with total error recovery and every byte sequence is valid CommonMark, so neither\n * of the other two languages can fail. The wrapper is applied to all of them anyway — the\n * guarantee is that no parser type escapes, not that this particular parser is trusted.\n */\nexport function wrapParserErrors<T>(what: string, run: () => T): T {\n try {\n return run();\n } catch (error) {\n if (error instanceof PolytypoError) throw error;\n throw new PolytypoError(\n \"POLYTYPO_MALFORMED_INPUT\",\n `Input does not parse as ${what}: ${describe(error)}`,\n );\n }\n}\n"]}
|
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
htmlFragmentSpans,
|
|
3
3
|
isSkippedElement,
|
|
4
4
|
wrapParserErrors
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-6242RKS3.js";
|
|
6
6
|
import {
|
|
7
7
|
resolveFrontmatterKeys,
|
|
8
8
|
yamlSpans
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-SLAQTVNN.js";
|
|
10
10
|
import {
|
|
11
11
|
PolytypoError,
|
|
12
12
|
analyzeOverUnits,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
planRules,
|
|
17
17
|
resolveNarrowTarget,
|
|
18
18
|
runOverUnits
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-YXUADCFN.js";
|
|
20
20
|
|
|
21
21
|
// src/modes/markdown.ts
|
|
22
22
|
import { parse, postprocess, preprocess } from "micromark";
|
|
@@ -394,4 +394,4 @@ export {
|
|
|
394
394
|
runMarkdownPipeline,
|
|
395
395
|
analyzeMarkdownPipeline
|
|
396
396
|
};
|
|
397
|
-
//# sourceMappingURL=chunk-
|
|
397
|
+
//# sourceMappingURL=chunk-6Q3KRZQ5.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
htmlSpans
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6242RKS3.js";
|
|
4
4
|
import {
|
|
5
5
|
analyzeOverSpans,
|
|
6
6
|
assertNoProtect,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
planRules,
|
|
9
9
|
resolveNarrowTarget,
|
|
10
10
|
runOverSpans
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-YXUADCFN.js";
|
|
12
12
|
|
|
13
13
|
// src/engine/html-pipeline.ts
|
|
14
14
|
function runHtmlPipeline(input, options) {
|
|
@@ -31,4 +31,4 @@ export {
|
|
|
31
31
|
runHtmlPipeline,
|
|
32
32
|
analyzeHtmlPipeline
|
|
33
33
|
};
|
|
34
|
-
//# sourceMappingURL=chunk-
|
|
34
|
+
//# sourceMappingURL=chunk-75YYV3FW.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkGL273L36cjs = require('./chunk-GL273L36.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkQDLVXAHKcjs = require('./chunk-QDLVXAHK.cjs');
|
|
13
|
+
|
|
14
|
+
// src/engine/yaml-pipeline.ts
|
|
15
|
+
function runYamlPipeline(input, options) {
|
|
16
|
+
const narrowTarget = _chunkQDLVXAHKcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
17
|
+
const planned = _chunkQDLVXAHKcjs.planRules.call(void 0, options.rules);
|
|
18
|
+
const locale = _chunkQDLVXAHKcjs.getLocaleData.call(void 0, options.locale);
|
|
19
|
+
const keys = _chunkGL273L36cjs.resolveYamlKeys.call(void 0, options.keys);
|
|
20
|
+
_chunkQDLVXAHKcjs.assertNoProtect.call(void 0, options.protect, "yaml");
|
|
21
|
+
return _chunkQDLVXAHKcjs.runOverSpans.call(void 0, input, _chunkGL273L36cjs.yamlSpans.call(void 0, input, keys), planned, locale, "yaml", narrowTarget);
|
|
22
|
+
}
|
|
23
|
+
function analyzeYamlPipeline(input, options) {
|
|
24
|
+
const narrowTarget = _chunkQDLVXAHKcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
25
|
+
const planned = _chunkQDLVXAHKcjs.planRules.call(void 0, options.rules);
|
|
26
|
+
const locale = _chunkQDLVXAHKcjs.getLocaleData.call(void 0, options.locale);
|
|
27
|
+
const keys = _chunkGL273L36cjs.resolveYamlKeys.call(void 0, options.keys);
|
|
28
|
+
_chunkQDLVXAHKcjs.assertNoProtect.call(void 0, options.protect, "yaml");
|
|
29
|
+
return _chunkQDLVXAHKcjs.analyzeOverSpans.call(void 0, input, _chunkGL273L36cjs.yamlSpans.call(void 0, input, keys), planned, locale, "yaml", narrowTarget);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
exports.runYamlPipeline = runYamlPipeline; exports.analyzeYamlPipeline = analyzeYamlPipeline;
|
|
36
|
+
//# sourceMappingURL=chunk-CVJVASBB.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-CVJVASBB.cjs","../src/engine/yaml-pipeline.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACIO,SAAS,eAAA,CAAgB,KAAA,EAAe,OAAA,EAAmC;AAChF,EAAA,MAAM,aAAA,EAAe,mDAAA,OAAoB,CAAQ,UAAU,CAAA;AAC3D,EAAA,MAAM,QAAA,EAAU,yCAAA,OAAU,CAAQ,KAAK,CAAA;AACvC,EAAA,MAAM,OAAA,EAAS,6CAAA,OAAc,CAAQ,MAAM,CAAA;AAC3C,EAAA,MAAM,KAAA,EAAO,+CAAA,OAAgB,CAAQ,IAAI,CAAA;AACzC,EAAA,+CAAA,OAAgB,CAAQ,OAAA,EAAS,MAAM,CAAA;AACvC,EAAA,OAAO,4CAAA,KAAa,EAAO,yCAAA,KAAU,EAAO,IAAI,CAAA,EAAG,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAQ,YAAY,CAAA;AAC1F;AAGO,SAAS,mBAAA,CAAoB,KAAA,EAAe,OAAA,EAAqC;AACtF,EAAA,MAAM,aAAA,EAAe,mDAAA,OAAoB,CAAQ,UAAU,CAAA;AAC3D,EAAA,MAAM,QAAA,EAAU,yCAAA,OAAU,CAAQ,KAAK,CAAA;AACvC,EAAA,MAAM,OAAA,EAAS,6CAAA,OAAc,CAAQ,MAAM,CAAA;AAC3C,EAAA,MAAM,KAAA,EAAO,+CAAA,OAAgB,CAAQ,IAAI,CAAA;AACzC,EAAA,+CAAA,OAAgB,CAAQ,OAAA,EAAS,MAAM,CAAA;AACvC,EAAA,OAAO,gDAAA,KAAiB,EAAO,yCAAA,KAAU,EAAO,IAAI,CAAA,EAAG,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAQ,YAAY,CAAA;AAC9F;ADJA;AACA;AACE;AACA;AACF,6FAAC","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-CVJVASBB.cjs","sourcesContent":[null,"import { yamlSpans } from \"../modes/yaml.js\";\nimport type { Options } from \"../types.js\";\nimport { getLocaleData } from \"./locale.js\";\nimport { resolveNarrowTarget } from \"./narrow-target.js\";\nimport { resolveYamlKeys } from \"./yaml-keys.js\";\nimport { assertNoProtect } from \"./protect.js\";\nimport { planRules } from \"./rule-runner.js\";\nimport { analyzeOverSpans, runOverSpans } from \"./span-runner.js\";\nimport type { Change } from \"./origin.js\";\n\n/**\n * `yaml` mode only, and the only mode pipeline with **no parser dependency at all** — span\n * selection is the specified scan of modes.md 3.8, not a library. There is likewise no\n * `POLYTYPO_MALFORMED_INPUT` counterpart here: with no declared grammar to violate, a file that\n * is not YAML yields few spans or none and comes back byte for byte (modes.md 3.8.3). The only\n * throw this mode adds is `keys`, which is about the call and not the input.\n */\nexport function runYamlPipeline(input: string, options: Partial<Options>): string {\n const narrowTarget = resolveNarrowTarget(options.narrowNbsp);\n const planned = planRules(options.rules);\n const locale = getLocaleData(options.locale);\n const keys = resolveYamlKeys(options.keys);\n assertNoProtect(options.protect, \"yaml\");\n return runOverSpans(input, yamlSpans(input, keys), planned, locale, \"yaml\", narrowTarget);\n}\n\n/** analyze.md §1, `yaml` mode: offsets are into the document, not into a span (analyze.md §6). */\nexport function analyzeYamlPipeline(input: string, options: Partial<Options>): Change[] {\n const narrowTarget = resolveNarrowTarget(options.narrowNbsp);\n const planned = planRules(options.rules);\n const locale = getLocaleData(options.locale);\n const keys = resolveYamlKeys(options.keys);\n assertNoProtect(options.protect, \"yaml\");\n return analyzeOverSpans(input, yamlSpans(input, keys), planned, locale, \"yaml\", narrowTarget);\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PolytypoError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YXUADCFN.js";
|
|
4
4
|
|
|
5
5
|
// src/engine/assert-fixed-mode.ts
|
|
6
6
|
function assertFixedMode(mode, fixed, entryPoint) {
|
|
@@ -14,4 +14,4 @@ function assertFixedMode(mode, fixed, entryPoint) {
|
|
|
14
14
|
export {
|
|
15
15
|
assertFixedMode
|
|
16
16
|
};
|
|
17
|
-
//# sourceMappingURL=chunk-
|
|
17
|
+
//# sourceMappingURL=chunk-FLLMLWN5.js.map
|