polytypo 1.22.1 → 1.23.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.
Files changed (48) hide show
  1. package/dist/{chunk-PREUPLPO.js → chunk-2DXV6J4X.js} +12 -2
  2. package/dist/chunk-2DXV6J4X.js.map +1 -0
  3. package/dist/{chunk-44KKUSOQ.js → chunk-4T6472KQ.js} +2 -2
  4. package/dist/{chunk-D6CWTH54.js → chunk-CI3NZEM3.js} +1 -1
  5. package/dist/{chunk-D6CWTH54.js.map → chunk-CI3NZEM3.js.map} +1 -1
  6. package/dist/{chunk-JWOUHTOD.cjs → chunk-GFBX7ERJ.cjs} +1 -1
  7. package/dist/{chunk-JWOUHTOD.cjs.map → chunk-GFBX7ERJ.cjs.map} +1 -1
  8. package/dist/{chunk-PLDK525W.cjs → chunk-GXN5UU4W.cjs} +6 -6
  9. package/dist/{chunk-PLDK525W.cjs.map → chunk-GXN5UU4W.cjs.map} +1 -1
  10. package/dist/{chunk-2QD7JARJ.js → chunk-H3Z64VQD.js} +3 -3
  11. package/dist/chunk-IFUGQYHJ.cjs +34 -0
  12. package/dist/{chunk-UNXIWWE7.cjs.map → chunk-IFUGQYHJ.cjs.map} +1 -1
  13. package/dist/{chunk-MEVOJV7I.js → chunk-IT7K7NZV.js} +2 -2
  14. package/dist/chunk-LOWQTULZ.cjs +38 -0
  15. package/dist/{chunk-OEKUKIMI.cjs.map → chunk-LOWQTULZ.cjs.map} +1 -1
  16. package/dist/{chunk-N2QFEDI2.js → chunk-MLASZMHY.js} +3 -3
  17. package/dist/{chunk-6S7AKBQZ.cjs → chunk-MNHZALA4.cjs} +3 -3
  18. package/dist/{chunk-6S7AKBQZ.cjs.map → chunk-MNHZALA4.cjs.map} +1 -1
  19. package/dist/{chunk-IQ7T2HFZ.js → chunk-Q5RRHO32.js} +2 -2
  20. package/dist/{chunk-BF6OL3QM.cjs → chunk-RMNY65SN.cjs} +14 -4
  21. package/dist/chunk-RMNY65SN.cjs.map +1 -0
  22. package/dist/{chunk-OY3D5CRP.cjs → chunk-TYJELWIF.cjs} +23 -23
  23. package/dist/{chunk-OY3D5CRP.cjs.map → chunk-TYJELWIF.cjs.map} +1 -1
  24. package/dist/chunk-VRSUY6YN.cjs +36 -0
  25. package/dist/{chunk-FSDQXTM5.cjs.map → chunk-VRSUY6YN.cjs.map} +1 -1
  26. package/dist/{chunk-PRG3GQNV.js → chunk-YEALOS6F.js} +4 -4
  27. package/dist/html.cjs +9 -9
  28. package/dist/html.js +4 -4
  29. package/dist/index.cjs +17 -17
  30. package/dist/index.js +7 -7
  31. package/dist/markdown.cjs +10 -10
  32. package/dist/markdown.js +5 -5
  33. package/dist/text.cjs +8 -8
  34. package/dist/text.js +3 -3
  35. package/dist/yaml.cjs +9 -9
  36. package/dist/yaml.js +4 -4
  37. package/package.json +1 -1
  38. package/dist/chunk-BF6OL3QM.cjs.map +0 -1
  39. package/dist/chunk-FSDQXTM5.cjs +0 -36
  40. package/dist/chunk-OEKUKIMI.cjs +0 -38
  41. package/dist/chunk-PREUPLPO.js.map +0 -1
  42. package/dist/chunk-UNXIWWE7.cjs +0 -34
  43. /package/dist/{chunk-44KKUSOQ.js.map → chunk-4T6472KQ.js.map} +0 -0
  44. /package/dist/{chunk-2QD7JARJ.js.map → chunk-H3Z64VQD.js.map} +0 -0
  45. /package/dist/{chunk-MEVOJV7I.js.map → chunk-IT7K7NZV.js.map} +0 -0
  46. /package/dist/{chunk-N2QFEDI2.js.map → chunk-MLASZMHY.js.map} +0 -0
  47. /package/dist/{chunk-IQ7T2HFZ.js.map → chunk-Q5RRHO32.js.map} +0 -0
  48. /package/dist/{chunk-PRG3GQNV.js.map → chunk-YEALOS6F.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  PolytypoError
3
- } from "./chunk-D6CWTH54.js";
3
+ } from "./chunk-CI3NZEM3.js";
4
4
 
5
5
  // src/modes/html.ts
6
6
  import { parse, parseFragment } from "parse5";
@@ -104,10 +104,20 @@ function splitCharacterReferences(source, start, end) {
104
104
  function isParent(node) {
105
105
  return "childNodes" in node;
106
106
  }
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
+ }
107
116
  function collect(node, source, spans) {
108
117
  if (node.nodeName === "#text") {
109
118
  const location = node.sourceCodeLocation;
110
119
  if (location === void 0 || location === null) return;
120
+ if (isLineBreakWhitespace(source, location.startOffset, location.endOffset)) return;
111
121
  for (const span of splitCharacterReferences(source, location.startOffset, location.endOffset)) {
112
122
  spans.push(span);
113
123
  }
@@ -144,4 +154,4 @@ export {
144
154
  htmlSpans,
145
155
  htmlFragmentSpans
146
156
  };
147
- //# sourceMappingURL=chunk-PREUPLPO.js.map
157
+ //# sourceMappingURL=chunk-2DXV6J4X.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 `&nbsp;` survives as\n * `&nbsp;` 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\nfunction collect(node: Node, source: string, spans: Span[]): void {\n if (node.nodeName === \"#text\") {\n const location = node.sourceCodeLocation;\n if (location === undefined || location === null) return;\n if (isLineBreakWhitespace(source, location.startOffset, location.endOffset)) return;\n for (const span of splitCharacterReferences(source, location.startOffset, location.endOffset)) {\n 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 for (const child of node.childNodes) collect(child, source, spans);\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;AACzD,SAAO,iBAAiB,IAAI,OAAO;AACrC;AAEA,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAAM,OAAO;AACb,IAAM,UAAU;AAChB,IAAM,UAAU;AAGhB,IAAM,qBAAqB;AAE3B,SAAS,aAAa,MAAuB;AAC3C,SAAO,QAAQ,MAAQ,QAAQ;AACjC;AAEA,SAAS,gBAAg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M,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":[]}
@@ -9,7 +9,7 @@ import {
9
9
  runRules,
10
10
  runRulesRecording,
11
11
  toCodePoints
12
- } from "./chunk-D6CWTH54.js";
12
+ } from "./chunk-CI3NZEM3.js";
13
13
 
14
14
  // src/engine/text-pipeline.ts
15
15
  function runTextPipeline(input, options) {
@@ -35,4 +35,4 @@ export {
35
35
  runTextPipeline,
36
36
  analyzeTextPipeline
37
37
  };
38
- //# sourceMappingURL=chunk-44KKUSOQ.js.map
38
+ //# sourceMappingURL=chunk-4T6472KQ.js.map
@@ -6555,4 +6555,4 @@ export {
6555
6555
  runProtected,
6556
6556
  analyzeProtected
6557
6557
  };
6558
- //# sourceMappingURL=chunk-D6CWTH54.js.map
6558
+ //# sourceMappingURL=chunk-CI3NZEM3.js.map