polytypo 1.7.0 → 1.8.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/dist/{chunk-GUTUSN4K.js → chunk-4RAZ2EDS.js} +4 -4
- package/dist/{chunk-74I62TZ2.js → chunk-6UQAKZ7L.js} +4 -4
- package/dist/{chunk-JVBK3LG3.js → chunk-EH542ZE4.js} +2 -2
- package/dist/{chunk-25XZKUNP.js → chunk-EQ2JTKYF.js} +1 -1
- package/dist/{chunk-25XZKUNP.js.map → chunk-EQ2JTKYF.js.map} +1 -1
- package/dist/{chunk-U5Y7C2L4.js → chunk-F6HVIPLF.js} +2 -2
- package/dist/{chunk-I2QPXPHX.cjs → chunk-GK5P55K5.cjs} +3 -3
- package/dist/{chunk-I2QPXPHX.cjs.map → chunk-GK5P55K5.cjs.map} +1 -1
- package/dist/{chunk-FMU74VA6.cjs → chunk-GUROIWJY.cjs} +1 -1
- package/dist/{chunk-FMU74VA6.cjs.map → chunk-GUROIWJY.cjs.map} +1 -1
- package/dist/{chunk-IQHYZG2K.cjs → chunk-KAJ3GVK2.cjs} +6 -6
- package/dist/{chunk-IQHYZG2K.cjs.map → chunk-KAJ3GVK2.cjs.map} +1 -1
- package/dist/{chunk-HBIIWBB5.js → chunk-KCKZHLI5.js} +2 -2
- package/dist/chunk-KFDDI4LH.cjs +35 -0
- package/dist/{chunk-X6CI7GWV.cjs.map → chunk-KFDDI4LH.cjs.map} +1 -1
- package/dist/{chunk-MMXKQUAS.cjs → chunk-M3TVDUGX.cjs} +4 -4
- package/dist/{chunk-MMXKQUAS.cjs.map → chunk-M3TVDUGX.cjs.map} +1 -1
- package/dist/{chunk-ITDTGCLJ.js → chunk-PEBD5XTD.js} +2 -2
- package/dist/chunk-UJ3D4DYP.cjs +33 -0
- package/dist/{chunk-33SLJJSZ.cjs.map → chunk-UJ3D4DYP.cjs.map} +1 -1
- package/dist/{chunk-VDLHT5CW.cjs → chunk-UWFI3XV7.cjs} +16 -16
- package/dist/{chunk-VDLHT5CW.cjs.map → chunk-UWFI3XV7.cjs.map} +1 -1
- package/dist/{chunk-54TSHDNC.cjs → chunk-VBHUVDW4.cjs} +115 -54
- package/dist/chunk-VBHUVDW4.cjs.map +1 -0
- package/dist/{chunk-DAIPI5CX.js → chunk-XLTVLET5.js} +2 -2
- package/dist/chunk-YA64BEKC.cjs +31 -0
- package/dist/{chunk-HTCGXDEG.cjs.map → chunk-YA64BEKC.cjs.map} +1 -1
- package/dist/{chunk-JE2MK4CC.js → chunk-YH77XVJB.js} +101 -40
- package/dist/chunk-YH77XVJB.js.map +1 -0
- package/dist/html.cjs +10 -10
- package/dist/html.js +5 -5
- package/dist/index.cjs +18 -18
- package/dist/index.js +8 -8
- package/dist/markdown.cjs +11 -11
- package/dist/markdown.js +6 -6
- package/dist/text.cjs +8 -8
- package/dist/text.js +3 -3
- package/dist/yaml.cjs +10 -10
- package/dist/yaml.js +5 -5
- package/package.json +1 -1
- package/dist/chunk-33SLJJSZ.cjs +0 -33
- package/dist/chunk-54TSHDNC.cjs.map +0 -1
- package/dist/chunk-HTCGXDEG.cjs +0 -31
- package/dist/chunk-JE2MK4CC.js.map +0 -1
- package/dist/chunk-X6CI7GWV.cjs +0 -35
- /package/dist/{chunk-GUTUSN4K.js.map → chunk-4RAZ2EDS.js.map} +0 -0
- /package/dist/{chunk-74I62TZ2.js.map → chunk-6UQAKZ7L.js.map} +0 -0
- /package/dist/{chunk-JVBK3LG3.js.map → chunk-EH542ZE4.js.map} +0 -0
- /package/dist/{chunk-U5Y7C2L4.js.map → chunk-F6HVIPLF.js.map} +0 -0
- /package/dist/{chunk-HBIIWBB5.js.map → chunk-KCKZHLI5.js.map} +0 -0
- /package/dist/{chunk-ITDTGCLJ.js.map → chunk-PEBD5XTD.js.map} +0 -0
- /package/dist/{chunk-DAIPI5CX.js.map → chunk-XLTVLET5.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner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E,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAc,EAAA;AAEhB,EAAA;AACF;AAEO;AAQL,EAAA;AACF;AAWO;AAQL,EAAA;AAGA,EAAA;AACF;AAQO;AAQL,EAAA;AAGF;AAEO;AAQL,EAAA;AACA,EAAA;AACA,EAAA;AAAO,IAAA;AAC8B,IAAA;AACnC,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACgC,IAAA;AACX,IAAA;AACwD,EAAA;AAEjF;AFgDA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-VDLHT5CW.cjs","sourcesContent":[null,"import { toCodePoints } from \"../engine/codepoints.js\";\nimport { isMarker, LINE_MARKER, MARKER } from \"../engine/sentinels.js\";\nimport { PolytypoError } from \"../errors.js\";\nimport type { Edit } from \"../types.js\";\nimport { NO_ORIGIN } from \"../engine/origin.js\";\n\n/**\n * The boundary markers are defined in the engine (src/engine/sentinels.ts), which is where all\n * three non-code-point sentinels live and where their disjointness is maintained. They are\n * re-exported here because the mode layer is what writes them into the array.\n *\n * Which marker separates two spans is decided by the **raw source bytes of the gap between\n * them**, so it is decidable without asking the parser anything and is identical in five\n * runtimes: a gap containing a line terminator gives `LINE_MARKER`, anything else `MARKER`.\n */\nexport { LINE_MARKER, MARKER, isMarker } from \"../engine/sentinels.js\";\n\n/** `BREAK` as the rules define it (`spaces.md` 3.1), tested against the gap's raw source. */\n/** U+0020, the one emitted code point whose meaning is positional (modes.md 3.4, 5 item 2). */\nconst SPACE = 0x20;\n\nconst LINE_TERMINATORS: ReadonlySet<number> = new Set([\n 0x0a, 0x0d, 0x0b, 0x0c, 0x85, 0x2028, 0x2029,\n]);\n\nfunction gapIsLineBoundary(source: string, from: number, to: number): boolean {\n for (let i = from; i < to; i += 1) {\n if (LINE_TERMINATORS.has(source.charCodeAt(i))) return true;\n }\n return false;\n}\n\n/**\n * A processable span, identified by its offsets in the **original source**. Offsets are UTF-16\n * indices into the JS source string, which is what every JS parser reports; they are an\n * implementation detail of this runtime and never reach the rules, which index code points.\n */\nexport interface Span {\n readonly start: number;\n readonly end: number;\n}\n\n/** A span's extent in the concatenated code-point array: `s₀` and `s₁` of modes.md 3.4. */\nexport interface SpanRange {\n readonly first: number;\n readonly last: number;\n}\n\n/**\n * Sort, drop empties, and coalesce spans separated by nothing in the source (modes.md 7.5:\n * a parser that reports one text run as two adjacent nodes must not manufacture a boundary).\n * Overlapping spans are an extractor bug and are rejected rather than silently merged.\n */\nexport function normalizeSpans(spans: readonly Span[]): Span[] {\n const sorted = spans.filter((s) => s.end > s.start).sort((a, b) => a.start - b.start);\n const out: Span[] = [];\n for (const span of sorted) {\n const last = out[out.length - 1];\n if (last === undefined) {\n out.push(span);\n continue;\n }\n if (span.start < last.end) {\n throw new PolytypoError(\n \"POLYTYPO_RULE_CONTRACT\",\n `mode extractor produced overlapping spans (${last.start}, ${last.end}) and (${span.start}, ${span.end})`,\n );\n }\n if (span.start === last.end) {\n out[out.length - 1] = { start: last.start, end: span.end };\n continue;\n }\n out.push(span);\n }\n return out;\n}\n\n/** `S₁ ⌢ [marker] ⌢ S₂ ⌢ … ⌢ Sₘ` (modes.md 3.5 step 2). */\nexport function concatenateSpans(source: string, spans: readonly Span[]): number[] {\n const cp: number[] = [];\n let previous: Span | undefined;\n for (const span of spans) {\n if (previous !== undefined) {\n cp.push(gapIsLineBoundary(source, previous.end, span.start) ? LINE_MARKER : MARKER);\n }\n for (const value of toCodePoints(source.slice(span.start, span.end))) cp.push(value);\n previous = span;\n }\n return cp;\n}\n\n/**\n * The span extents of the array as it stands. Recomputed after every rule, because applying\n * edits shifts every index after the first one — the markers themselves are guaranteed to\n * survive, since no edit may contain one.\n */\nexport function spanRangesOf(cp: readonly number[]): SpanRange[] {\n const ranges: SpanRange[] = [];\n let first = 0;\n for (let i = 0; i < cp.length; i += 1) {\n if (isMarker(cp[i] as number)) {\n ranges.push({ first, last: i - 1 });\n first = i + 1;\n }\n }\n ranges.push({ first, last: cp.length - 1 });\n return ranges;\n}\n\nfunction spanContaining(ranges: readonly SpanRange[], p: number): SpanRange | undefined {\n for (const range of ranges) {\n if (p >= range.first && p <= range.last + 1) return range;\n }\n return undefined;\n}\n\n/**\n * modes.md 3.4, two safety nets, both pure functions of `(p, q, r, s₀, s₁)` — so the verdict is\n * identical on every run, which is what makes redistribution deterministic (modes.md 5, point 3).\n *\n * 1. **No edit may contain a marker.** No rule can produce one; one that does is a bug, and the\n * edit is discarded rather than treated as a redistribution question.\n * 2. **The edge-growth rule.** An edit is discarded if it would place code points at an\n * extremity of its span that were not there before: with `d = q - p + 1` the replaced length\n * and `r` the replacement length, discard when `p = s₀ and r > d`, or `q = s₁ and r > d`.\n *\n * The length test is the whole rule and needs no knowledge of Markdown or HTML syntax. It\n * separates exactly the cases that matter: `\"` → `“` at an edge is 1 → 1 and applies; `--` →\n * `␣–␣` at an edge is 2 → 3 and is discarded, while the same edit interior to a span applies;\n * `(c)` → `©` is 3 → 1 and applies, because shrinking is always safe. An insertion has `d = 0`,\n * so it is discarded exactly when its position coincides with a span edge — the rule this one\n * generalises.\n *\n * **Deletion at an edge is not restricted here**, and must not be: `r > d` is false for a\n * deletion, so this filter never sees one. Deletion at an edge is governed by modes.md 3.3's\n * *Edge tests* clause instead — where a rule asks \"am I at the edge of the text I am allowed to\n * modify\" rather than \"what character is here\", the marker behaves as `NONE`. That clause is the\n * one place a rule may treat a span edge as the end of the text, it exists because `spaces` is\n * the only rule that deletes, and 3.3 states the division: **a rule that deletes must treat a\n * span edge as the end of the text; a rule that replaces or inserts must not, and is governed by\n * this filter.** The single test that claims the clause is `spaces.md` 3.2 step 4.\n */\nexport function filterBoundaryEdits(\n cp: readonly number[],\n edits: readonly Edit[],\n ranges: readonly SpanRange[],\n): Edit[] {\n const out: Edit[] = [];\n for (const edit of edits) {\n let containsMarker = false;\n for (let i = edit.start; i < edit.end; i += 1) {\n if (isMarker(cp[i] as number)) {\n containsMarker = true;\n break;\n }\n }\n if (containsMarker) continue;\n\n // `[start, end)` in the engine's half-open form is `cp[p … q]` with p = start, q = end - 1;\n // an insertion is `q = p - 1`, which falls out of the same expression.\n const p = edit.start;\n const q = edit.end - 1;\n const d = edit.end - edit.start;\n const r = edit.replacement.length;\n const span = spanContaining(ranges, p);\n if (span !== undefined && (p === span.first || q === span.last)) {\n if (r > d) continue;\n // The character clause. `r > d` is not the rule, only a formalisation of it that misses\n // `r === d`: `dashes` P3 admits a run of THREE dashes, so `---` -> `␣–␣` is 3 -> 3 and the\n // length test sees nothing while U+0020 lands on both extremities anyway. Testing the\n // character catches it, and only U+0020 needs testing — it is the one code point any rule\n // emits whose meaning comes from its position rather than from itself (modes.md 5 item 2).\n const first = edit.replacement[0];\n const last = edit.replacement[r - 1];\n if (r > 0 && p === span.first && first === SPACE && cp[p] !== SPACE) continue;\n if (r > 0 && q === span.last && last === SPACE && cp[q] !== SPACE) continue;\n }\n\n out.push(edit);\n }\n return out;\n}\n\n/** Redistribute the transformed array back to one piece per span (modes.md 3.5 step 4). */\nexport function splitOnMarker(cp: readonly number[], expected: number): number[][] {\n const pieces: number[][] = [[]];\n for (const value of cp) {\n if (isMarker(value)) {\n pieces.push([]);\n continue;\n }\n (pieces[pieces.length - 1] as number[]).push(value);\n }\n if (pieces.length !== expected) {\n throw new PolytypoError(\n \"POLYTYPO_RULE_CONTRACT\",\n `boundary markers did not survive the pipeline: expected ${expected} spans, found ${pieces.length}`,\n );\n }\n return pieces;\n}\n\n/**\n * The origin map for `concatenateSpans` (analyze.md §2): for every code point of the joined\n * array, the code-point offset of the character it came from IN THE DOCUMENT, and NO_ORIGIN for\n * the markers, which came from nowhere. `Span` bounds are native string indices, so the\n * conversion to code-point offsets happens here and not in the caller — this is the one place\n * that knows both coordinate systems.\n */\nexport function originOfSpans(source: string, spans: readonly Span[]): number[] {\n const codePointIndexOf = new Array<number>(source.length + 1);\n let cpIndex = 0;\n for (let i = 0; i < source.length;) {\n codePointIndexOf[i] = cpIndex;\n const code = source.codePointAt(i) as number;\n const width = code > 0xffff ? 2 : 1;\n if (width === 2) codePointIndexOf[i + 1] = cpIndex;\n i += width;\n cpIndex += 1;\n }\n codePointIndexOf[source.length] = cpIndex;\n\n const origin: number[] = [];\n let previous: Span | undefined;\n for (const span of spans) {\n if (previous !== undefined) origin.push(NO_ORIGIN);\n const base = codePointIndexOf[span.start] as number;\n const length = toCodePoints(source.slice(span.start, span.end)).length;\n for (let k = 0; k < length; k += 1) origin.push(base + k);\n previous = span;\n }\n return origin;\n}\n","import {\n concatenateSpans,\n filterBoundaryEdits,\n normalizeSpans,\n originOfSpans,\n spanRangesOf,\n splitOnMarker,\n type Span,\n} from \"../modes/spans.js\";\nimport { RULES } from \"../rules/registry.js\";\nimport type { LocaleData, Mode, RuleId } from \"../types.js\";\nimport { applyEdits } from \"./edits.js\";\nimport { fromCodePoints, toCodePoints } from \"./codepoints.js\";\nimport type { Change } from \"./origin.js\";\nimport { runRulesRecording } from \"./rule-runner.js\";\n\n/**\n * The same sequence as `runRules` (`./rule-runner.js`), with the two boundary filters of\n * modes.md 3.4 interposed. The span extents are recomputed after every rule, because applying\n * an edit shifts every index after it; the markers themselves always survive, since no edit may\n * contain one.\n */\nfunction runRulesOverSpans(\n cp: readonly number[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): readonly number[] {\n let current = cp;\n for (const id of planned) {\n const rule = RULES[id];\n if (rule === undefined) continue;\n const edits = rule.apply({ cp: current, locale, mode, narrowTarget });\n current = applyEdits(current, filterBoundaryEdits(current, edits, spanRangesOf(current)), id);\n }\n return current;\n}\n\n/**\n * modes.md 3.5. The pipeline runs **once**, over the marker-separated concatenation of every\n * processable span — not per span, which would pair quotation marks in isolation, and not over a\n * naive concatenation, which would manufacture adjacencies the document does not have.\n *\n * The output is the input with a set of disjoint substring replacements applied and nothing else\n * (modes.md 4). A span whose content the rules did not change contributes no replacement, so a\n * document needing no changes comes back byte-identical; the parser located the spans and was\n * then discarded, and the document is never serialised.\n */\ninterface Replacement {\n readonly span: Span;\n readonly text: string;\n}\n\n/** One text unit: the marker-separated concatenation, the pipeline, and the pieces it produced. */\nfunction replacementsOfUnit(\n source: string,\n spans: readonly Span[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): Replacement[] {\n const normalized = normalizeSpans(spans);\n if (normalized.length === 0) return [];\n const transformed = runRulesOverSpans(\n concatenateSpans(source, normalized),\n planned,\n locale,\n mode,\n narrowTarget,\n );\n const pieces = splitOnMarker(transformed, normalized.length);\n return normalized.map((span, i) => ({ span, text: fromCodePoints(pieces[i] as number[]) }));\n}\n\n/** modes.md 4: the source with disjoint replacements applied at recorded offsets, nothing else. */\nfunction emit(source: string, replacements: readonly Replacement[]): string {\n let out = \"\";\n let cursor = 0;\n for (const { span, text } of replacements) {\n const original = source.slice(span.start, span.end);\n out += source.slice(cursor, span.start);\n out += text === original ? original : text;\n cursor = span.end;\n }\n return out + source.slice(cursor);\n}\n\nexport function runOverSpans(\n source: string,\n spans: readonly Span[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): string {\n return emit(source, replacementsOfUnit(source, spans, planned, locale, mode, narrowTarget));\n}\n\n/**\n * modes.md 3.1 and 3.5 step 3 (spec 1.7.0). A document has one text unit, except in `markdown`\n * with `frontmatterKeys`, where the frontmatter block's spans form a unit of their own. The\n * pipeline runs once per unit, and the two edit sets are disjoint because no span of one unit lies\n * inside the other — which is exactly what `markdownSpans` skipping the block guarantees.\n *\n * Only step 5 is shared: the source is emitted once, with every unit's replacements in document\n * order.\n */\nexport function runOverUnits(\n source: string,\n units: readonly (readonly Span[])[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): string {\n const replacements = units\n .flatMap((spans) => replacementsOfUnit(source, spans, planned, locale, mode, narrowTarget))\n .sort((a, b) => a.span.start - b.span.start);\n return emit(source, replacements);\n}\n\n/**\n * `runOverSpans`, reporting instead of applying (analyze.md §1). The span table supplies the\n * origin map, so every change comes back in DOCUMENT coordinates — analyze.md §6 names a\n * runtime that reports span-local offsets here as the mistake that passes every text-mode test.\n */\n/** `analyzeOverSpans` per text unit (modes.md 3.1), reported in document order. */\nexport function analyzeOverUnits(\n source: string,\n units: readonly (readonly Span[])[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): Change[] {\n return units\n .flatMap((spans) => analyzeOverSpans(source, spans, planned, locale, mode, narrowTarget))\n .sort((a, b) => a.start - b.start);\n}\n\nexport function analyzeOverSpans(\n source: string,\n spans: readonly Span[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): Change[] {\n const normalized = normalizeSpans(spans);\n if (normalized.length === 0) return [];\n return runRulesRecording(\n concatenateSpans(source, normalized),\n planned,\n locale,\n mode,\n narrowTarget,\n originOfSpans(source, normalized),\n toCodePoints(source).length,\n (current, edits) => filterBoundaryEdits(current, edits, spanRangesOf(current)),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-UWFI3XV7.cjs","../src/modes/spans.ts","../src/engine/span-runner.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACMA,IAAM,MAAA,EAAQ,EAAA;AAEd,IAAM,iBAAA,kBAAwC,IAAI,GAAA,CAAI;AAAA,EACpD,EAAA;AAAA,EAAM,EAAA;AAAA,EAAM,EAAA;AAAA,EAAM,EAAA;AAAA,EAAM,GAAA;AAAA,EAAM,IAAA;AAAA,EAAQ;AACxC,CAAC,CAAA;AAED,SAAS,iBAAA,CAAkB,MAAA,EAAgB,IAAA,EAAc,EAAA,EAAqB;AAC5E,EAAA,IAAA,CAAA,IAAS,EAAA,EAAI,IAAA,EAAM,EAAA,EAAI,EAAA,EAAI,EAAA,GAAK,CAAA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CAAA;AAAA,MACR,wBAAA;AAAA,MACA,CAAA,wDAAA,EAA2D,QAAQ,CAAA,cAAA,EAAiB,MAAA,CAAO,MAAM,CAAA;AAAA,IAAA;AACnG,EAAA;AAEF,EAAA;AACF;AASO;AACL,EAAA;AACA,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAW,EAAA;AAEb,EAAA;AAEA,EAAA;AACA,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAW,EAAA;AAEb,EAAA;AACF;ADlFA;AACA;AEjIA;AAOE,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAA4F,EAAA;AAE9F,EAAA;AACF;AAkBA;AAQE,EAAA;AACA,EAAA;AACA,EAAA;AAAoB,IAAA;AACiB,IAAA;AACnC,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AAEF,EAAA;AACA,EAAA;AACF;AAGA;AACE,EAAA;AACA,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAc,EAAA;AAEhB,EAAA;AACF;AAEO;AAQL,EAAA;AACF;AAWO;AAQL,EAAA;AAGA,EAAA;AACF;AAQO;AAQL,EAAA;AAGF;AAEO;AAQL,EAAA;AACA,EAAA;AACA,EAAA;AAAO,IAAA;AAC8B,IAAA;AACnC,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACgC,IAAA;AACX,IAAA;AACwD,EAAA;AAEjF;AFgDA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-UWFI3XV7.cjs","sourcesContent":[null,"import { toCodePoints } from \"../engine/codepoints.js\";\nimport { isMarker, LINE_MARKER, MARKER } from \"../engine/sentinels.js\";\nimport { PolytypoError } from \"../errors.js\";\nimport type { Edit } from \"../types.js\";\nimport { NO_ORIGIN } from \"../engine/origin.js\";\n\n/**\n * The boundary markers are defined in the engine (src/engine/sentinels.ts), which is where all\n * three non-code-point sentinels live and where their disjointness is maintained. They are\n * re-exported here because the mode layer is what writes them into the array.\n *\n * Which marker separates two spans is decided by the **raw source bytes of the gap between\n * them**, so it is decidable without asking the parser anything and is identical in five\n * runtimes: a gap containing a line terminator gives `LINE_MARKER`, anything else `MARKER`.\n */\nexport { LINE_MARKER, MARKER, isMarker } from \"../engine/sentinels.js\";\n\n/** `BREAK` as the rules define it (`spaces.md` 3.1), tested against the gap's raw source. */\n/** U+0020, the one emitted code point whose meaning is positional (modes.md 3.4, 5 item 2). */\nconst SPACE = 0x20;\n\nconst LINE_TERMINATORS: ReadonlySet<number> = new Set([\n 0x0a, 0x0d, 0x0b, 0x0c, 0x85, 0x2028, 0x2029,\n]);\n\nfunction gapIsLineBoundary(source: string, from: number, to: number): boolean {\n for (let i = from; i < to; i += 1) {\n if (LINE_TERMINATORS.has(source.charCodeAt(i))) return true;\n }\n return false;\n}\n\n/**\n * A processable span, identified by its offsets in the **original source**. Offsets are UTF-16\n * indices into the JS source string, which is what every JS parser reports; they are an\n * implementation detail of this runtime and never reach the rules, which index code points.\n */\nexport interface Span {\n readonly start: number;\n readonly end: number;\n}\n\n/** A span's extent in the concatenated code-point array: `s₀` and `s₁` of modes.md 3.4. */\nexport interface SpanRange {\n readonly first: number;\n readonly last: number;\n}\n\n/**\n * Sort, drop empties, and coalesce spans separated by nothing in the source (modes.md 7.5:\n * a parser that reports one text run as two adjacent nodes must not manufacture a boundary).\n * Overlapping spans are an extractor bug and are rejected rather than silently merged.\n */\nexport function normalizeSpans(spans: readonly Span[]): Span[] {\n const sorted = spans.filter((s) => s.end > s.start).sort((a, b) => a.start - b.start);\n const out: Span[] = [];\n for (const span of sorted) {\n const last = out[out.length - 1];\n if (last === undefined) {\n out.push(span);\n continue;\n }\n if (span.start < last.end) {\n throw new PolytypoError(\n \"POLYTYPO_RULE_CONTRACT\",\n `mode extractor produced overlapping spans (${last.start}, ${last.end}) and (${span.start}, ${span.end})`,\n );\n }\n if (span.start === last.end) {\n out[out.length - 1] = { start: last.start, end: span.end };\n continue;\n }\n out.push(span);\n }\n return out;\n}\n\n/** `S₁ ⌢ [marker] ⌢ S₂ ⌢ … ⌢ Sₘ` (modes.md 3.5 step 2). */\nexport function concatenateSpans(source: string, spans: readonly Span[]): number[] {\n const cp: number[] = [];\n let previous: Span | undefined;\n for (const span of spans) {\n if (previous !== undefined) {\n cp.push(gapIsLineBoundary(source, previous.end, span.start) ? LINE_MARKER : MARKER);\n }\n for (const value of toCodePoints(source.slice(span.start, span.end))) cp.push(value);\n previous = span;\n }\n return cp;\n}\n\n/**\n * The span extents of the array as it stands. Recomputed after every rule, because applying\n * edits shifts every index after the first one — the markers themselves are guaranteed to\n * survive, since no edit may contain one.\n */\nexport function spanRangesOf(cp: readonly number[]): SpanRange[] {\n const ranges: SpanRange[] = [];\n let first = 0;\n for (let i = 0; i < cp.length; i += 1) {\n if (isMarker(cp[i] as number)) {\n ranges.push({ first, last: i - 1 });\n first = i + 1;\n }\n }\n ranges.push({ first, last: cp.length - 1 });\n return ranges;\n}\n\nfunction spanContaining(ranges: readonly SpanRange[], p: number): SpanRange | undefined {\n for (const range of ranges) {\n if (p >= range.first && p <= range.last + 1) return range;\n }\n return undefined;\n}\n\n/**\n * modes.md 3.4, two safety nets, both pure functions of `(p, q, r, s₀, s₁)` — so the verdict is\n * identical on every run, which is what makes redistribution deterministic (modes.md 5, point 3).\n *\n * 1. **No edit may contain a marker.** No rule can produce one; one that does is a bug, and the\n * edit is discarded rather than treated as a redistribution question.\n * 2. **The edge-growth rule.** An edit is discarded if it would place code points at an\n * extremity of its span that were not there before: with `d = q - p + 1` the replaced length\n * and `r` the replacement length, discard when `p = s₀ and r > d`, or `q = s₁ and r > d`.\n *\n * The length test is the whole rule and needs no knowledge of Markdown or HTML syntax. It\n * separates exactly the cases that matter: `\"` → `“` at an edge is 1 → 1 and applies; `--` →\n * `␣–␣` at an edge is 2 → 3 and is discarded, while the same edit interior to a span applies;\n * `(c)` → `©` is 3 → 1 and applies, because shrinking is always safe. An insertion has `d = 0`,\n * so it is discarded exactly when its position coincides with a span edge — the rule this one\n * generalises.\n *\n * **Deletion at an edge is not restricted here**, and must not be: `r > d` is false for a\n * deletion, so this filter never sees one. Deletion at an edge is governed by modes.md 3.3's\n * *Edge tests* clause instead — where a rule asks \"am I at the edge of the text I am allowed to\n * modify\" rather than \"what character is here\", the marker behaves as `NONE`. That clause is the\n * one place a rule may treat a span edge as the end of the text, it exists because `spaces` is\n * the only rule that deletes, and 3.3 states the division: **a rule that deletes must treat a\n * span edge as the end of the text; a rule that replaces or inserts must not, and is governed by\n * this filter.** The single test that claims the clause is `spaces.md` 3.2 step 4.\n */\nexport function filterBoundaryEdits(\n cp: readonly number[],\n edits: readonly Edit[],\n ranges: readonly SpanRange[],\n): Edit[] {\n const out: Edit[] = [];\n for (const edit of edits) {\n let containsMarker = false;\n for (let i = edit.start; i < edit.end; i += 1) {\n if (isMarker(cp[i] as number)) {\n containsMarker = true;\n break;\n }\n }\n if (containsMarker) continue;\n\n // `[start, end)` in the engine's half-open form is `cp[p … q]` with p = start, q = end - 1;\n // an insertion is `q = p - 1`, which falls out of the same expression.\n const p = edit.start;\n const q = edit.end - 1;\n const d = edit.end - edit.start;\n const r = edit.replacement.length;\n const span = spanContaining(ranges, p);\n if (span !== undefined && (p === span.first || q === span.last)) {\n if (r > d) continue;\n // The character clause. `r > d` is not the rule, only a formalisation of it that misses\n // `r === d`: `dashes` P3 admits a run of THREE dashes, so `---` -> `␣–␣` is 3 -> 3 and the\n // length test sees nothing while U+0020 lands on both extremities anyway. Testing the\n // character catches it, and only U+0020 needs testing — it is the one code point any rule\n // emits whose meaning comes from its position rather than from itself (modes.md 5 item 2).\n const first = edit.replacement[0];\n const last = edit.replacement[r - 1];\n if (r > 0 && p === span.first && first === SPACE && cp[p] !== SPACE) continue;\n if (r > 0 && q === span.last && last === SPACE && cp[q] !== SPACE) continue;\n }\n\n out.push(edit);\n }\n return out;\n}\n\n/** Redistribute the transformed array back to one piece per span (modes.md 3.5 step 4). */\nexport function splitOnMarker(cp: readonly number[], expected: number): number[][] {\n const pieces: number[][] = [[]];\n for (const value of cp) {\n if (isMarker(value)) {\n pieces.push([]);\n continue;\n }\n (pieces[pieces.length - 1] as number[]).push(value);\n }\n if (pieces.length !== expected) {\n throw new PolytypoError(\n \"POLYTYPO_RULE_CONTRACT\",\n `boundary markers did not survive the pipeline: expected ${expected} spans, found ${pieces.length}`,\n );\n }\n return pieces;\n}\n\n/**\n * The origin map for `concatenateSpans` (analyze.md §2): for every code point of the joined\n * array, the code-point offset of the character it came from IN THE DOCUMENT, and NO_ORIGIN for\n * the markers, which came from nowhere. `Span` bounds are native string indices, so the\n * conversion to code-point offsets happens here and not in the caller — this is the one place\n * that knows both coordinate systems.\n */\nexport function originOfSpans(source: string, spans: readonly Span[]): number[] {\n const codePointIndexOf = new Array<number>(source.length + 1);\n let cpIndex = 0;\n for (let i = 0; i < source.length;) {\n codePointIndexOf[i] = cpIndex;\n const code = source.codePointAt(i) as number;\n const width = code > 0xffff ? 2 : 1;\n if (width === 2) codePointIndexOf[i + 1] = cpIndex;\n i += width;\n cpIndex += 1;\n }\n codePointIndexOf[source.length] = cpIndex;\n\n const origin: number[] = [];\n let previous: Span | undefined;\n for (const span of spans) {\n if (previous !== undefined) origin.push(NO_ORIGIN);\n const base = codePointIndexOf[span.start] as number;\n const length = toCodePoints(source.slice(span.start, span.end)).length;\n for (let k = 0; k < length; k += 1) origin.push(base + k);\n previous = span;\n }\n return origin;\n}\n","import {\n concatenateSpans,\n filterBoundaryEdits,\n normalizeSpans,\n originOfSpans,\n spanRangesOf,\n splitOnMarker,\n type Span,\n} from \"../modes/spans.js\";\nimport { RULES } from \"../rules/registry.js\";\nimport type { LocaleData, Mode, RuleId } from \"../types.js\";\nimport { applyEdits } from \"./edits.js\";\nimport { fromCodePoints, toCodePoints } from \"./codepoints.js\";\nimport type { Change } from \"./origin.js\";\nimport { runRulesRecording } from \"./rule-runner.js\";\n\n/**\n * The same sequence as `runRules` (`./rule-runner.js`), with the two boundary filters of\n * modes.md 3.4 interposed. The span extents are recomputed after every rule, because applying\n * an edit shifts every index after it; the markers themselves always survive, since no edit may\n * contain one.\n */\nfunction runRulesOverSpans(\n cp: readonly number[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): readonly number[] {\n let current = cp;\n for (const id of planned) {\n const rule = RULES[id];\n if (rule === undefined) continue;\n const edits = rule.apply({ cp: current, locale, mode, narrowTarget });\n current = applyEdits(current, filterBoundaryEdits(current, edits, spanRangesOf(current)), id);\n }\n return current;\n}\n\n/**\n * modes.md 3.5. The pipeline runs **once**, over the marker-separated concatenation of every\n * processable span — not per span, which would pair quotation marks in isolation, and not over a\n * naive concatenation, which would manufacture adjacencies the document does not have.\n *\n * The output is the input with a set of disjoint substring replacements applied and nothing else\n * (modes.md 4). A span whose content the rules did not change contributes no replacement, so a\n * document needing no changes comes back byte-identical; the parser located the spans and was\n * then discarded, and the document is never serialised.\n */\ninterface Replacement {\n readonly span: Span;\n readonly text: string;\n}\n\n/** One text unit: the marker-separated concatenation, the pipeline, and the pieces it produced. */\nfunction replacementsOfUnit(\n source: string,\n spans: readonly Span[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): Replacement[] {\n const normalized = normalizeSpans(spans);\n if (normalized.length === 0) return [];\n const transformed = runRulesOverSpans(\n concatenateSpans(source, normalized),\n planned,\n locale,\n mode,\n narrowTarget,\n );\n const pieces = splitOnMarker(transformed, normalized.length);\n return normalized.map((span, i) => ({ span, text: fromCodePoints(pieces[i] as number[]) }));\n}\n\n/** modes.md 4: the source with disjoint replacements applied at recorded offsets, nothing else. */\nfunction emit(source: string, replacements: readonly Replacement[]): string {\n let out = \"\";\n let cursor = 0;\n for (const { span, text } of replacements) {\n const original = source.slice(span.start, span.end);\n out += source.slice(cursor, span.start);\n out += text === original ? original : text;\n cursor = span.end;\n }\n return out + source.slice(cursor);\n}\n\nexport function runOverSpans(\n source: string,\n spans: readonly Span[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): string {\n return emit(source, replacementsOfUnit(source, spans, planned, locale, mode, narrowTarget));\n}\n\n/**\n * modes.md 3.1 and 3.5 step 3 (spec 1.7.0). A document has one text unit, except in `markdown`\n * with `frontmatterKeys`, where the frontmatter block's spans form a unit of their own. The\n * pipeline runs once per unit, and the two edit sets are disjoint because no span of one unit lies\n * inside the other — which is exactly what `markdownSpans` skipping the block guarantees.\n *\n * Only step 5 is shared: the source is emitted once, with every unit's replacements in document\n * order.\n */\nexport function runOverUnits(\n source: string,\n units: readonly (readonly Span[])[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): string {\n const replacements = units\n .flatMap((spans) => replacementsOfUnit(source, spans, planned, locale, mode, narrowTarget))\n .sort((a, b) => a.span.start - b.span.start);\n return emit(source, replacements);\n}\n\n/**\n * `runOverSpans`, reporting instead of applying (analyze.md §1). The span table supplies the\n * origin map, so every change comes back in DOCUMENT coordinates — analyze.md §6 names a\n * runtime that reports span-local offsets here as the mistake that passes every text-mode test.\n */\n/** `analyzeOverSpans` per text unit (modes.md 3.1), reported in document order. */\nexport function analyzeOverUnits(\n source: string,\n units: readonly (readonly Span[])[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): Change[] {\n return units\n .flatMap((spans) => analyzeOverSpans(source, spans, planned, locale, mode, narrowTarget))\n .sort((a, b) => a.start - b.start);\n}\n\nexport function analyzeOverSpans(\n source: string,\n spans: readonly Span[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): Change[] {\n const normalized = normalizeSpans(spans);\n if (normalized.length === 0) return [];\n return runRulesRecording(\n concatenateSpans(source, normalized),\n planned,\n locale,\n mode,\n narrowTarget,\n originOfSpans(source, normalized),\n toCodePoints(source).length,\n (current, edits) => filterBoundaryEdits(current, edits, spanRangesOf(current)),\n );\n}\n"]}
|
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkM3TVDUGXcjs = require('./chunk-M3TVDUGX.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkKAJ3GVK2cjs = require('./chunk-KAJ3GVK2.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkUWFI3XV7cjs = require('./chunk-UWFI3XV7.cjs');
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
19
|
+
var _chunkGUROIWJYcjs = require('./chunk-GUROIWJY.cjs');
|
|
20
20
|
|
|
21
21
|
// src/modes/markdown.ts
|
|
22
22
|
var _micromark = require('micromark');
|
|
@@ -52,8 +52,14 @@ var SKIPPED_TOKEN_TYPES = /* @__PURE__ */ new Set([
|
|
|
52
52
|
// These are `micromark-extension-frontmatter`'s own token types, one per matter. An earlier
|
|
53
53
|
// revision listed `"frontmatter"`, which the extension never emits: the block was skipped only
|
|
54
54
|
// because its content arrives as `yamlValue`/`tomlValue` rather than `data`, so the entry that
|
|
55
|
-
// was supposed to do the work did none.
|
|
56
|
-
//
|
|
55
|
+
// was supposed to do the work did none.
|
|
56
|
+
//
|
|
57
|
+
// Since spec 1.8.0 the skip is 3.7.3a's mask, not this: a located block reaches the parser as
|
|
58
|
+
// blanks, so the extension cannot see one. The extension stays because it is measured inert —
|
|
59
|
+
// `tests/modes/frontmatter-keys.test.ts` asserts over every edge document that it never finds
|
|
60
|
+
// a block the scan denies — and because removing a working locator that costs nothing would be
|
|
61
|
+
// a change with no problem behind it. What the test would catch is the case that would matter:
|
|
62
|
+
// the two disagreeing about whether a document has a block at all.
|
|
57
63
|
"yaml",
|
|
58
64
|
"toml"
|
|
59
65
|
]);
|
|
@@ -101,7 +107,7 @@ function updateElementStack(stack, tag, caseSensitive) {
|
|
|
101
107
|
if (stack[stack.length - 1] === name) stack.pop();
|
|
102
108
|
return;
|
|
103
109
|
}
|
|
104
|
-
if (!parsed.selfClosing &&
|
|
110
|
+
if (!parsed.selfClosing && _chunkM3TVDUGXcjs.isSkippedElement.call(void 0, name)) stack.push(name);
|
|
105
111
|
}
|
|
106
112
|
function tokenize(source, extensions) {
|
|
107
113
|
return _micromark.postprocess.call(void 0,
|
|
@@ -111,12 +117,12 @@ function tokenize(source, extensions) {
|
|
|
111
117
|
function resolveDialect(dialect) {
|
|
112
118
|
if (dialect === "commonmark" || dialect === "mdx") return dialect;
|
|
113
119
|
if (dialect === void 0) {
|
|
114
|
-
throw new (0,
|
|
120
|
+
throw new (0, _chunkGUROIWJYcjs.PolytypoError)(
|
|
115
121
|
"POLYTYPO_INVALID_DIALECT",
|
|
116
122
|
'Mode "markdown" requires a dialect. Expected "commonmark" or "mdx"; there is no default.'
|
|
117
123
|
);
|
|
118
124
|
}
|
|
119
|
-
throw new (0,
|
|
125
|
+
throw new (0, _chunkGUROIWJYcjs.PolytypoError)(
|
|
120
126
|
"POLYTYPO_INVALID_DIALECT",
|
|
121
127
|
`Unknown dialect "${String(dialect)}". Expected "commonmark" or "mdx".`
|
|
122
128
|
);
|
|
@@ -126,8 +132,63 @@ function extensionsFor(dialect) {
|
|
|
126
132
|
const fm = _micromarkextensionfrontmatter.frontmatter.call(void 0, [...FRONTMATTER_MATTERS]);
|
|
127
133
|
return dialect === "mdx" ? [fm, _micromarkextensiongfm.gfm.call(void 0, ), _micromarkextensionmdxjs.mdxjs.call(void 0, )] : [fm, _micromarkextensiongfm.gfm.call(void 0, )];
|
|
128
134
|
}
|
|
135
|
+
var YAML_DELIMITER = "---";
|
|
136
|
+
var TOML_DELIMITER = "+++";
|
|
137
|
+
var TAB = 9;
|
|
138
|
+
var LF = 10;
|
|
139
|
+
var CR = 13;
|
|
140
|
+
var SPACE = 32;
|
|
141
|
+
var BOM = 65279;
|
|
142
|
+
function markdownLineFrom(source, start) {
|
|
143
|
+
for (let i = start; i < source.length; i += 1) {
|
|
144
|
+
const unit = source.charCodeAt(i);
|
|
145
|
+
if (unit === LF) return { end: i, next: i + 1 };
|
|
146
|
+
if (unit === CR) return { end: i, next: source.charCodeAt(i + 1) === LF ? i + 2 : i + 1 };
|
|
147
|
+
}
|
|
148
|
+
return { end: source.length, next: source.length };
|
|
149
|
+
}
|
|
150
|
+
function isBlankRun(source, from, to) {
|
|
151
|
+
for (let i = from; i < to; i += 1) {
|
|
152
|
+
const unit = source.charCodeAt(i);
|
|
153
|
+
if (unit !== SPACE && unit !== TAB) return false;
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
function isDelimiterLine(source, start, line, delimiter) {
|
|
158
|
+
return source.startsWith(delimiter, start) && isBlankRun(source, start + delimiter.length, line.end);
|
|
159
|
+
}
|
|
160
|
+
function locateFrontmatter(source) {
|
|
161
|
+
const start = source.charCodeAt(0) === BOM ? 1 : 0;
|
|
162
|
+
const matter = source.startsWith(YAML_DELIMITER, start) ? "yaml" : source.startsWith(TOML_DELIMITER, start) ? "toml" : null;
|
|
163
|
+
if (matter === null) return null;
|
|
164
|
+
const delimiter = matter === "yaml" ? YAML_DELIMITER : TOML_DELIMITER;
|
|
165
|
+
const opener = markdownLineFrom(source, start);
|
|
166
|
+
if (!isBlankRun(source, start + delimiter.length, opener.end)) return null;
|
|
167
|
+
const contentStart = opener.next;
|
|
168
|
+
for (let at = contentStart; at < source.length; ) {
|
|
169
|
+
const line = markdownLineFrom(source, at);
|
|
170
|
+
if (isDelimiterLine(source, at, line, delimiter)) {
|
|
171
|
+
return { matter, start, end: line.end, contentStart, contentEnd: at };
|
|
172
|
+
}
|
|
173
|
+
at = line.next;
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
function maskFrontmatter(source, block) {
|
|
178
|
+
if (block === null) return source;
|
|
179
|
+
let masked = "";
|
|
180
|
+
for (let i = 0; i < block.end; i += 1) {
|
|
181
|
+
const unit = source.charCodeAt(i);
|
|
182
|
+
masked += unit === LF || unit === CR ? source[i] : " ";
|
|
183
|
+
}
|
|
184
|
+
return masked + source.slice(block.end);
|
|
185
|
+
}
|
|
129
186
|
function markdownSpans(source, dialect) {
|
|
130
|
-
const
|
|
187
|
+
const block = locateFrontmatter(source);
|
|
188
|
+
const masked = maskFrontmatter(source, block);
|
|
189
|
+
const shift = masked.charCodeAt(0) === BOM ? 1 : 0;
|
|
190
|
+
const text = shift === 0 ? masked : masked.slice(shift);
|
|
191
|
+
const events = _chunkM3TVDUGXcjs.wrapParserErrors.call(void 0, dialect, () => tokenize(text, extensionsFor(dialect)));
|
|
131
192
|
const spans = [];
|
|
132
193
|
const elementStack = [];
|
|
133
194
|
let skipDepth = 0;
|
|
@@ -141,7 +202,7 @@ function markdownSpans(source, dialect) {
|
|
|
141
202
|
if (kind === "enter") {
|
|
142
203
|
updateElementStack(
|
|
143
204
|
elementStack,
|
|
144
|
-
|
|
205
|
+
text.slice(token.start.offset, token.end.offset),
|
|
145
206
|
type !== "htmlText"
|
|
146
207
|
);
|
|
147
208
|
}
|
|
@@ -150,9 +211,9 @@ function markdownSpans(source, dialect) {
|
|
|
150
211
|
}
|
|
151
212
|
if (type === "htmlFlow") {
|
|
152
213
|
if (kind === "enter" && skipDepth === 0 && elementStack.length === 0) {
|
|
153
|
-
for (const span of
|
|
154
|
-
|
|
155
|
-
token.start.offset
|
|
214
|
+
for (const span of _chunkM3TVDUGXcjs.htmlFragmentSpans.call(void 0,
|
|
215
|
+
text.slice(token.start.offset, token.end.offset),
|
|
216
|
+
token.start.offset + shift
|
|
156
217
|
)) {
|
|
157
218
|
spans.push(span);
|
|
158
219
|
}
|
|
@@ -161,64 +222,64 @@ function markdownSpans(source, dialect) {
|
|
|
161
222
|
continue;
|
|
162
223
|
}
|
|
163
224
|
if (kind === "enter" && type === "data" && skipDepth === 0 && elementStack.length === 0) {
|
|
164
|
-
spans.push({ start: token.start.offset, end: token.end.offset });
|
|
225
|
+
spans.push({ start: token.start.offset + shift, end: token.end.offset + shift });
|
|
165
226
|
}
|
|
166
227
|
}
|
|
167
|
-
return spans;
|
|
228
|
+
if (block === null) return spans;
|
|
229
|
+
return spans.flatMap((span) => {
|
|
230
|
+
if (span.start >= block.end) return [span];
|
|
231
|
+
if (span.end <= block.end) return [];
|
|
232
|
+
return [{ start: block.end, end: span.end }];
|
|
233
|
+
});
|
|
168
234
|
}
|
|
169
|
-
function
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (kind === "enter") {
|
|
180
|
-
inBlock = true;
|
|
181
|
-
continue;
|
|
235
|
+
function declinedContentRanges(content) {
|
|
236
|
+
const declined = [];
|
|
237
|
+
let start = 0;
|
|
238
|
+
while (start < content.length) {
|
|
239
|
+
const lf = content.indexOf("\n", start);
|
|
240
|
+
const next = lf === -1 ? content.length : lf + 1;
|
|
241
|
+
for (let i = start; i < next; i += 1) {
|
|
242
|
+
if (content.charCodeAt(i) === CR && content.charCodeAt(i + 1) !== LF) {
|
|
243
|
+
declined.push({ start, end: next });
|
|
244
|
+
break;
|
|
182
245
|
}
|
|
183
|
-
break;
|
|
184
246
|
}
|
|
185
|
-
|
|
186
|
-
if (kind !== "enter") continue;
|
|
187
|
-
if (type === "yamlFence") {
|
|
188
|
-
if (contentStart >= 0) contentEnd = token.start.offset;
|
|
189
|
-
continue;
|
|
190
|
-
}
|
|
191
|
-
if (type === "lineEnding" && contentStart < 0) contentStart = token.end.offset;
|
|
247
|
+
start = next;
|
|
192
248
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
249
|
+
return declined;
|
|
250
|
+
}
|
|
251
|
+
function frontmatterSpans(source, frontmatterKeys) {
|
|
252
|
+
if (frontmatterKeys.length === 0) return [];
|
|
253
|
+
const block = locateFrontmatter(source);
|
|
254
|
+
if (block === null || block.matter === "toml") return [];
|
|
255
|
+
const { contentStart, contentEnd } = block;
|
|
256
|
+
const content = source.slice(contentStart, contentEnd);
|
|
257
|
+
const declined = declinedContentRanges(content);
|
|
258
|
+
return _chunkKAJ3GVK2cjs.yamlSpans.call(void 0, content, frontmatterKeys).filter((span) => !declined.some((range) => span.start < range.end && range.start < span.end)).map((span) => ({ start: span.start + contentStart, end: span.end + contentStart }));
|
|
198
259
|
}
|
|
199
260
|
|
|
200
261
|
// src/engine/markdown-pipeline.ts
|
|
201
262
|
function runMarkdownPipeline(input, options) {
|
|
202
|
-
const narrowTarget =
|
|
203
|
-
const planned =
|
|
204
|
-
const locale =
|
|
263
|
+
const narrowTarget = _chunkGUROIWJYcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
264
|
+
const planned = _chunkGUROIWJYcjs.planRules.call(void 0, options.rules);
|
|
265
|
+
const locale = _chunkGUROIWJYcjs.getLocaleData.call(void 0, options.locale);
|
|
205
266
|
const dialect = resolveDialect(options.dialect);
|
|
206
|
-
const frontmatterKeys =
|
|
267
|
+
const frontmatterKeys = _chunkKAJ3GVK2cjs.resolveFrontmatterKeys.call(void 0, options.frontmatterKeys);
|
|
207
268
|
const units = unitsOf(input, dialect, frontmatterKeys);
|
|
208
|
-
return
|
|
269
|
+
return _chunkUWFI3XV7cjs.runOverUnits.call(void 0, input, units, planned, locale, "markdown", narrowTarget);
|
|
209
270
|
}
|
|
210
271
|
function unitsOf(input, dialect, frontmatterKeys) {
|
|
211
272
|
const body = markdownSpans(input, dialect);
|
|
212
273
|
if (frontmatterKeys === void 0) return [body];
|
|
213
|
-
return [frontmatterSpans(input,
|
|
274
|
+
return [frontmatterSpans(input, frontmatterKeys), body];
|
|
214
275
|
}
|
|
215
276
|
function analyzeMarkdownPipeline(input, options) {
|
|
216
|
-
const narrowTarget =
|
|
217
|
-
const planned =
|
|
218
|
-
const locale =
|
|
277
|
+
const narrowTarget = _chunkGUROIWJYcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
278
|
+
const planned = _chunkGUROIWJYcjs.planRules.call(void 0, options.rules);
|
|
279
|
+
const locale = _chunkGUROIWJYcjs.getLocaleData.call(void 0, options.locale);
|
|
219
280
|
const dialect = resolveDialect(options.dialect);
|
|
220
|
-
const frontmatterKeys =
|
|
221
|
-
return
|
|
281
|
+
const frontmatterKeys = _chunkKAJ3GVK2cjs.resolveFrontmatterKeys.call(void 0, options.frontmatterKeys);
|
|
282
|
+
return _chunkUWFI3XV7cjs.analyzeOverUnits.call(void 0,
|
|
222
283
|
input,
|
|
223
284
|
unitsOf(input, dialect, frontmatterKeys),
|
|
224
285
|
planned,
|
|
@@ -232,4 +293,4 @@ function analyzeMarkdownPipeline(input, options) {
|
|
|
232
293
|
|
|
233
294
|
|
|
234
295
|
exports.runMarkdownPipeline = runMarkdownPipeline; exports.analyzeMarkdownPipeline = analyzeMarkdownPipeline;
|
|
235
|
-
//# sourceMappingURL=chunk-
|
|
296
|
+
//# sourceMappingURL=chunk-VBHUVDW4.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-VBHUVDW4.cjs","../src/modes/markdown.ts","../src/engine/markdown-pipeline.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACpBA,sCAA+C;AAC/C,gFAA4B;AAC5B,gEAAoB;AACpB,oEAAsB;AAiBtB,IAAM,oBAAA,kBAA2C,IAAI,GAAA,CAAI;AAAA;AAAA,EAEvD,YAAA;A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oB,KAAA,CAAA,EAAW,OAAO,CAAC,IAAI,CAAA;AAC/C,EAAA,OAAO,CAAC,gBAAA,CAAiB,KAAA,EAAO,eAAe,CAAA,EAAG,IAAI,CAAA;AACxD;AAKO,SAAS,uBAAA,CAAwB,KAAA,EAAe,OAAA,EAAqC;AAC1F,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,QAAA,EAAU,cAAA,CAAe,OAAA,CAAQ,OAAO,CAAA;AAC9C,EAAA,MAAM,gBAAA,EAAkB,sDAAA,OAAuB,CAAQ,eAAe,CAAA;AACtE,EAAA,OAAO,gDAAA;AAAA,IACL,KAAA;AAAA,IACA,OAAA,CAAQ,KAAA,EAAO,OAAA,EAAS,eAAe,CAAA;AAAA,IACvC,OAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,EACF,CAAA;AACF;AF+NA;AACA;AACE;AACA;AACF,6GAAC","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-VBHUVDW4.cjs","sourcesContent":[null,"import { parse, postprocess, preprocess } from \"micromark\";\nimport { frontmatter } from \"micromark-extension-frontmatter\";\nimport { gfm } from \"micromark-extension-gfm\";\nimport { mdxjs } from \"micromark-extension-mdxjs\";\nimport type { Event, Extension } from \"micromark-util-types\";\nimport { PolytypoError } from \"../errors.js\";\nimport type { Dialect } from \"../types.js\";\nimport { htmlFragmentSpans, isSkippedElement } from \"./html.js\";\nimport { yamlSpans } from \"./yaml.js\";\nimport { wrapParserErrors } from \"./parse-error.js\";\nimport type { Span } from \"./spans.js\";\n\n/**\n * spec/rules/modes.md 3.7. Each entry is skipped **whole**, including anything that looks\n * processable inside it. The complement is not enumerated: a span is emitted only for a\n * micromark `data` token, which is the tokenizer's own name for \"literal content\", so list\n * markers, emphasis delimiters, heading sequences, table padding, line endings, hard-break\n * spaces, character escapes and character references are outside every span by construction\n * rather than by a second list that could drift from the first.\n */\nconst SKIPPED_TOKEN_TYPES: ReadonlySet<string> = new Set([\n // fenced code blocks (including the info string and the fences) and indented code blocks\n \"codeFenced\",\n \"codeIndented\",\n // inline code spans, including the backticks\n \"codeText\",\n // autolinks `<https://…>`, and GFM's bare-URL form\n \"autolink\",\n \"literalAutolink\",\n // link and image destinations and titles; the definition line of a reference link. The link\n // *text* is a `labelText`, which is not skipped.\n \"resource\",\n \"reference\",\n \"definition\",\n // MDX: expression containers in full, and every JSX attribute — the whole tag is skipped, so\n // attributes never surface. JSX element *children* sit outside the tag tokens and are\n // processable.\n \"mdxFlowExpression\",\n \"mdxTextExpression\",\n \"mdxjsEsm\",\n // modes.md 3.7.3, and it matters: without it the second `---` of a YAML block reads as a setext\n // underline, `title: Une note` becomes a paragraph, and `fr` puts a narrow no-break space in\n // front of the colon of a machine-read metadata field. Covered by conformance fixtures\n // en-us-markdown-{commonmark,mdx}-frontmatter, fr-markdown-{commonmark,mdx}-frontmatter-nbsp,\n // en-us-markdown-commonmark-frontmatter-toml and -frontmatter-unterminated.\n //\n // These are `micromark-extension-frontmatter`'s own token types, one per matter. An earlier\n // revision listed `\"frontmatter\"`, which the extension never emits: the block was skipped only\n // because its content arrives as `yamlValue`/`tomlValue` rather than `data`, so the entry that\n // was supposed to do the work did none.\n //\n // Since spec 1.8.0 the skip is 3.7.3a's mask, not this: a located block reaches the parser as\n // blanks, so the extension cannot see one. The extension stays because it is measured inert —\n // `tests/modes/frontmatter-keys.test.ts` asserts over every edge document that it never finds\n // a block the scan denies — and because removing a working locator that costs nothing would be\n // a change with no problem behind it. What the test would catch is the case that would matter:\n // the two disagreeing about whether a document has a block at all.\n \"yaml\",\n \"toml\",\n]);\n\n/** Token types whose enter/exit also maintains the skipped-element stack. */\nconst RAW_TAG_TOKEN_TYPES: ReadonlySet<string> = new Set([\n \"htmlText\",\n \"mdxJsxTextTag\",\n \"mdxJsxFlowTag\",\n]);\n\nconst LESS_THAN = 0x3c;\nconst GREATER_THAN = 0x3e;\nconst SLASH = 0x2f;\nconst EXCLAMATION = 0x21;\nconst QUESTION = 0x3f;\n\nfunction isAsciiLetter(unit: number): boolean {\n return (unit >= 0x61 && unit <= 0x7a) || (unit >= 0x41 && unit <= 0x5a);\n}\n\nfunction isTagNameUnit(unit: number): boolean {\n // Deliberately permissive: anything that is not a delimiter belongs to the name. Custom\n // elements (`my-callout`) and member expressions (`Foo.Bar`) must come out whole so that they\n // fail the skip-list membership test rather than being truncated into something that passes.\n return (\n unit !== GREATER_THAN &&\n unit !== SLASH &&\n unit !== 0x20 &&\n unit !== 0x09 &&\n unit !== 0x0a &&\n unit !== 0x0d\n );\n}\n\n/** ASCII-only, because HTML tag names are ASCII case-insensitive and `toLowerCase()` is not. */\nfunction asciiLower(value: string): string {\n let out = \"\";\n for (let i = 0; i < value.length; i += 1) {\n const unit = value.charCodeAt(i);\n out += unit >= 0x41 && unit <= 0x5a ? String.fromCharCode(unit + 0x20) : value[i];\n }\n return out;\n}\n\ninterface RawTag {\n readonly name: string;\n readonly closing: boolean;\n readonly selfClosing: boolean;\n}\n\nfunction readTag(tag: string): RawTag | null {\n if (tag.charCodeAt(0) !== LESS_THAN) return null;\n let i = 1;\n const closing = tag.charCodeAt(i) === SLASH;\n if (closing) i += 1;\n // Comments, declarations and processing instructions carry no element name.\n if (tag.charCodeAt(i) === EXCLAMATION || tag.charCodeAt(i) === QUESTION) return null;\n if (!isAsciiLetter(tag.charCodeAt(i))) return null;\n const nameAt = i;\n while (i < tag.length && isTagNameUnit(tag.charCodeAt(i))) i += 1;\n const selfClosing = tag.charCodeAt(tag.length - 2) === SLASH;\n return { name: tag.slice(nameAt, i), closing, selfClosing };\n}\n\n/**\n * modes.md 3.7: raw HTML is \"handed to the html skip list of 3.6\". Inline raw HTML reaches the\n * tokenizer as isolated tags with ordinary markdown content between them, so honouring the\n * subtree rule means tracking which skipped element is currently open. JSX names are compared\n * case-sensitively (`<Code>` is a component, `<code>` is an element); HTML names are not.\n */\nfunction updateElementStack(stack: string[], tag: string, caseSensitive: boolean): void {\n const parsed = readTag(tag);\n if (parsed === null) return;\n const name = caseSensitive ? parsed.name : asciiLower(parsed.name);\n if (parsed.closing) {\n if (stack[stack.length - 1] === name) stack.pop();\n return;\n }\n if (!parsed.selfClosing && isSkippedElement(name)) stack.push(name);\n}\n\nfunction tokenize(source: string, extensions: readonly Extension[]): Event[] {\n return postprocess(\n parse({ extensions: [...extensions] })\n .document()\n .write(preprocess()(source, null, true)),\n );\n}\n\n/**\n * modes.md 3.7.1. The dialect is the caller's, never detected: `\"commonmark\"` is CommonMark 0.31\n * plus GFM, `\"mdx\"` is the same minus indented code blocks and `<…>` autolinks, plus JSX and\n * `{…}` expression containers. Both enable frontmatter and GFM, which 3.7.2 makes normative —\n * §4's promise that table alignment rows survive is empty unless tables are recognised at all.\n */\nexport function resolveDialect(dialect: Dialect | undefined): Dialect {\n if (dialect === \"commonmark\" || dialect === \"mdx\") return dialect;\n if (dialect === undefined) {\n throw new PolytypoError(\n \"POLYTYPO_INVALID_DIALECT\",\n 'Mode \"markdown\" requires a dialect. Expected \"commonmark\" or \"mdx\"; there is no default.',\n );\n }\n throw new PolytypoError(\n \"POLYTYPO_INVALID_DIALECT\",\n `Unknown dialect \"${String(dialect)}\". Expected \"commonmark\" or \"mdx\".`,\n );\n}\n\n// modes.md 3.7.3 names both frontmatter delimiters, `---` (YAML) and `+++` (TOML), and skips\n// either whole. micromark's default matter is YAML alone, so both must be asked for by name: with\n// the default, a `+++` block parses as prose and the machine-read fields inside it get typeset.\nconst FRONTMATTER_MATTERS = [\"yaml\", \"toml\"] as const;\n\nexport function extensionsFor(dialect: Dialect): Extension[] {\n const fm = frontmatter([...FRONTMATTER_MATTERS]);\n return dialect === \"mdx\" ? [fm, gfm(), mdxjs()] : [fm, gfm()];\n}\n\n// modes.md 3.7.3a, spec 1.8.0: where the frontmatter block begins and ends, decided by the scan\n// below and by nothing else. Four runtimes reached the construct through four parsers and got four\n// answers — two of them typeset `date: \"2026-09-26\"` over one trailing space on a fence — so the\n// section makes this scan normative and a parser's opinion a thing measured against it. Locating\n// the block here is also what lets `frontmatterSpans` stop parsing the document a second time\n// (polytypo/polytypo#59).\nconst YAML_DELIMITER = \"---\";\nconst TOML_DELIMITER = \"+++\";\n\nconst TAB = 0x09;\nconst LF = 0x0a;\nconst CR = 0x0d;\nconst SPACE = 0x20;\nconst BOM = 0xfeff;\n\ninterface SourceLine {\n /** Index just past the line's content: the terminator, or the end of the source. */\n readonly end: number;\n /** Index the next line starts at, or the end of the source when this line is the last. */\n readonly next: number;\n}\n\n/**\n * 3.7.3a step 5: **CommonMark's** line, not 3.8.4's. A line ends at U+000A, at a U+000D that is\n * not followed by U+000A, or at the end of input, and the terminator is never part of the line.\n * The block is a Markdown construct and ends its lines the way the language around it does; the\n * YAML inside it keeps 3.8.4's LF-only model (`./yaml.js`), and the two are different on purpose —\n * harmonising them silently changes one of them.\n */\nfunction markdownLineFrom(source: string, start: number): SourceLine {\n for (let i = start; i < source.length; i += 1) {\n const unit = source.charCodeAt(i);\n if (unit === LF) return { end: i, next: i + 1 };\n if (unit === CR) return { end: i, next: source.charCodeAt(i + 1) === LF ? i + 2 : i + 1 };\n }\n return { end: source.length, next: source.length };\n}\n\n/** 3.7.3a steps 2 and 3: what a delimiter line may carry after the delimiter, and nothing else. */\nfunction isBlankRun(source: string, from: number, to: number): boolean {\n for (let i = from; i < to; i += 1) {\n const unit = source.charCodeAt(i);\n if (unit !== SPACE && unit !== TAB) return false;\n }\n return true;\n}\n\n/**\n * A delimiter line: the delimiter at the line's first code point — indentation disqualifies it —\n * then U+0020 and U+0009 to the end of the line. A fourth delimiter character is not whitespace,\n * so `----` is neither an opener nor a closer.\n */\nfunction isDelimiterLine(\n source: string,\n start: number,\n line: SourceLine,\n delimiter: string,\n): boolean {\n return (\n source.startsWith(delimiter, start) && isBlankRun(source, start + delimiter.length, line.end)\n );\n}\n\n/** modes.md 3.7.3a. The frontmatter block's extent, in source offsets. */\nexport interface FrontmatterBlock {\n /** Which matter the delimiter names. TOML yields no spans either way (3.7.4). */\n readonly matter: \"yaml\" | \"toml\";\n /** First code point of the opening delimiter: 0, or 1 past a single leading U+FEFF (step 1). */\n readonly start: number;\n /**\n * End of the closing delimiter line's content — its trailing whitespace included, its terminator\n * excluded.\n */\n readonly end: number;\n /** 3.7.4: the code point after the opening delimiter line's terminator. */\n readonly contentStart: number;\n /** 3.7.4: the code point that begins the closing delimiter line. */\n readonly contentEnd: number;\n}\n\n/**\n * modes.md 3.7.3a, the whole of it. Offsets are UTF-16 indices, like every other mode in this\n * runtime; every code point the scan tests is ASCII or U+FEFF, so indexing by code unit and\n * indexing by code point agree on all of them.\n */\nexport function locateFrontmatter(source: string): FrontmatterBlock | null {\n // Step 1: the document must begin with the delimiter, with a single leading U+FEFF stepped over\n // first — it is a byte-order mark, not content, and reading it as content would deny the block\n // to every file some Windows editors produce.\n const start = source.charCodeAt(0) === BOM ? 1 : 0;\n const matter = source.startsWith(YAML_DELIMITER, start)\n ? \"yaml\"\n : source.startsWith(TOML_DELIMITER, start)\n ? \"toml\"\n : null;\n if (matter === null) return null;\n const delimiter = matter === \"yaml\" ? YAML_DELIMITER : TOML_DELIMITER;\n\n // Step 2: the rest of the opening line may be U+0020 and U+0009 and nothing else.\n const opener = markdownLineFrom(source, start);\n if (!isBlankRun(source, start + delimiter.length, opener.end)) return null;\n\n // Step 3: the closing line is the first LATER line of the same delimiter. Step 4: with none,\n // there is no block, and the opening delimiter is whatever the dialect makes of it.\n const contentStart = opener.next;\n for (let at = contentStart; at < source.length;) {\n const line = markdownLineFrom(source, at);\n if (isDelimiterLine(source, at, line, delimiter)) {\n return { matter, start, end: line.end, contentStart, contentEnd: at };\n }\n at = line.next;\n }\n return null;\n}\n\n/**\n * modes.md 3.7.3a: **the parser is handed the block masked out** — the located block, both\n * delimiter lines included and step 1's leading U+FEFF with them, replaced by U+0020, with line\n * terminators kept as they are. The mark is in that list because without it the first line is not\n * blank: no parser is required to strip it, and a runtime masking the block alone emits a span\n * for it.\n *\n * The invariant is that the masked source stay **positionally aligned with the original in the unit\n * this runtime maps parser offsets back through**, which here is UTF-16 code units: micromark's\n * offsets are handed straight to `Span`, so one U+0020 per code unit is what JS owes. An astral\n * character therefore masks to two spaces, not one. It is deliberately not stated as a count of\n * code points — a runtime that converts offsets against the masked source first owes code-point\n * alignment instead, and both are conformant.\n *\n * Suppressing spans inside the block's range instead is not equivalent, and the runtime that did\n * that is measured in 3.7.3a: a fence inside a metadata value pairs with the body's own, and the\n * body's code block and its prose swap roles — or, with nothing to pair with, swallows the rest of\n * the document. The damage is in what the parser concluded, so no span-level check can see it.\n *\n * Masking is also what keeps 3.7.4's two text units disjoint now that the extent is the scan's and\n * not the parser's: the body cannot emit a span inside a block the parser was never shown.\n */\nfunction maskFrontmatter(source: string, block: FrontmatterBlock | null): string {\n if (block === null) return source;\n let masked = \"\";\n for (let i = 0; i < block.end; i += 1) {\n const unit = source.charCodeAt(i);\n masked += unit === LF || unit === CR ? source[i] : \" \";\n }\n return masked + source.slice(block.end);\n}\n\n/**\n * modes.md 3.7. The body's spans. The document reaches the parser with its frontmatter block\n * masked out (3.7.3a), so the block is skipped because the scan located it, not because an\n * extension recognised it — and `text` below is what the token offsets refer to.\n *\n * Two corrections sit between `text` and the spans this returns:\n *\n * - **`shift`**: micromark's `preprocess` drops a leading U+FEFF and then reports offsets against\n * the shortened string, so every span in a document carrying one lands a code unit to the left —\n * which ate the last code point of every span and left\n * `en-us-markdown-commonmark-byte-order-mark-no-block` unconverted in full. The mark is removed\n * here instead, and the difference added back. A document whose block was located needs no such\n * correction, because 3.7.3a masks the mark along with the block;\n * - **the no-span rule** (3.7.3a): no span may lie inside the block whatever the parser made of the\n * masked text. A span straddling the block's end is **clipped** to the part outside it, and\n * dropped only when nothing is left, so body prose past the block cannot be lost to a parser's\n * mistake\n * about where the block ended. Masking is what makes this inert for micromark — measured over\n * nineteen block shapes in both dialects, it emits nothing inside a masked block — and the spec\n * states the rule separately because it is not true of every parser.\n */\nexport function markdownSpans(source: string, dialect: Dialect): Span[] {\n const block = locateFrontmatter(source);\n const masked = maskFrontmatter(source, block);\n const shift = masked.charCodeAt(0) === BOM ? 1 : 0;\n const text = shift === 0 ? masked : masked.slice(shift);\n const events = wrapParserErrors(dialect, () => tokenize(text, extensionsFor(dialect)));\n const spans: Span[] = [];\n const elementStack: string[] = [];\n let skipDepth = 0;\n\n for (const [kind, token] of events) {\n const type = token.type;\n\n if (SKIPPED_TOKEN_TYPES.has(type)) {\n skipDepth += kind === \"enter\" ? 1 : -1;\n continue;\n }\n\n if (RAW_TAG_TOKEN_TYPES.has(type)) {\n if (kind === \"enter\") {\n updateElementStack(\n elementStack,\n text.slice(token.start.offset, token.end.offset),\n type !== \"htmlText\",\n );\n }\n skipDepth += kind === \"enter\" ? 1 : -1;\n continue;\n }\n\n // An HTML block is handed to the `html` extractor rather than skipped whole, so that the\n // prose inside `<div>…</div>` is typeset while the markup is not.\n if (type === \"htmlFlow\") {\n if (kind === \"enter\" && skipDepth === 0 && elementStack.length === 0) {\n for (const span of htmlFragmentSpans(\n text.slice(token.start.offset, token.end.offset),\n token.start.offset + shift,\n )) {\n spans.push(span);\n }\n }\n skipDepth += kind === \"enter\" ? 1 : -1;\n continue;\n }\n\n if (kind === \"enter\" && type === \"data\" && skipDepth === 0 && elementStack.length === 0) {\n spans.push({ start: token.start.offset + shift, end: token.end.offset + shift });\n }\n }\n\n if (block === null) return spans;\n return spans.flatMap((span) => {\n if (span.start >= block.end) return [span];\n if (span.end <= block.end) return [];\n return [{ start: block.end, end: span.end }];\n });\n}\n\n/**\n * modes.md 3.7.4: **a content line containing a U+000D not followed by U+000A yields no spans**,\n * \"exactly as 3.8.4 step 1 already declines a line containing U+0009\". The two line models meet in\n * the block content and do not compose — 3.7.3a step 5 finds a block in a lone-U+000D document, and\n * 3.8.4's LF-only scan then reads the whole of it as one line. Measured, letting it through is not\n * merely inert: marks pair across what were two mapping lines, an unlisted line inside the listed\n * key's scalar takes `fr`'s spacing, and the U+000D itself lands inside a span — which 3.8.4\n * forbids.\n *\n * The decline **drops the spans the content scan produced for that line and does not alter the\n * content the scan is given**. Substituting each lone U+000D for a character 3.8.4 already\n * declines is the shortcut three ports reached for, this one included, and it is measured not\n * equivalent: the substitution moves the character onto a line of its own and can end a value run.\n * Both shapes are pinned as fixtures, and both are decided by what `yaml` mode does with the same\n * characters, since 3.7.4 claims 3.8's scan applies verbatim:\n *\n * - `title: a \"b\"\\nslug: c \"d\"\\n\\r` — the content-final U+000D is a blank line joining `slug`'s\n * value run, so 3.8.6's continuation bail declines `slug`. As a U+0009 it is a line with a tab\n * in it, not a blank one, the run ends and `slug` converts. `yaml` mode converts `title` only,\n * in both shipped runtimes measured;\n * - `summary: a\\rb\\n title: c -- d\\n` — the indented line is inside `summary`'s value run, so\n * `title` is not a key at all. Substitution ends the run and invents one.\n *\n * **The window runs to the start of the next line, not to the end of this one**, because 3.8.4's\n * own splitter treats a trailing U+000D as a terminator without a U+000A after it — so a block\n * whose single line ends in one looks clean if the terminator is excluded.\n */\nfunction declinedContentRanges(content: string): readonly Span[] {\n const declined: Span[] = [];\n let start = 0;\n while (start < content.length) {\n const lf = content.indexOf(\"\\n\", start);\n const next = lf === -1 ? content.length : lf + 1;\n for (let i = start; i < next; i += 1) {\n if (content.charCodeAt(i) === CR && content.charCodeAt(i + 1) !== LF) {\n declined.push({ start, end: next });\n break;\n }\n }\n start = next;\n }\n return declined;\n}\n\n/**\n * modes.md 3.7.4, spec 1.7.0. The frontmatter block's own spans, which form a **second text\n * unit**: the pipeline runs over them separately from the body's, so an unbalanced mark in a\n * metadata field can never pair with one in the first paragraph and this option cannot change a\n * byte outside the block.\n *\n * The block is located by `locateFrontmatter` (3.7.3a, spec 1.8.0) rather than by a second parse\n * of the document, which is both what polytypo/polytypo#59 reported and, since 1.8.0, the wrong\n * authority: the scan owns the extent and a parser is measured against it.\n *\n * Spans inside it are taken by the scan of modes.md 3.8 — frontmatter *is* YAML, and specifying it\n * twice is how two implementations of one grammar drift — with `frontmatterKeys` as step 8's key\n * predicate.\n *\n * A TOML block yields nothing, with the option or without it: TOML's quoting is a second grammar\n * this scan does not claim (modes.md §7.13). So does any content line carrying a lone U+000D — see\n * `declinedContentRanges`, which filters what the scan produced rather than changing what it reads.\n */\nexport function frontmatterSpans(source: string, frontmatterKeys: readonly string[]): Span[] {\n if (frontmatterKeys.length === 0) return [];\n const block = locateFrontmatter(source);\n if (block === null || block.matter === \"toml\") return [];\n\n const { contentStart, contentEnd } = block;\n const content = source.slice(contentStart, contentEnd);\n const declined = declinedContentRanges(content);\n\n return (\n yamlSpans(content, frontmatterKeys)\n // 3.7.4: a span reaching a declined position is dropped whole rather than trimmed.\n .filter((span) => !declined.some((range) => span.start < range.end && range.start < span.end))\n .map((span) => ({ start: span.start + contentStart, end: span.end + contentStart }))\n );\n}\n","import { frontmatterSpans, markdownSpans, resolveDialect } from \"../modes/markdown.js\";\nimport type { Dialect, Options } from \"../types.js\";\nimport { getLocaleData } from \"./locale.js\";\nimport { resolveNarrowTarget } from \"./narrow-target.js\";\nimport { planRules } from \"./rule-runner.js\";\nimport { resolveFrontmatterKeys } from \"./yaml-keys.js\";\nimport { analyzeOverUnits, runOverUnits } from \"./span-runner.js\";\nimport type { Change } from \"./origin.js\";\nimport type { Span } from \"../modes/spans.js\";\n\n/**\n * `markdown` mode only. Imports the Micromark/MDX stack and `parse5` (via `../modes/markdown.js`\n * importing `../modes/html.js` for normative embedded-HTML handling, modes.md 3.7) — both are\n * legitimately reachable from `polytypo/markdown` (AUDIT_REMEDIATION_AND_RELEASE_PLAN.md 5.1).\n *\n * Validation order — `planRules`, then `getLocaleData`, then `resolveDialect`/parsing — mirrors\n * the pre-Stage-5 aggregate `runPipeline` exactly: an unknown-rule error wins over an\n * unknown-locale error, which wins over a missing/invalid dialect, which wins over a parse\n * failure. All four are public, tested behaviour this refactor was not authorised to change.\n */\nexport function runMarkdownPipeline(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 dialect = resolveDialect(options.dialect);\n const frontmatterKeys = resolveFrontmatterKeys(options.frontmatterKeys);\n const units = unitsOf(input, dialect, frontmatterKeys);\n return runOverUnits(input, units, planned, locale, \"markdown\", narrowTarget);\n}\n\n/**\n * modes.md 3.7.4: the body, and — only when the caller named frontmatter keys — the frontmatter\n * block as a second text unit. Without the option this is exactly the single unit every document\n * had before spec 1.7.0, which is why no released output can move.\n *\n * The two units must be **disjoint** — 3.7.4: \"no source position can belong to both units\". Since\n * spec 1.8.0 that is 3.7.3a's masking rule doing the work rather than a shared parser: the body is\n * read from a document whose block is blanked out, so it cannot emit a span the frontmatter unit\n * also claims, whatever the parser would have made of the block's characters.\n */\nfunction unitsOf(\n input: string,\n dialect: Dialect,\n frontmatterKeys: readonly string[] | undefined,\n): Span[][] {\n const body = markdownSpans(input, dialect);\n if (frontmatterKeys === undefined) return [body];\n return [frontmatterSpans(input, frontmatterKeys), body];\n}\n\n/** analyze.md §1, `markdown` mode. Dialect validation happens here exactly as it does for\n * `runMarkdownPipeline`, so an absent dialect throws POLYTYPO_INVALID_DIALECT from `analyze`\n * too (analyze.md §4 A1). */\nexport function analyzeMarkdownPipeline(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 dialect = resolveDialect(options.dialect);\n const frontmatterKeys = resolveFrontmatterKeys(options.frontmatterKeys);\n return analyzeOverUnits(\n input,\n unitsOf(input, dialect, frontmatterKeys),\n planned,\n locale,\n \"markdown\",\n narrowTarget,\n );\n}\n"]}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
runRules,
|
|
7
7
|
runRulesRecording,
|
|
8
8
|
toCodePoints
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-EQ2JTKYF.js";
|
|
10
10
|
|
|
11
11
|
// src/engine/text-pipeline.ts
|
|
12
12
|
function runTextPipeline(input, options) {
|
|
@@ -28,4 +28,4 @@ export {
|
|
|
28
28
|
runTextPipeline,
|
|
29
29
|
analyzeTextPipeline
|
|
30
30
|
};
|
|
31
|
-
//# sourceMappingURL=chunk-
|
|
31
|
+
//# sourceMappingURL=chunk-XLTVLET5.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkGUROIWJYcjs = require('./chunk-GUROIWJY.cjs');
|
|
10
|
+
|
|
11
|
+
// src/engine/text-pipeline.ts
|
|
12
|
+
function runTextPipeline(input, options) {
|
|
13
|
+
const narrowTarget = _chunkGUROIWJYcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
14
|
+
const planned = _chunkGUROIWJYcjs.planRules.call(void 0, options.rules);
|
|
15
|
+
const locale = _chunkGUROIWJYcjs.getLocaleData.call(void 0, options.locale);
|
|
16
|
+
return _chunkGUROIWJYcjs.fromCodePoints.call(void 0, _chunkGUROIWJYcjs.runRules.call(void 0, _chunkGUROIWJYcjs.toCodePoints.call(void 0, input), planned, locale, "text", narrowTarget));
|
|
17
|
+
}
|
|
18
|
+
function analyzeTextPipeline(input, options) {
|
|
19
|
+
const narrowTarget = _chunkGUROIWJYcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
20
|
+
const planned = _chunkGUROIWJYcjs.planRules.call(void 0, options.rules);
|
|
21
|
+
const locale = _chunkGUROIWJYcjs.getLocaleData.call(void 0, options.locale);
|
|
22
|
+
const cp = _chunkGUROIWJYcjs.toCodePoints.call(void 0, input);
|
|
23
|
+
const origin = cp.map((_value, index) => index);
|
|
24
|
+
return _chunkGUROIWJYcjs.runRulesRecording.call(void 0, cp, planned, locale, "text", narrowTarget, origin, cp.length);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
exports.runTextPipeline = runTextPipeline; exports.analyzeTextPipeline = analyzeTextPipeline;
|
|
31
|
+
//# sourceMappingURL=chunk-YA64BEKC.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-YA64BEKC.cjs","../src/engine/text-pipeline.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACQO,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,OAAO,8CAAA,wCAAe,4CAAS,KAAkB,CAAA,EAAG,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAQ,YAAY,CAAC,CAAA;AAC5F;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,GAAA,EAAK,4CAAA,KAAkB,CAAA;AAC7B,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;ADRA;AACA;AACE;AACA;AACF,6FAAC","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-YA64BEKC.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\";\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 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 origin = cp.map((_value, index) => index);\n return runRulesRecording(cp, planned, locale, \"text\", narrowTarget, origin, cp.length);\n}\n"]}
|