@orkestrel/markdown 0.0.5 → 0.0.6
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/src/core/index.cjs +803 -272
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +1459 -8
- package/dist/src/core/index.d.ts +1459 -8
- package/dist/src/core/index.js +803 -272
- package/dist/src/core/index.js.map +1 -1
- package/package.json +17 -13
- package/dist/src/core/Markdown.d.ts +0 -86
- package/dist/src/core/constants.d.ts +0 -17
- package/dist/src/core/factories.d.ts +0 -92
- package/dist/src/core/helpers.d.ts +0 -451
- package/dist/src/core/parsers.d.ts +0 -66
- package/dist/src/core/shapers.d.ts +0 -105
- package/dist/src/core/types.d.ts +0 -269
- package/dist/src/core/validators.d.ts +0 -287
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["#document"],"sources":["../../../src/core/constants.ts","../../../src/core/validators.ts","../../../src/core/helpers.ts","../../../src/core/parsers.ts","../../../src/core/shapers.ts","../../../src/core/Markdown.ts","../../../src/core/factories.ts"],"sourcesContent":["/**\n * The URL schemes `renderHTML` permits on a link `href` - anything else (notably\n * `javascript:`, `data:`, `vbscript:`, `file:`) is dropped to an empty `href` so a\n * hostile link can never execute. Frozen, lower-case; a relative / anchor /\n * scheme-less `href` (no `scheme:` prefix) is always allowed.\n */\nexport const SAFE_URL_SCHEMES: ReadonlySet<string> = new Set(['http', 'https', 'mailto', 'tel'])\n\n/**\n * The maximum recursion depth the parse pipeline (`parseDocument` and its\n * `parsers.ts` helpers) and the `helpers.ts` traversal / render functions\n * (`renderHTML`, `renderMarkdown`, `walkNodes`, `foldNode`) honor before degrading to\n * literal text - bounds blockquote nesting, inline nesting (emphasis / links), and\n * traversal/render recursion so pathological or hostile input (deeply nested\n * blockquotes, runaway emphasis) cannot exhaust the call stack. Past this depth the\n * parser treats the remaining content as literal text instead of recursing further.\n */\nexport const MAX_DEPTH = 64\n","import type { Guard } from '@orkestrel/contract'\nimport type {\n\tBlockNode,\n\tBlockquoteNode,\n\tCodeBlockNode,\n\tCodeSpanNode,\n\tEmphasisNode,\n\tHeadingNode,\n\tInlineNode,\n\tLinkNode,\n\tListNode,\n\tMarkdownDocument,\n\tMarkdownNode,\n\tParagraphNode,\n\tTableNode,\n\tTextNode,\n\tThematicBreakNode,\n} from './types.js'\nimport {\n\tarrayOf,\n\tisBoolean,\n\tisEmptyString,\n\tisNumber,\n\tisString,\n\tliteralOf,\n\tlazyOf,\n\trecordOf,\n\tunionOf,\n} from '@orkestrel/contract'\nimport { splitTableRow } from './helpers.js'\n\n// AGENTS section 14: guards are total. This file owns two predicate families:\n// line / string structural predicates that test raw strings during parsing\n// (isWhitespace, isEscapable, isQuote, isFenceClose, isThematicBreak,\n// isTableStart), and node guards that narrow a MarkdownNode to one parsed\n// block / inline variant by its element tag.\n\n/**\n * Whether `character` is an inline whitespace character (space / tab / newline) - the\n * emphasis flanking rule's space test.\n *\n * @param character - The character to test\n * @returns `true` when it is inline whitespace\n *\n * @example\n * ```ts\n * isWhitespace(' ') // true\n * isWhitespace('a') // false\n * ```\n */\nexport function isWhitespace(character: string): boolean {\n\treturn character === ' ' || character === '\\t' || character === '\\n'\n}\n\n/**\n * Whether `character` is escapable by a leading backslash - the ASCII punctuation\n * markdown gives meaning to (so `\\*` becomes `*` but `\\.` stays `\\.`).\n *\n * @param character - The single character after a backslash\n * @returns `true` when a backslash before it is an escape\n *\n * @example\n * ```ts\n * isEscapable('*') // true\n * isEscapable('a') // false\n * ```\n */\nexport function isEscapable(character: string): boolean {\n\treturn /[\\\\`*_{}[\\]()#+\\-.!>~|]/.test(character)\n}\n\n/**\n * Whether `line` is blank - empty, or containing only whitespace - the markdown\n * definition of a blank line that block parsing uses to separate paragraphs, skip\n * gaps, and end list continuations.\n *\n * @param line - The candidate line\n * @returns `true` when the line is blank\n *\n * @example\n * ```ts\n * isBlankLine(' ') // true\n * ```\n */\nexport function isBlankLine(line: string): boolean {\n\treturn isEmptyString(line.trim())\n}\n\n/**\n * Whether `line` is a blockquote line (`>` optionally indented up to three spaces) -\n * its content is de-quoted by {@link stripQuote}.\n *\n * @param line - The candidate line\n * @returns `true` when the line begins a blockquote\n *\n * @example\n * ```ts\n * isQuote('> quoted') // true\n * ```\n */\nexport function isQuote(line: string): boolean {\n\treturn /^\\s{0,3}>/.test(line)\n}\n\n/**\n * Whether `line` closes a fence opened by `marker` - the same fence character, a run\n * at least as long, and nothing else but surrounding whitespace.\n *\n * @param line - The candidate closing line\n * @param marker - The opening fence's marker run (from {@link extractFence})\n * @returns `true` when `line` closes the fence\n *\n * @example\n * ```ts\n * isFenceClose('```', '```') // true\n * ```\n */\nexport function isFenceClose(line: string, marker: string): boolean {\n\tconst character = marker[0] === '~' ? '~' : '`'\n\tlet index = 0\n\twhile (index < line.length && isFenceWhitespace(line[index])) index++\n\tlet run = 0\n\twhile (index < line.length && line[index] === character) {\n\t\trun++\n\t\tindex++\n\t}\n\tif (run < marker.length) return false\n\twhile (index < line.length && isFenceWhitespace(line[index])) index++\n\treturn index === line.length\n}\n\n/**\n * Whether `character` is a regex-`\\s`-equivalent whitespace character - the\n * character class {@link isFenceClose}'s scan treats as surrounding padding.\n *\n * @param character - The single character to test, or `undefined` past the end of a line\n * @returns `true` when it is whitespace\n *\n * @example\n * ```ts\n * isFenceWhitespace(' ') // true\n * isFenceWhitespace(undefined) // false\n * ```\n */\nexport function isFenceWhitespace(character: string | undefined): boolean {\n\treturn (\n\t\tcharacter === ' ' ||\n\t\tcharacter === '\\t' ||\n\t\tcharacter === '\\n' ||\n\t\tcharacter === '\\r' ||\n\t\tcharacter === '\\f' ||\n\t\tcharacter === '\\v'\n\t)\n}\n\n/**\n * Whether `line` is a thematic break (horizontal rule) - three or more of the SAME\n * marker `-`, `*`, or `_` (optionally space-separated) and nothing else (`---`,\n * `***`, `___`, `- - -`).\n *\n * @param line - The candidate line\n * @returns `true` when the line is a thematic break\n *\n * @example\n * ```ts\n * isThematicBreak('---') // true\n * ```\n */\nexport function isThematicBreak(line: string): boolean {\n\tconst stripped = line.trim().replace(/\\s+/g, '')\n\tif (stripped.length < 3) return false\n\tconst marker = stripped[0]\n\tif (marker !== '-' && marker !== '*' && marker !== '_') return false\n\treturn [...stripped].every((character) => character === marker)\n}\n\n/**\n * Whether the pair (`header`, `delimiter`) opens a GFM table - `delimiter` is a row of\n * `|`-separated cells each matching `:?-+:?`, the GFM rule that a table requires a\n * header row IMMEDIATELY followed by a delimiter row.\n *\n * @param header - The candidate header line\n * @param delimiter - The line after it (the candidate delimiter)\n * @returns `true` when the two lines open a table\n *\n * @example\n * ```ts\n * isTableStart('| a |', '| - |') // true\n * ```\n */\nexport function isTableStart(header: string, delimiter: string | undefined): boolean {\n\tif (delimiter === undefined || !header.includes('|')) return false\n\tconst cells = splitTableRow(delimiter)\n\tif (cells.length === 0) return false\n\treturn cells.every((cell) => /^:?-+:?$/.test(cell.trim()))\n}\n\n// === Block guards\n\n/** Determine whether a node is a heading block. */\nexport function isHeadingNode(node: MarkdownNode): node is HeadingNode {\n\treturn node.element === 'heading'\n}\n\n/**\n * Determine whether a node is a paragraph block.\n *\n * @example\n * ```ts\n * isParagraphNode({ element: 'paragraph', children: [] }) // true\n * ```\n */\nexport function isParagraphNode(node: MarkdownNode): node is ParagraphNode {\n\treturn node.element === 'paragraph'\n}\n\n/**\n * Determine whether a node is a list block.\n *\n * @example\n * ```ts\n * isListNode({ element: 'list', ordered: false, start: 1, items: [] }) // true\n * ```\n */\nexport function isListNode(node: MarkdownNode): node is ListNode {\n\treturn node.element === 'list'\n}\n\n/** Determine whether a node is a GFM table block. */\nexport function isTableNode(node: MarkdownNode): node is TableNode {\n\treturn node.element === 'table'\n}\n\n/**\n * Determine whether a node is a fenced code block.\n *\n * @example\n * ```ts\n * isCodeBlockNode({ element: 'codeBlock', code: 'x' }) // true\n * ```\n */\nexport function isCodeBlockNode(node: MarkdownNode): node is CodeBlockNode {\n\treturn node.element === 'codeBlock'\n}\n\n/**\n * Determine whether a node is a blockquote block.\n *\n * @example\n * ```ts\n * isBlockquoteNode({ element: 'blockquote', children: [] }) // true\n * ```\n */\nexport function isBlockquoteNode(node: MarkdownNode): node is BlockquoteNode {\n\treturn node.element === 'blockquote'\n}\n\n/**\n * Determine whether a node is a thematic break (horizontal rule) block.\n *\n * @example\n * ```ts\n * isThematicBreakNode({ element: 'thematicBreak' }) // true\n * ```\n */\nexport function isThematicBreakNode(node: MarkdownNode): node is ThematicBreakNode {\n\treturn node.element === 'thematicBreak'\n}\n\n// === Inline guards\n\n/**\n * Determine whether a node is a plain text run.\n *\n * @example\n * ```ts\n * isTextNode({ element: 'text', value: 'hi' }) // true\n * ```\n */\nexport function isTextNode(node: MarkdownNode): node is TextNode {\n\treturn node.element === 'text'\n}\n\n/**\n * Determine whether a node is an emphasis run (`*em*` / `**strong**`).\n *\n * @example\n * ```ts\n * isEmphasisNode({ element: 'emphasis', strong: false, children: [] }) // true\n * ```\n */\nexport function isEmphasisNode(node: MarkdownNode): node is EmphasisNode {\n\treturn node.element === 'emphasis'\n}\n\n/**\n * Determine whether a node is an inline code span.\n *\n * @remarks\n * Narrows to {@link CodeSpanNode} - the node whose `element` discriminant is\n * `'codeSpan'`.\n *\n * @example\n * ```ts\n * isCodeSpanNode({ element: 'codeSpan', value: 'x' }) // true\n * ```\n */\nexport function isCodeSpanNode(node: MarkdownNode): node is CodeSpanNode {\n\treturn node.element === 'codeSpan'\n}\n\n/** Determine whether a node is a link. */\nexport function isLinkNode(node: MarkdownNode): node is LinkNode {\n\treturn node.element === 'link'\n}\n\n// === From-unknown AST guards\n//\n// The node guards above narrow an ALREADY-PARSED MarkdownNode by its `element`\n// tag. The guards below instead validate an arbitrary `unknown` value (untrusted\n// input - a deserialized AST, a value crossing a process/RPC boundary) against\n// the full node shape, field by field, composed from @orkestrel/contract\n// combinators. Each guard IS its own hoisted composed value (compiled once at\n// module init, not per call); inline<->block recursion (emphasis/link children,\n// list items, blockquote children) resolves through `lazyOf`, closing over the\n// exported guard names themselves - legal because `lazyOf`'s thunk resolves per\n// call, strictly after module init has assigned every export. @orkestrel/contract\n// guarantees guard totality (AGENTS §14): `lazyOf`, `unionOf`, `recordOf`, and\n// every built-in guard are throw-contained, so a hostile getter, a structural\n// cycle, or pathologically deep input returns `false` rather than throwing -\n// no additional `attempt` wrapping is needed here.\n\n/**\n * Determine whether an arbitrary value is a valid {@link InlineNode} - a text\n * run, emphasis, code span, or link, recursively validated.\n *\n * @remarks\n * Total: never throws, even on cyclic or pathologically deep input - every\n * combinator involved (`unionOf`, `recordOf`, `arrayOf`, `lazyOf`) is\n * throw-contained per the `@orkestrel/contract` guard contract (AGENTS §14).\n *\n * @param value - The value to test\n * @returns `true` when `value` is a well-formed {@link InlineNode}\n *\n * @example\n * ```ts\n * import { isInlineNode } from '@orkestrel/markdown'\n *\n * isInlineNode({ element: 'text', value: 'hi' }) // true\n * isInlineNode({ element: 'text' }) // false - missing `value`\n * ```\n */\nexport const isInlineNode: Guard<InlineNode> = unionOf(\n\trecordOf({ element: literalOf('text'), value: isString }),\n\trecordOf({\n\t\telement: literalOf('emphasis'),\n\t\tstrong: isBoolean,\n\t\tchildren: arrayOf(lazyOf(() => isInlineNode)),\n\t}),\n\trecordOf({ element: literalOf('codeSpan'), value: isString }),\n\trecordOf({\n\t\telement: literalOf('link'),\n\t\thref: isString,\n\t\tchildren: arrayOf(lazyOf(() => isInlineNode)),\n\t}),\n)\n\n/**\n * Determine whether an arbitrary value is a valid {@link BlockNode} - a\n * heading, paragraph, list, table, code block, blockquote, or thematic break,\n * recursively validated.\n *\n * @remarks\n * Total: never throws, even on cyclic or pathologically deep input - every\n * combinator involved (`unionOf`, `recordOf`, `arrayOf`, `lazyOf`) is\n * throw-contained per the `@orkestrel/contract` guard contract (AGENTS §14).\n * A list item's shape is inlined here (and in {@link isMarkdownNode}) rather\n * than named separately - it is used at exactly these two sites.\n *\n * @param value - The value to test\n * @returns `true` when `value` is a well-formed {@link BlockNode}\n *\n * @example\n * ```ts\n * import { isBlockNode } from '@orkestrel/markdown'\n *\n * isBlockNode({ element: 'thematicBreak' }) // true\n * isBlockNode({ element: 'heading' }) // false - missing `level` / `children`\n * ```\n */\nexport const isBlockNode: Guard<BlockNode> = unionOf(\n\trecordOf({ element: literalOf('heading'), level: isNumber, children: arrayOf(isInlineNode) }),\n\trecordOf({ element: literalOf('paragraph'), children: arrayOf(isInlineNode) }),\n\trecordOf({\n\t\telement: literalOf('list'),\n\t\tordered: isBoolean,\n\t\tstart: isNumber,\n\t\titems: arrayOf(\n\t\t\trecordOf({ element: literalOf('listItem'), children: arrayOf(lazyOf(() => isBlockNode)) }),\n\t\t),\n\t}),\n\trecordOf({\n\t\telement: literalOf('table'),\n\t\theader: arrayOf(arrayOf(isInlineNode)),\n\t\trows: arrayOf(arrayOf(arrayOf(isInlineNode))),\n\t\talign: arrayOf(literalOf('none', 'left', 'right', 'center')),\n\t}),\n\trecordOf({ element: literalOf('codeBlock'), lang: isString, code: isString }, ['lang']),\n\trecordOf({ element: literalOf('blockquote'), children: arrayOf(lazyOf(() => isBlockNode)) }),\n\trecordOf({ element: literalOf('thematicBreak') }),\n)\n\n/**\n * Determine whether an arbitrary value is a valid {@link MarkdownNode} - the\n * {@link MarkdownDocument} root, a {@link BlockNode}, a {@link ListItemNode}, or\n * an {@link InlineNode}, recursively validated.\n *\n * @remarks\n * Total: never throws, even on cyclic or pathologically deep input - every\n * combinator involved (`unionOf`, `recordOf`, `arrayOf`, `lazyOf`) is\n * throw-contained per the `@orkestrel/contract` guard contract (AGENTS §14).\n * A list item's shape is inlined here (and in {@link isBlockNode}) rather than\n * named separately - it is used at exactly these two sites.\n *\n * @param value - The value to test\n * @returns `true` when `value` is a well-formed {@link MarkdownNode}\n *\n * @example\n * ```ts\n * import { isMarkdownNode } from '@orkestrel/markdown'\n *\n * isMarkdownNode({ element: 'text', value: 'hi' }) // true\n * isMarkdownNode({ element: 'bogus' }) // false\n * ```\n */\nexport const isMarkdownNode: Guard<MarkdownNode> = unionOf(\n\tlazyOf(() => isMarkdownDocument),\n\tlazyOf(() => isBlockNode),\n\trecordOf({ element: literalOf('listItem'), children: arrayOf(lazyOf(() => isBlockNode)) }),\n\tlazyOf(() => isInlineNode),\n)\n\n/**\n * Determine whether an arbitrary value is a valid {@link MarkdownDocument} -\n * the parsed-AST root {@link parseDocument} returns, recursively\n * validated.\n *\n * @remarks\n * Total: never throws, even on cyclic or pathologically deep input - every\n * combinator involved (`recordOf`, `arrayOf`) is throw-contained per the\n * `@orkestrel/contract` guard contract (AGENTS §14).\n *\n * @param value - The value to test\n * @returns `true` when `value` is a well-formed {@link MarkdownDocument}\n *\n * @example\n * ```ts\n * import { isMarkdownDocument } from '@orkestrel/markdown'\n *\n * isMarkdownDocument({ element: 'document', children: [] }) // true\n * isMarkdownDocument({ element: 'document' }) // false - missing `children`\n * ```\n */\nexport const isMarkdownDocument: Guard<MarkdownDocument> = recordOf({\n\telement: literalOf('document'),\n\tchildren: arrayOf(isBlockNode),\n})\n","import type {\n\tBlockNode,\n\tEmphasisNode,\n\tInlineNode,\n\tLinkNode,\n\tListItemNode,\n\tListItemParts,\n\tMarkdownDocument,\n\tMarkdownHandlers,\n\tMarkdownNode,\n\tMarkdownRewriteHandler,\n\tTableAlign,\n\tTableNode,\n} from './types.js'\nimport { MAX_DEPTH, SAFE_URL_SCHEMES } from './constants.js'\nimport {\n\tisBlockNode,\n\tisEscapable,\n\tisInlineNode,\n\tisQuote,\n\tisTableStart,\n\tisThematicBreak,\n\tisWhitespace,\n} from './validators.js'\nimport { isEmptyString, isNonEmptyArray, isNonEmptyString, parseInteger } from '@orkestrel/contract'\n\n// Markdown parsing + rendering leaves (pure, total, zero-dependency)\n//\n// The pure leaf primitives {@link parseDocument} composes: the line / block\n// scanners (headings, fences, list items, table rows, quotes, thematic breaks), the\n// inline `scan*` engine (emphasis / links / code with backslash escapes), and the HTML\n// escaping + URL-sanitization the renderer leans on. Every function is PURE, TOTAL, and\n// referentially transparent - malformed input degrades to text, never throws (AGENTS\n// §14) - so each is unit-tested in isolation. The ORCHESTRATION that threads these\n// together (the block / inline / render recursion) lives in parsers.ts's functions,\n// not here (AGENTS §5): a helper is a functional-core leaf, a method is the\n// composition. Inline scanning is index-based (no backtracking regex) so it is\n// linear-time - no ReDoS on adversarial input.\n\n// Text + line utilities\n\n/**\n * Normalize line endings to `\\n` and split a markdown document into its lines - CRLF\n * (`\\r\\n`) and bare CR (`\\r`) both collapse to `\\n` first, so a Windows-origin\n * document parses identically. A single trailing newline does not yield a final\n * empty line.\n *\n * @param markdown - The raw markdown source\n * @returns The document's lines, line-terminators stripped\n *\n * @example\n * ```ts\n * splitLines('a\\r\\nb\\nc') // ['a', 'b', 'c']\n * ```\n */\nexport function splitLines(markdown: string): readonly string[] {\n\tconst lines = markdown.replace(/\\r\\n?/g, '\\n').split('\\n')\n\tif (lines.length > 1 && lines[lines.length - 1] === '') lines.pop()\n\treturn lines\n}\n\n/**\n * The count of leading space / tab characters on `line` (a tab counts as one) - the\n * indent that decides whether a list item's continuation belongs to the item.\n *\n * @param line - The line to measure\n * @returns The number of leading space / tab characters\n *\n * @example\n * ```ts\n * leadingIndent(' text') // 2\n * ```\n */\nexport function leadingIndent(line: string): number {\n\tlet count = 0\n\tfor (const character of line) {\n\t\tif (character === ' ' || character === '\\t') count += 1\n\t\telse break\n\t}\n\treturn count\n}\n\n// Block-level detection\n\n/**\n * Extract an ATX heading line (`#` … `######` followed by text) into its\n * `{ level, text }`, or `undefined` when `line` is not a heading. A run of more than 6\n * `#`s, or `#`s not followed by whitespace + text, is not a\n * heading; an optional closing `###` run is stripped.\n *\n * @param line - The candidate line\n * @returns The heading level (1–6) and its raw inline text, or `undefined`\n *\n * @example\n * ```ts\n * extractHeading('## Title') // { level: 2, text: 'Title' }\n * ```\n */\nexport function extractHeading(\n\tline: string,\n): { readonly level: number; readonly text: string } | undefined {\n\tconst match = /^(#{1,6})(?:\\s+(.*))?$/.exec(line.trimStart())\n\tif (!match || match[1] === undefined) return undefined\n\tconst level = match[1].length\n\tconst text = (match[2] ?? '').replace(/\\s+#+\\s*$/, '').trim()\n\treturn { level, text }\n}\n\n/**\n * Extract a fenced-code opening line (```` ``` ```` or `~~~`, optionally with an info\n * string) into its `{ marker, lang }`, or `undefined` when `line` is not a fence\n * opener. `marker` is the exact fence run (the closer must match the same character +\n * at least the same length); `lang` is the first word of the info string.\n *\n * @param line - The candidate line\n * @returns The fence marker run and its language tag, or `undefined`\n *\n * @example\n * ```ts\n * extractFence('```ts') // { marker: '```', lang: 'ts' }\n * ```\n */\nexport function extractFence(\n\tline: string,\n): { readonly marker: string; readonly lang: string | undefined } | undefined {\n\tconst match = /^\\s*(`{3,}|~{3,})\\s*(.*)$/.exec(line)\n\tif (!match || match[1] === undefined) return undefined\n\tconst info = (match[2] ?? '').trim()\n\t// A backtick in a backtick fence's info string is invalid (ambiguous with a span).\n\tif (match[1].startsWith('`') && info.includes('`')) return undefined\n\tconst lang = isNonEmptyString(info) ? info.split(/\\s+/)[0] : undefined\n\treturn { marker: match[1], lang }\n}\n\n/**\n * Extract a list-item line (`-` / `*` / `+` bullet, or `1.` / `1)` ordinal, followed by\n * a space) into its {@link ListItemParts}, or `undefined` when `line` is not a list\n * item. `content` is the text after the marker; `marker` is the full marker-plus-space\n * width (for measuring a continuation's indent).\n *\n * @param line - The candidate line\n * @returns The list-item parts, or `undefined` when not a list item\n *\n * @example\n * ```ts\n * extractListItem('- item') // { ordered: false, start: 1, content: 'item', indent: 0, marker: 2 }\n * ```\n */\nexport function extractListItem(line: string): ListItemParts | undefined {\n\tconst unordered = /^(\\s*)([-*+])\\s+(.*)$/.exec(line)\n\tif (unordered && unordered[1] !== undefined) {\n\t\tconst indent = unordered[1].length\n\t\tconst content = unordered[3] ?? ''\n\t\treturn { ordered: false, start: 1, content, indent, marker: line.length - content.length }\n\t}\n\tconst ordered = /^(\\s*)(\\d{1,9})[.)]\\s+(.*)$/.exec(line)\n\tif (ordered && ordered[1] !== undefined && ordered[2] !== undefined) {\n\t\tconst indent = ordered[1].length\n\t\tconst content = ordered[3] ?? ''\n\t\treturn {\n\t\t\tordered: true,\n\t\t\tstart: parseInteger(ordered[2]) ?? 1,\n\t\t\tcontent,\n\t\t\tindent,\n\t\t\tmarker: line.length - content.length,\n\t\t}\n\t}\n\treturn undefined\n}\n\n/**\n * Strip one level of blockquote marker (`>` plus one optional following space) from a\n * blockquote line, so the de-quoted lines re-parse as nested blocks.\n *\n * @param line - A blockquote line (per {@link isQuote})\n * @returns The line with its leading `>` (and one space) removed\n *\n * @example\n * ```ts\n * stripQuote('> text') // 'text'\n * ```\n */\nexport function stripQuote(line: string): string {\n\treturn line.replace(/^\\s{0,3}>\\s?/, '')\n}\n\n/**\n * Split one GFM table row into its cell strings - outer pipes are optional, an escaped\n * pipe (`\\|`) inside a cell is NOT a separator (it becomes a literal `|`), and the\n * empty leading / trailing cell produced by an outer `|` is dropped.\n *\n * @param row - The raw table row line\n * @returns The row's cells, in column order\n *\n * @example\n * ```ts\n * splitTableRow('|a|b|') // ['a', 'b']\n * ```\n */\nexport function splitTableRow(row: string): readonly string[] {\n\tconst cells: string[] = []\n\tlet current = ''\n\tconst trimmed = row.trim()\n\tfor (let index = 0; index < trimmed.length; index += 1) {\n\t\tconst character = trimmed[index]\n\t\tif (character === '\\\\' && trimmed[index + 1] === '|') {\n\t\t\tcurrent += '|'\n\t\t\tindex += 1\n\t\t} else if (character === '|') {\n\t\t\tcells.push(current)\n\t\t\tcurrent = ''\n\t\t} else {\n\t\t\tcurrent += character\n\t\t}\n\t}\n\tcells.push(current)\n\tif (isNonEmptyArray<string>(cells) && isEmptyString((cells[0] ?? '').trim())) cells.shift()\n\tif (isNonEmptyArray<string>(cells) && isEmptyString((cells[cells.length - 1] ?? '').trim()))\n\t\tcells.pop()\n\treturn cells\n}\n\n/**\n * Derive the per-column {@link TableAlign} list from a GFM delimiter row - `:---`\n * left, `---:` right, `:---:` center, `---` none.\n *\n * @param delimiter - The table's delimiter row\n * @returns One alignment per column, in column order\n *\n * @example\n * ```ts\n * tableAlignments('| :--- | ---: |') // ['left', 'right']\n * ```\n */\nexport function tableAlignments(delimiter: string): readonly TableAlign[] {\n\treturn splitTableRow(delimiter).map((cell) => {\n\t\tconst text = cell.trim()\n\t\tconst left = text.startsWith(':')\n\t\tconst right = text.endsWith(':')\n\t\tif (left && right) return 'center'\n\t\tif (right) return 'right'\n\t\tif (left) return 'left'\n\t\treturn 'none'\n\t})\n}\n\n// Block phase\n\n/**\n * Whether the line at `index` starts a NEW block kind (heading / fence / thematic\n * break / blockquote / list / table) - the paragraph collector stops at such a line\n * so a block following a paragraph without a blank line still parses (a trusted-input\n * caller writing a `##` heading directly under a paragraph, with no intervening blank\n * line).\n *\n * @param lines - The document's lines\n * @param index - The line index to test\n * @returns `true` when the line begins a different block\n *\n * @example\n * ```ts\n * startsBlock(['text', '## Heading'], 1) // true\n * ```\n */\nexport function startsBlock(lines: readonly string[], index: number): boolean {\n\tconst line = lines[index] ?? ''\n\treturn (\n\t\textractHeading(line) !== undefined ||\n\t\textractFence(line) !== undefined ||\n\t\tisThematicBreak(line) ||\n\t\tisQuote(line) ||\n\t\textractListItem(line) !== undefined ||\n\t\tisTableStart(line, lines[index + 1])\n\t)\n}\n\n// Inline phase\n\n/**\n * Resolve backslash escapes in a raw string to their literal characters - used for a\n * link `href` (which is not otherwise inline-parsed) and any plain text run.\n *\n * @param text - The raw text possibly carrying `\\x` escapes\n * @returns The text with escapable `\\x` reduced to `x`\n *\n * @example\n * ```ts\n * unescapeText('\\\\*hi\\\\*') // '*hi*'\n * ```\n */\nexport function unescapeText(text: string): string {\n\tlet out = ''\n\tfor (let index = 0; index < text.length; index += 1) {\n\t\tconst character = text[index] ?? ''\n\t\tif (character === '\\\\' && isEscapable(text[index + 1] ?? '')) {\n\t\t\tout += text[index + 1] ?? ''\n\t\t\tindex += 1\n\t\t} else {\n\t\t\tout += character\n\t\t}\n\t}\n\treturn out\n}\n\n/**\n * Merge adjacent text nodes into one - the inline scanner emits a text node per\n * unrecognized character, so coalescing keeps the AST clean and assertion-friendly.\n *\n * @param nodes - The inline nodes (possibly with adjacent text runs)\n * @returns The nodes with consecutive text nodes concatenated\n *\n * @example\n * ```ts\n * coalesceText([{ element: 'text', value: 'a' }, { element: 'text', value: 'b' }])\n * // [{ element: 'text', value: 'ab' }]\n * ```\n */\nexport function coalesceText(nodes: readonly InlineNode[]): readonly InlineNode[] {\n\tconst out: InlineNode[] = []\n\tfor (const node of nodes) {\n\t\tconst last = out[out.length - 1]\n\t\tif (node.element === 'text' && last !== undefined && last.element === 'text') {\n\t\t\tout[out.length - 1] = { element: 'text', value: last.value + node.value }\n\t\t} else {\n\t\t\tout.push(node)\n\t\t}\n\t}\n\treturn out\n}\n\n/**\n * Scan an inline code span at `start` (a `` ` ``-run … a matching `` ` ``-run of the\n * SAME length, the CommonMark rule that lets a span contain backticks). Returns the\n * span's literal text + end index, or `undefined` when no matching closer exists (it\n * then degrades to literal backticks).\n *\n * @param source - The inline source text\n * @param start - The index of the opening backtick\n * @param to - The exclusive end of the scan window\n * @returns The span text + end index, or `undefined`\n *\n * @example\n * ```ts\n * scanCode('`code`', 0, 6) // { value: 'code', end: 6 }\n * ```\n */\nexport function scanCode(\n\tsource: string,\n\tstart: number,\n\tto: number,\n): { readonly value: string; readonly end: number } | undefined {\n\tlet run = 0\n\twhile (start + run < to && source[start + run] === '`') run += 1\n\tconst open = '`'.repeat(run)\n\tlet search = start + run\n\tfor (;;) {\n\t\tconst closeAt = source.indexOf(open, search)\n\t\tif (closeAt === -1 || closeAt + run > to) return undefined\n\t\t// The closer must be EXACTLY `run` backticks (not bordered by another backtick).\n\t\tif (source[closeAt - 1] !== '`' && source[closeAt + run] !== '`') {\n\t\t\tlet value = source.slice(start + run, closeAt)\n\t\t\tif (\n\t\t\t\tvalue.length > 2 &&\n\t\t\t\tvalue.startsWith(' ') &&\n\t\t\t\tvalue.endsWith(' ') &&\n\t\t\t\tvalue.trim().length > 0\n\t\t\t) {\n\t\t\t\tvalue = value.slice(1, -1)\n\t\t\t}\n\t\t\treturn { value, end: closeAt + run }\n\t\t}\n\t\tsearch = closeAt + 1\n\t}\n}\n\n/**\n * Scan a link `[text](href)` at `start` - the text runs to a BALANCED `]`, then `(`\n * must immediately follow and the destination runs to the matching `)` (both respect\n * nested delimiters + escapes). Returns the link node, or `undefined` when the shape\n * does not hold (it then degrades to a literal `[`).\n *\n * @param source - The inline source text\n * @param start - The index of the opening `[`\n * @param to - The exclusive end of the scan window\n * @param depth - The current inline-recursion depth (defaults to 0 at the entry point);\n * at {@link MAX_DEPTH} the link's text children degrade to literal text instead of\n * recursing further\n * @returns The parsed {@link LinkNode} + end index, or `undefined`\n *\n * @example\n * ```ts\n * scanLink('[text](url)', 0, 11)\n * // { node: { element: 'link', href: 'url', children: [...] }, end: 11 }\n * ```\n */\nexport function scanLink(\n\tsource: string,\n\tstart: number,\n\tto: number,\n\tdepth = 0,\n): { readonly node: LinkNode; readonly end: number } | undefined {\n\tlet bracketDepth = 0\n\tlet close = -1\n\tfor (let index = start; index < to; index += 1) {\n\t\tconst character = source[index] ?? ''\n\t\tif (character === '\\\\') {\n\t\t\tindex += 1\n\t\t\tcontinue\n\t\t}\n\t\tif (character === '[') bracketDepth += 1\n\t\telse if (character === ']') {\n\t\t\tbracketDepth -= 1\n\t\t\tif (bracketDepth === 0) {\n\t\t\t\tclose = index\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\tif (close === -1 || source[close + 1] !== '(') return undefined\n\tlet parenDepth = 0\n\tlet parenClose = -1\n\tfor (let index = close + 1; index < to; index += 1) {\n\t\tconst character = source[index] ?? ''\n\t\tif (character === '\\\\') {\n\t\t\tindex += 1\n\t\t\tcontinue\n\t\t}\n\t\tif (character === '(') parenDepth += 1\n\t\telse if (character === ')') {\n\t\t\tparenDepth -= 1\n\t\t\tif (parenDepth === 0) {\n\t\t\t\tparenClose = index\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\tif (parenClose === -1) return undefined\n\tconst href = unescapeText(source.slice(close + 2, parenClose).trim())\n\tconst children = scanInline(source, start + 1, close, depth + 1)\n\treturn { node: { element: 'link', href, children }, end: parenClose + 1 }\n}\n\n/**\n * Scan an emphasis run at `start` (`*` / `_`, doubled for strong) - finds the nearest\n * matching closing run of the same marker + width, requiring non-space immediately\n * inside both delimiters (the CommonMark flanking simplification that blocks `* x *`).\n * Returns the emphasis node, or `undefined` when no valid closer exists (it then\n * degrades to a literal marker).\n *\n * @param source - The inline source text\n * @param start - The index of the opening marker\n * @param to - The exclusive end of the scan window\n * @param depth - The current inline-recursion depth (defaults to 0 at the entry point);\n * at {@link MAX_DEPTH} the emphasis's children degrade to literal text instead of\n * recursing further\n * @returns The parsed {@link EmphasisNode} + end index, or `undefined`\n *\n * @example\n * ```ts\n * scanEmphasis('*em*', 0, 4)\n * // { node: { element: 'emphasis', strong: false, children: [...] }, end: 4 }\n * ```\n */\nexport function scanEmphasis(\n\tsource: string,\n\tstart: number,\n\tto: number,\n\tdepth = 0,\n): { readonly node: EmphasisNode; readonly end: number } | undefined {\n\tconst marker = source[start] ?? ''\n\tlet run = 0\n\twhile (start + run < to && source[start + run] === marker && run < 2) run += 1\n\tconst strong = run === 2\n\tconst openEnd = start + run\n\tif (openEnd >= to || isWhitespace(source[openEnd] ?? '')) return undefined\n\tlet index = openEnd\n\twhile (index < to) {\n\t\tconst character = source[index] ?? ''\n\t\tif (character === '\\\\') {\n\t\t\tindex += 2\n\t\t\tcontinue\n\t\t}\n\t\tif (character === '`') {\n\t\t\tconst span = scanCode(source, index, to)\n\t\t\tindex = span ? span.end : index + 1\n\t\t\tcontinue\n\t\t}\n\t\tif (character === marker) {\n\t\t\tlet closeRun = 0\n\t\t\twhile (index + closeRun < to && source[index + closeRun] === marker) closeRun += 1\n\t\t\tif (closeRun >= run && !isWhitespace(source[index - 1] ?? '')) {\n\t\t\t\treturn {\n\t\t\t\t\tnode: {\n\t\t\t\t\t\telement: 'emphasis',\n\t\t\t\t\t\tstrong,\n\t\t\t\t\t\tchildren: scanInline(source, openEnd, index, depth + 1),\n\t\t\t\t\t},\n\t\t\t\t\tend: index + run,\n\t\t\t\t}\n\t\t\t}\n\t\t\tindex += closeRun\n\t\t\tcontinue\n\t\t}\n\t\tindex += 1\n\t}\n\treturn undefined\n}\n\n/**\n * Scan the window `[from, to)` of `source` into inline nodes - the single recursive\n * engine the inline phase runs on (emphasis / link text recurse through it). Linear:\n * each character is consumed once; a failed construct emits its opening character as\n * text and advances by one, so there is no re-scan (no ReDoS).\n *\n * @param source - The inline source text\n * @param from - The inclusive start of the scan window\n * @param to - The exclusive end of the scan window\n * @param depth - The current inline-recursion depth (defaults to 0 at the entry point);\n * incremented by one on every recursive descent through {@link scanLink} /\n * {@link scanEmphasis}. At {@link MAX_DEPTH} the window is never scanned for markup -\n * it emits as a single literal text node - so pathological nesting (`[[[[…`,\n * `****…`) cannot exhaust the call stack.\n * @returns The parsed inline nodes (NOT yet coalesced)\n *\n * @example\n * ```ts\n * scanInline('hi *there*', 0, 10) // [{ element: 'text', value: 'hi ' }, { element: 'emphasis', ... }]\n * ```\n */\nexport function scanInline(\n\tsource: string,\n\tfrom: number,\n\tto: number,\n\tdepth = 0,\n): readonly InlineNode[] {\n\tif (depth >= MAX_DEPTH)\n\t\treturn from < to ? [{ element: 'text', value: source.slice(from, to) }] : []\n\tconst nodes: InlineNode[] = []\n\tlet index = from\n\tlet pending = ''\n\tconst flush = (): void => {\n\t\tif (pending.length > 0) {\n\t\t\tnodes.push({ element: 'text', value: pending })\n\t\t\tpending = ''\n\t\t}\n\t}\n\twhile (index < to) {\n\t\tconst character = source[index] ?? ''\n\t\tif (character === '\\\\' && index + 1 < to && isEscapable(source[index + 1] ?? '')) {\n\t\t\tpending += source[index + 1] ?? ''\n\t\t\tindex += 2\n\t\t\tcontinue\n\t\t}\n\t\tif (character === '`') {\n\t\t\tconst span = scanCode(source, index, to)\n\t\t\tif (span) {\n\t\t\t\tflush()\n\t\t\t\tnodes.push({ element: 'codeSpan', value: span.value })\n\t\t\t\tindex = span.end\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t\tif (character === '[') {\n\t\t\tconst link = scanLink(source, index, to, depth)\n\t\t\tif (link) {\n\t\t\t\tflush()\n\t\t\t\tnodes.push(link.node)\n\t\t\t\tindex = link.end\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t\tif (character === '*' || character === '_') {\n\t\t\tconst emphasis = scanEmphasis(source, index, to, depth)\n\t\t\tif (emphasis) {\n\t\t\t\tflush()\n\t\t\t\tnodes.push(emphasis.node)\n\t\t\t\tindex = emphasis.end\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t\tpending += character\n\t\tindex += 1\n\t}\n\tflush()\n\treturn nodes\n}\n\n// Rendering (AST HTML string)\n\n/**\n * HTML-escape text content - `&` / `<` / `>` / `\"` / `'` to their entities - so text\n * from a markdown document can never inject markup. The renderer applies this to every\n * text run, code body, and (escaped further) attribute value.\n *\n * @param text - The raw text\n * @returns The HTML-escaped text\n *\n * @example\n * ```ts\n * escapeHtml('<a>&\"\\'') // '<a>&"''\n * ```\n */\nexport function escapeHtml(text: string): string {\n\treturn text\n\t\t.replace(/&/g, '&')\n\t\t.replace(/</g, '<')\n\t\t.replace(/>/g, '>')\n\t\t.replace(/\"/g, '"')\n\t\t.replace(/'/g, ''')\n}\n\n/**\n * Sanitize + HTML-attribute-escape a link `href` - a destination whose scheme is not\n * in {@link SAFE_URL_SCHEMES} (notably `javascript:` / `data:` / `vbscript:`), or that\n * is protocol-relative (`//host/path`, or a backslash variant a browser normalizes to\n * the same effect - `\\\\host`, `/\\host`, `\\/host` - inherits whatever scheme the\n * embedding page is served over, including an unsafe one), is dropped to an empty\n * string; a relative / anchor / scheme-less (and non-protocol-relative) destination\n * (including a SINGLE leading `/` or `\\`) is kept;\n * the surviving value is then HTML-escaped. Defence-in-depth against an XSS `href`,\n * even though the input is trusted.\n *\n * @param href - The raw link destination\n * @returns A safe, escaped `href` (empty when the scheme is unsafe or protocol-relative)\n *\n * @example\n * ```ts\n * sanitizeUrl('javascript:alert(1)') // ''\n * sanitizeUrl('/path') // '/path'\n * ```\n */\nexport function sanitizeUrl(href: string): string {\n\t// Strip every whitespace + C0/C1 control codepoint (≤ U+0020 or U+007F–U+009F)\n\t// anywhere - a `java\\tscript:` / embedded-newline scheme-spoofing evasion - by\n\t// codepoint, not a control-character regex class (AGENTS §1: no disables).\n\tlet cleaned = ''\n\tfor (const character of href) {\n\t\tconst code = character.codePointAt(0) ?? 0\n\t\tif (code > 0x20 && !(code >= 0x7f && code <= 0x9f)) cleaned += character\n\t}\n\tif (/^[/\\\\]{2}/.exec(cleaned)) return ''\n\tconst scheme = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(cleaned)\n\tif (scheme && scheme[1] !== undefined && !SAFE_URL_SCHEMES.has(scheme[1].toLowerCase())) return ''\n\treturn escapeHtml(cleaned)\n}\n\n/**\n * Render a {@link MarkdownNode} (typically a {@link MarkdownDocument}) to a safe HTML\n * string - the recursive AST → HTML engine (headings, paragraphs, lists, GFM tables,\n * fenced code, blockquotes, links, emphasis, inline code), escaping every text run and\n * sanitizing every link `href`.\n *\n * @remarks\n * Total: never throws. At {@link MAX_DEPTH} a value-bearing node (`text` / `codeSpan`)\n * degrades to its escaped `value`; any other node degrades to `''` instead of\n * recursing further, so pathologically deep input cannot exhaust the call stack. The\n * recursive engine and its per-shape sub-steps (inline concatenation, table cell,\n * tight list-item) are nested inner functions - the only exported surface is\n * `renderHTML` itself.\n *\n * @param node - The AST node to render (a full document, or any sub-node)\n * @returns The rendered, XSS-safe HTML string\n *\n * @example\n * ```ts\n * renderHTML({ element: 'document', children: [\n * { element: 'heading', level: 1, children: [{ element: 'text', value: 'Hi' }] },\n * ] })\n * // '<h1>Hi</h1>'\n * ```\n */\nexport function renderHTML(node: MarkdownNode): string {\n\tfunction render(current: MarkdownNode, depth: number): string {\n\t\tif (depth >= MAX_DEPTH)\n\t\t\treturn 'value' in current && typeof current.value === 'string'\n\t\t\t\t? escapeHtml(current.value)\n\t\t\t\t: ''\n\t\tswitch (current.element) {\n\t\t\tcase 'document':\n\t\t\t\treturn current.children.map((child) => render(child, depth + 1)).join('\\n')\n\t\t\tcase 'heading':\n\t\t\t\treturn `<h${current.level}>${renderInline(current.children, depth)}</h${current.level}>`\n\t\t\tcase 'paragraph':\n\t\t\t\treturn `<p>${renderInline(current.children, depth)}</p>`\n\t\t\tcase 'thematicBreak':\n\t\t\t\treturn '<hr>'\n\t\t\tcase 'blockquote':\n\t\t\t\treturn `<blockquote>\\n${current.children.map((child) => render(child, depth + 1)).join('\\n')}\\n</blockquote>`\n\t\t\tcase 'codeBlock': {\n\t\t\t\tconst open =\n\t\t\t\t\tcurrent.lang === undefined\n\t\t\t\t\t\t? '<code>'\n\t\t\t\t\t\t: `<code class=\"language-${escapeHtml(current.lang)}\">`\n\t\t\t\treturn `<pre>${open}${escapeHtml(current.code)}</code></pre>`\n\t\t\t}\n\t\t\tcase 'list': {\n\t\t\t\tconst items = current.items.map((item) => render(item, depth + 1)).join('\\n')\n\t\t\t\tif (!current.ordered) return `<ul>\\n${items}\\n</ul>`\n\t\t\t\tconst start = current.start !== 1 ? ` start=\"${current.start}\"` : ''\n\t\t\t\treturn `<ol${start}>\\n${items}\\n</ol>`\n\t\t\t}\n\t\t\tcase 'listItem':\n\t\t\t\treturn `<li>${renderItem(current.children, depth)}</li>`\n\t\t\tcase 'table': {\n\t\t\t\tconst head = `<tr>${current.header.map((cell, column) => renderCell('th', cell, current.align[column], depth)).join('')}</tr>`\n\t\t\t\tconst body = current.rows\n\t\t\t\t\t.map(\n\t\t\t\t\t\t(row) =>\n\t\t\t\t\t\t\t`<tr>${row.map((cell, column) => renderCell('td', cell, current.align[column], depth)).join('')}</tr>`,\n\t\t\t\t\t)\n\t\t\t\t\t.join('\\n')\n\t\t\t\tconst bodyHtml = isNonEmptyArray(current.rows) ? `\\n<tbody>\\n${body}\\n</tbody>` : ''\n\t\t\t\treturn `<table>\\n<thead>\\n${head}\\n</thead>${bodyHtml}\\n</table>`\n\t\t\t}\n\t\t\tcase 'text':\n\t\t\t\treturn escapeHtml(current.value)\n\t\t\tcase 'emphasis':\n\t\t\t\treturn current.strong\n\t\t\t\t\t? `<strong>${renderInline(current.children, depth + 1)}</strong>`\n\t\t\t\t\t: `<em>${renderInline(current.children, depth + 1)}</em>`\n\t\t\tcase 'codeSpan':\n\t\t\t\treturn `<code>${escapeHtml(current.value)}</code>`\n\t\t\tcase 'link':\n\t\t\t\treturn `<a href=\"${sanitizeUrl(current.href)}\">${renderInline(current.children, depth + 1)}</a>`\n\t\t\tdefault:\n\t\t\t\treturn ''\n\t\t}\n\t}\n\n\tfunction renderInline(nodes: readonly InlineNode[], depth: number): string {\n\t\treturn nodes.map((child) => render(child, depth + 1)).join('')\n\t}\n\n\tfunction renderCell(\n\t\ttag: 'th' | 'td',\n\t\tcell: readonly InlineNode[],\n\t\talign: TableAlign | undefined,\n\t\tdepth: number,\n\t): string {\n\t\tconst style =\n\t\t\talign === 'left' || align === 'right' || align === 'center'\n\t\t\t\t? ` style=\"text-align:${align}\"`\n\t\t\t\t: ''\n\t\treturn `<${tag}${style}>${renderInline(cell, depth + 1)}</${tag}>`\n\t}\n\n\tfunction renderItem(children: readonly BlockNode[], depth: number): string {\n\t\tif (children.length === 1) {\n\t\t\tconst only = children[0]\n\t\t\tif (only !== undefined && only.element === 'paragraph')\n\t\t\t\treturn renderInline(only.children, depth)\n\t\t}\n\t\treturn children.map((child) => render(child, depth + 1)).join('\\n')\n\t}\n\n\treturn render(node, 0)\n}\n\n/**\n * Render a {@link MarkdownNode} to its CANONICAL markdown source - the inverse\n * projection of `renderHTML`, and the serializer a `parse(renderMarkdown(doc))`\n * round-trip is built on. Canonical forms: `*em*` / `**strong**` (underscore emphasis\n * normalizes to asterisks), `- ` bullets, `N. ` sequential ordinals (from the list's\n * `start`), `---` thematic breaks, fenced code blocks (backtick run widened past any\n * 3+ backtick run inside the body), ATX headings, `> `-prefixed blockquote lines, GFM\n * tables (1-space-padded cells, `\\|`-escaped pipes, an alignment delimiter row), and\n * `[text](href)` links. A `text` node's literal content is backslash-escaped wherever\n * it would otherwise re-parse as markup (AGENTS §14 parse↔render soundness).\n *\n * @remarks\n * Total: never throws. At {@link MAX_DEPTH} a value-bearing node degrades to its\n * escaped `value`; any other node degrades to `''`. Blocks are joined by exactly one\n * blank line; a document with zero blocks renders `''`.\n *\n * @param node - The AST node to render (a full document, or any sub-node)\n * @returns The canonical markdown source\n *\n * @example\n * ```ts\n * renderMarkdown({ element: 'document', children: [\n * { element: 'heading', level: 2, children: [{ element: 'text', value: 'Hi' }] },\n * ] })\n * // '## Hi'\n * ```\n */\nexport function renderMarkdown(node: MarkdownNode): string {\n\tfunction escapeText(value: string): string {\n\t\tlet out = ''\n\t\tfor (let index = 0; index < value.length; index += 1) {\n\t\t\tconst character = value[index] ?? ''\n\t\t\tconst atLineStart = index === 0 || value[index - 1] === '\\n'\n\t\t\tif (\n\t\t\t\tcharacter === '\\\\' ||\n\t\t\t\tcharacter === '*' ||\n\t\t\t\tcharacter === '_' ||\n\t\t\t\tcharacter === '`' ||\n\t\t\t\tcharacter === '[' ||\n\t\t\t\tcharacter === ']'\n\t\t\t) {\n\t\t\t\tout += `\\\\${character}`\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (atLineStart) {\n\t\t\t\tif (character === '#' || character === '>') {\n\t\t\t\t\tout += `\\\\${character}`\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif ((character === '-' || character === '+') && (value[index + 1] ?? ' ') === ' ') {\n\t\t\t\t\tout += `\\\\${character}`\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (/[0-9]/.test(character)) {\n\t\t\t\t\tlet end = index\n\t\t\t\t\twhile (end < value.length && /[0-9]/.test(value[end] ?? '')) end += 1\n\t\t\t\t\tconst marker = value[end]\n\t\t\t\t\tif ((marker === '.' || marker === ')') && value[end + 1] === ' ') {\n\t\t\t\t\t\tout += `${value.slice(index, end)}\\\\${marker}`\n\t\t\t\t\t\tindex = end\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tout += character\n\t\t}\n\t\treturn out\n\t}\n\n\tfunction fenceFor(body: string, minimum: number): string {\n\t\tlet longest = 0\n\t\tlet run = 0\n\t\tfor (const character of body) {\n\t\t\tif (character === '`') {\n\t\t\t\trun += 1\n\t\t\t\tlongest = Math.max(longest, run)\n\t\t\t} else {\n\t\t\t\trun = 0\n\t\t\t}\n\t\t}\n\t\treturn '`'.repeat(Math.max(minimum, longest + 1))\n\t}\n\n\tfunction renderInline(nodes: readonly InlineNode[], depth: number): string {\n\t\treturn nodes.map((child) => render(child, depth + 1)).join('')\n\t}\n\n\tfunction renderBlocks(blocks: readonly BlockNode[], depth: number): string {\n\t\treturn blocks.map((block) => render(block, depth + 1)).join('\\n\\n')\n\t}\n\n\tfunction renderItem(item: ListItemNode, marker: string, depth: number): string {\n\t\tconst body = renderBlocks(item.children, depth + 1)\n\t\tconst pad = ' '.repeat(marker.length)\n\t\treturn body\n\t\t\t.split('\\n')\n\t\t\t.map((line, index) => (index === 0 ? marker + line : line === '' ? '' : pad + line))\n\t\t\t.join('\\n')\n\t}\n\n\tfunction renderCell(cell: readonly InlineNode[], depth: number): string {\n\t\treturn renderInline(cell, depth + 1).replace(/\\|/g, '\\\\|')\n\t}\n\n\tfunction renderTable(current: TableNode, depth: number): string {\n\t\tconst columns = current.header.length\n\t\tconst headerRow = `| ${current.header.map((cell) => renderCell(cell, depth)).join(' | ')} |`\n\t\tconst delimiterRow = `| ${current.align\n\t\t\t.map((align) => {\n\t\t\t\tif (align === 'left') return ':--'\n\t\t\t\tif (align === 'right') return '--:'\n\t\t\t\tif (align === 'center') return ':-:'\n\t\t\t\treturn '---'\n\t\t\t})\n\t\t\t.join(' | ')} |`\n\t\tconst bodyRows = current.rows.map((row) => {\n\t\t\tconst cells: string[] = []\n\t\t\tfor (let column = 0; column < columns; column += 1) {\n\t\t\t\tconst cell = row[column]\n\t\t\t\tcells.push(cell === undefined ? '' : renderCell(cell, depth))\n\t\t\t}\n\t\t\treturn `| ${cells.join(' | ')} |`\n\t\t})\n\t\treturn [headerRow, delimiterRow, ...bodyRows].join('\\n')\n\t}\n\n\tfunction render(current: MarkdownNode, depth: number): string {\n\t\tif (depth >= MAX_DEPTH)\n\t\t\treturn 'value' in current && typeof current.value === 'string'\n\t\t\t\t? escapeText(current.value)\n\t\t\t\t: ''\n\t\tswitch (current.element) {\n\t\t\tcase 'document':\n\t\t\t\treturn renderBlocks(current.children, depth)\n\t\t\tcase 'heading': {\n\t\t\t\tconst text = renderInline(current.children, depth)\n\t\t\t\t// A trailing `#` run reads back as an ATX closing sequence on reparse -\n\t\t\t\t// escape the FIRST `#` of that run so it can't be stripped. Only fire when\n\t\t\t\t// the char preceding the run isn't a backslash - escapeText already escapes\n\t\t\t\t// a line-start `#`, and re-escaping it here would double-escape (`## #` -> text\n\t\t\t\t// \"#\" -> escapeText \"\\#\" -> would become \"\\\\#\" and break round-trip).\n\t\t\t\tconst escaped = text.replace(/(^|[^\\\\])(#+)$/, (_match, pre: string, hashes: string) => {\n\t\t\t\t\tconst first = hashes[0] ?? ''\n\t\t\t\t\treturn `${pre}\\\\${first}${hashes.slice(1)}`\n\t\t\t\t})\n\t\t\t\treturn `${'#'.repeat(current.level)} ${escaped}`\n\t\t\t}\n\t\t\tcase 'paragraph':\n\t\t\t\treturn renderInline(current.children, depth)\n\t\t\tcase 'thematicBreak':\n\t\t\t\treturn '---'\n\t\t\tcase 'blockquote': {\n\t\t\t\tconst inner = renderBlocks(current.children, depth)\n\t\t\t\treturn inner\n\t\t\t\t\t.split('\\n')\n\t\t\t\t\t.map((line) => (line === '' ? '>' : `> ${line}`))\n\t\t\t\t\t.join('\\n')\n\t\t\t}\n\t\t\tcase 'codeBlock': {\n\t\t\t\tconst fence = fenceFor(current.code, 3)\n\t\t\t\tconst lang = current.lang === undefined ? '' : current.lang\n\t\t\t\treturn `${fence}${lang}\\n${current.code}\\n${fence}`\n\t\t\t}\n\t\t\tcase 'list': {\n\t\t\t\tlet ordinal = current.start\n\t\t\t\tconst items = current.items.map((item) => {\n\t\t\t\t\tconst marker = current.ordered ? `${ordinal++}. ` : '- '\n\t\t\t\t\treturn renderItem(item, marker, depth)\n\t\t\t\t})\n\t\t\t\treturn items.join('\\n')\n\t\t\t}\n\t\t\tcase 'listItem':\n\t\t\t\treturn renderBlocks(current.children, depth)\n\t\t\tcase 'table':\n\t\t\t\treturn renderTable(current, depth)\n\t\t\tcase 'text':\n\t\t\t\treturn escapeText(current.value)\n\t\t\tcase 'emphasis': {\n\t\t\t\tconst marker = current.strong ? '**' : '*'\n\t\t\t\treturn `${marker}${renderInline(current.children, depth)}${marker}`\n\t\t\t}\n\t\t\tcase 'codeSpan': {\n\t\t\t\tconst fence = fenceFor(current.value, 1)\n\t\t\t\tconst pad = current.value.startsWith('`') || current.value.endsWith('`') ? ' ' : ''\n\t\t\t\treturn `${fence}${pad}${current.value}${pad}${fence}`\n\t\t\t}\n\t\t\tcase 'link': {\n\t\t\t\t// Mirror scanLink's unescape - a href containing `\\`, `(`, or `)` must\n\t\t\t\t// round-trip through the same balanced-paren + backslash-escape scan.\n\t\t\t\tconst href = current.href.replace(/[\\\\()]/g, (character) => `\\\\${character}`)\n\t\t\t\treturn `[${renderInline(current.children, depth)}](${href})`\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn ''\n\t\t}\n\t}\n\n\treturn render(node, 0)\n}\n\n/**\n * Depth-first, pre-order, root-inclusive traversal of a {@link MarkdownNode} - yields\n * the node itself, then recurses into its children (block children, list items, table\n * header/row cells' inline nodes) in walk order.\n *\n * @remarks\n * Total: never throws. Descent stops at {@link MAX_DEPTH} (the node at the cap is\n * still yielded; its children are not) so pathologically deep input cannot exhaust\n * the call stack.\n *\n * @param node - The AST node to walk (a full document, or any sub-node)\n * @returns A generator yielding every visited node, pre-order\n *\n * @example\n * ```ts\n * const doc = { element: 'document', children: [{ element: 'thematicBreak' }] } as const\n * [...walkNodes(doc)].map((node) => node.element) // ['document', 'thematicBreak']\n * ```\n */\nexport function* walkNodes(node: MarkdownNode): Generator<MarkdownNode> {\n\tfunction* walk(current: MarkdownNode, depth: number): Generator<MarkdownNode> {\n\t\tyield current\n\t\tif (depth >= MAX_DEPTH) return\n\t\tswitch (current.element) {\n\t\t\tcase 'document':\n\t\t\tcase 'heading':\n\t\t\tcase 'paragraph':\n\t\t\tcase 'blockquote':\n\t\t\tcase 'listItem':\n\t\t\tcase 'emphasis':\n\t\t\tcase 'link':\n\t\t\t\tfor (const child of current.children) yield* walk(child, depth + 1)\n\t\t\t\treturn\n\t\t\tcase 'list':\n\t\t\t\tfor (const item of current.items) yield* walk(item, depth + 1)\n\t\t\t\treturn\n\t\t\tcase 'table':\n\t\t\t\tfor (const cell of current.header) for (const inline of cell) yield* walk(inline, depth + 1)\n\t\t\t\tfor (const row of current.rows)\n\t\t\t\t\tfor (const cell of row) for (const inline of cell) yield* walk(inline, depth + 1)\n\t\t\t\treturn\n\t\t\tdefault:\n\t\t\t\treturn\n\t\t}\n\t}\n\tyield* walk(node, 0)\n}\n\n/**\n * Fold a {@link MarkdownNode} into a `T` via a total catamorphism - children are\n * folded first (post-order), then the node's own {@link MarkdownHandler} is invoked\n * with the already-folded children.\n *\n * @remarks\n * **Table contract.** A {@link TableNode} has no single `children` array - its cells\n * live in `header` (one inline-node list per column) and `rows` (a list of such\n * rows). The `table` handler receives ONE folded `T` per inline node, flattened in\n * walk order across ALL cells - every header cell's inline nodes (column order), then\n * every body row's cells' inline nodes (row order, then column order) - and reads\n * `node.header[c].length` / `node.rows[r][c].length` off the table node itself to\n * recover cell boundaries within the flat list.\n *\n * Total: never throws. At `depth >= {@link MAX_DEPTH}` the node's handler is invoked\n * with an empty children list instead of recursing further.\n *\n * @param node - The AST node to fold\n * @param handlers - The total {@link MarkdownHandlers} table, one handler per element\n * @param depth - The starting recursion depth (pass `0` at the entry point)\n * @returns The folded `T`\n *\n * @example\n * ```ts\n * const countHandlers: MarkdownHandlers<number> = {\n * document: (_, children) => children.reduce((a, b) => a + b, 1),\n * // ...one handler per element, each summing its folded children\n * }\n * foldNode(document, countHandlers, 0) // total node count\n * ```\n */\nexport function foldNode<T>(node: MarkdownNode, handlers: MarkdownHandlers<T>, depth: number): T {\n\tfunction dispatch(current: MarkdownNode, children: readonly T[]): T {\n\t\tswitch (current.element) {\n\t\t\tcase 'document':\n\t\t\t\treturn handlers.document(current, children)\n\t\t\tcase 'heading':\n\t\t\t\treturn handlers.heading(current, children)\n\t\t\tcase 'paragraph':\n\t\t\t\treturn handlers.paragraph(current, children)\n\t\t\tcase 'thematicBreak':\n\t\t\t\treturn handlers.thematicBreak(current, children)\n\t\t\tcase 'blockquote':\n\t\t\t\treturn handlers.blockquote(current, children)\n\t\t\tcase 'codeBlock':\n\t\t\t\treturn handlers.codeBlock(current, children)\n\t\t\tcase 'list':\n\t\t\t\treturn handlers.list(current, children)\n\t\t\tcase 'listItem':\n\t\t\t\treturn handlers.listItem(current, children)\n\t\t\tcase 'table':\n\t\t\t\treturn handlers.table(current, children)\n\t\t\tcase 'text':\n\t\t\t\treturn handlers.text(current, children)\n\t\t\tcase 'emphasis':\n\t\t\t\treturn handlers.emphasis(current, children)\n\t\t\tcase 'codeSpan':\n\t\t\t\treturn handlers.codeSpan(current, children)\n\t\t\tcase 'link':\n\t\t\t\treturn handlers.link(current, children)\n\t\t}\n\t}\n\n\tfunction childNodes(current: MarkdownNode): readonly MarkdownNode[] {\n\t\tswitch (current.element) {\n\t\t\tcase 'document':\n\t\t\tcase 'heading':\n\t\t\tcase 'paragraph':\n\t\t\tcase 'blockquote':\n\t\t\tcase 'listItem':\n\t\t\tcase 'emphasis':\n\t\t\tcase 'link':\n\t\t\t\treturn current.children\n\t\t\tcase 'list':\n\t\t\t\treturn current.items\n\t\t\tcase 'table': {\n\t\t\t\tconst header = current.header.flatMap((cell) => cell)\n\t\t\t\tconst rows = current.rows.flatMap((row) => row.flatMap((cell) => cell))\n\t\t\t\treturn [...header, ...rows]\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn []\n\t\t}\n\t}\n\n\tfunction fold(current: MarkdownNode, level: number): T {\n\t\tif (level >= MAX_DEPTH) return dispatch(current, [])\n\t\tconst children = childNodes(current).map((child) => fold(child, level + 1))\n\t\treturn dispatch(current, children)\n\t}\n\n\treturn fold(node, depth)\n}\n\n/**\n * Rewrite a {@link MarkdownDocument} bottom-up (copy-on-write) - each node's children\n * are rewritten first (post-order), then `rewrite` is applied to the node itself; the\n * document ROOT is never passed to `rewrite` (the `element: 'document'` invariant\n * always holds). A table's inline cells and a list's items ARE rewritten.\n *\n * @remarks\n * Never mutates `document` - every level is rebuilt into a fresh object/array, even\n * when `rewrite` returns its input unchanged. When `rewrite` returns a node whose\n * `element` does not fit the slot it was called for (a block slot handed a\n * non-{@link BlockNode}, an inline slot handed a non-{@link InlineNode}, a list-item\n * slot handed a non-`listItem`), the ill-fitting result is discarded and the\n * freshly-rebuilt (unrewritten-at-this-level) node is kept instead - `rewriteDocument`\n * stays total and never produces a structurally invalid document.\n *\n * Descent is capped at {@link MAX_DEPTH}, the same cap {@link walkNodes} and\n * {@link foldNode} observe: at `depth >= MAX_DEPTH` the subtree is passed through\n * UNCHANGED (by reference, not rebuilt, and `rewrite` is not invoked on it) instead of\n * recursing further, so a pathologically deep adopted document cannot exhaust the\n * call stack. {@link MarkdownInterface.map} inherits this cap since it delegates here.\n *\n * @param document - The document AST to rewrite\n * @param rewrite - The bottom-up {@link MarkdownRewriteHandler}\n * @returns A new, rewritten {@link MarkdownDocument}\n *\n * @example\n * ```ts\n * rewriteDocument(document, (node) =>\n * node.element === 'text' ? { element: 'text', value: node.value.toUpperCase() } : node,\n * )\n * ```\n */\nexport function rewriteDocument(\n\tdocument: MarkdownDocument,\n\trewrite: MarkdownRewriteHandler,\n): MarkdownDocument {\n\tfunction rewriteInline(node: InlineNode, depth: number): InlineNode {\n\t\tif (depth >= MAX_DEPTH) return node\n\t\tconst rebuilt = rebuildInline(node, depth)\n\t\tconst result = rewrite(rebuilt)\n\t\treturn isInlineNode(result) ? result : rebuilt\n\t}\n\n\tfunction rewriteBlock(node: BlockNode, depth: number): BlockNode {\n\t\tif (depth >= MAX_DEPTH) return node\n\t\tconst rebuilt = rebuildBlock(node, depth)\n\t\tconst result = rewrite(rebuilt)\n\t\treturn isBlockNode(result) ? result : rebuilt\n\t}\n\n\tfunction rewriteItem(item: ListItemNode, depth: number): ListItemNode {\n\t\tif (depth >= MAX_DEPTH) return item\n\t\tconst rebuilt: ListItemNode = {\n\t\t\telement: 'listItem',\n\t\t\tchildren: item.children.map((child) => rewriteBlock(child, depth + 1)),\n\t\t}\n\t\tconst result = rewrite(rebuilt)\n\t\treturn result.element === 'listItem' ? result : rebuilt\n\t}\n\n\tfunction rebuildInline(node: InlineNode, depth: number): InlineNode {\n\t\tswitch (node.element) {\n\t\t\tcase 'emphasis':\n\t\t\t\treturn { ...node, children: node.children.map((child) => rewriteInline(child, depth + 1)) }\n\t\t\tcase 'link':\n\t\t\t\treturn { ...node, children: node.children.map((child) => rewriteInline(child, depth + 1)) }\n\t\t\tcase 'text':\n\t\t\tcase 'codeSpan':\n\t\t\t\treturn node\n\t\t}\n\t}\n\n\tfunction rebuildBlock(node: BlockNode, depth: number): BlockNode {\n\t\tswitch (node.element) {\n\t\t\tcase 'heading':\n\t\t\t\treturn { ...node, children: node.children.map((child) => rewriteInline(child, depth + 1)) }\n\t\t\tcase 'paragraph':\n\t\t\t\treturn { ...node, children: node.children.map((child) => rewriteInline(child, depth + 1)) }\n\t\t\tcase 'blockquote':\n\t\t\t\treturn { ...node, children: node.children.map((child) => rewriteBlock(child, depth + 1)) }\n\t\t\tcase 'list':\n\t\t\t\treturn { ...node, items: node.items.map((item) => rewriteItem(item, depth + 1)) }\n\t\t\tcase 'table':\n\t\t\t\treturn {\n\t\t\t\t\t...node,\n\t\t\t\t\theader: node.header.map((cell) => cell.map((inline) => rewriteInline(inline, depth + 1))),\n\t\t\t\t\trows: node.rows.map((row) =>\n\t\t\t\t\t\trow.map((cell) => cell.map((inline) => rewriteInline(inline, depth + 1))),\n\t\t\t\t\t),\n\t\t\t\t}\n\t\t\tcase 'codeBlock':\n\t\t\tcase 'thematicBreak':\n\t\t\t\treturn node\n\t\t}\n\t}\n\n\treturn { element: 'document', children: document.children.map((child) => rewriteBlock(child, 0)) }\n}\n\n/**\n * Concatenate the `value` / `code` content of every descendant text / code-span /\n * code-block node under `node`, in walk order - the plain-text projection of an AST\n * (search indexing, word counts, a text-only preview).\n *\n * @remarks\n * Total: never throws. Descent stops at {@link MAX_DEPTH} (contributes `''` past the\n * cap instead of recursing further).\n *\n * @param node - The AST node to flatten (a full document, or any sub-node)\n * @returns The concatenated text content\n *\n * @example\n * ```ts\n * flattenText({ element: 'paragraph', children: [\n * { element: 'text', value: 'a ' },\n * { element: 'codeSpan', value: 'b' },\n * ] })\n * // 'a b'\n * ```\n */\nexport function flattenText(node: MarkdownNode): string {\n\tfunction flatten(current: MarkdownNode, depth: number): string {\n\t\tif (depth >= MAX_DEPTH) return ''\n\t\tswitch (current.element) {\n\t\t\tcase 'text':\n\t\t\t\treturn current.value\n\t\t\tcase 'codeSpan':\n\t\t\t\treturn current.value\n\t\t\tcase 'codeBlock':\n\t\t\t\treturn current.code\n\t\t\tcase 'document':\n\t\t\tcase 'heading':\n\t\t\tcase 'paragraph':\n\t\t\tcase 'blockquote':\n\t\t\tcase 'listItem':\n\t\t\tcase 'emphasis':\n\t\t\tcase 'link':\n\t\t\t\treturn current.children.map((child) => flatten(child, depth + 1)).join('')\n\t\t\tcase 'list':\n\t\t\t\treturn current.items.map((item) => flatten(item, depth + 1)).join('')\n\t\t\tcase 'table': {\n\t\t\t\tconst header = current.header\n\t\t\t\t\t.map((cell) => cell.map((inline) => flatten(inline, depth + 1)).join(''))\n\t\t\t\t\t.join('')\n\t\t\t\tconst rows = current.rows\n\t\t\t\t\t.map((row) =>\n\t\t\t\t\t\trow.map((cell) => cell.map((inline) => flatten(inline, depth + 1)).join('')).join(''),\n\t\t\t\t\t)\n\t\t\t\t\t.join('')\n\t\t\t\treturn header + rows\n\t\t\t}\n\t\t\tcase 'thematicBreak':\n\t\t\t\treturn ''\n\t\t\tdefault:\n\t\t\t\treturn ''\n\t\t}\n\t}\n\treturn flatten(node, 0)\n}\n","import type {\n\tBlockNode,\n\tInlineNode,\n\tListItemNode,\n\tListNode,\n\tMarkdownDocument,\n\tTableAlign,\n\tTableNode,\n} from './types.js'\nimport {\n\tcoalesceText,\n\tleadingIndent,\n\textractFence,\n\textractHeading,\n\textractListItem,\n\tscanInline,\n\tsplitLines,\n\tsplitTableRow,\n\tstartsBlock,\n\tstripQuote,\n\ttableAlignments,\n} from './helpers.js'\nimport { isBlankLine, isFenceClose, isQuote, isTableStart, isThematicBreak } from './validators.js'\nimport { MAX_DEPTH } from './constants.js'\nimport { isNonEmptyArray } from '@orkestrel/contract'\n\n/**\n * Parses a run of markdown lines into a block AST, recursing into nested\n * blockquotes, list items, and depth-capped degrade paragraphs.\n *\n * @param lines - The markdown lines to parse.\n * @param depth - The current recursion depth (blockquotes/lists increment it).\n * @returns The parsed block nodes.\n *\n * @example\n * ```ts\n * parseBlocks(['# Hi'], 0) // [{ element: 'heading', level: 1, children: [...] }]\n * ```\n */\nexport function parseBlocks(lines: readonly string[], depth: number): readonly BlockNode[] {\n\tif (depth >= MAX_DEPTH) {\n\t\treturn lines.length > 0\n\t\t\t? [{ element: 'paragraph', children: [{ element: 'text', value: lines.join('\\n') }] }]\n\t\t\t: []\n\t}\n\tconst blocks: BlockNode[] = []\n\tlet index = 0\n\twhile (index < lines.length) {\n\t\tconst line = lines[index] ?? ''\n\t\tif (isBlankLine(line)) {\n\t\t\tindex += 1\n\t\t\tcontinue\n\t\t}\n\t\tconst fence = extractFence(line)\n\t\tif (fence) {\n\t\t\tconst body: string[] = []\n\t\t\tindex += 1\n\t\t\twhile (index < lines.length && !isFenceClose(lines[index] ?? '', fence.marker)) {\n\t\t\t\tbody.push(lines[index] ?? '')\n\t\t\t\tindex += 1\n\t\t\t}\n\t\t\tindex += 1 // step past the closing fence (a no-op past EOF)\n\t\t\tblocks.push({\n\t\t\t\telement: 'codeBlock',\n\t\t\t\t...(fence.lang === undefined ? {} : { lang: fence.lang }),\n\t\t\t\tcode: body.join('\\n'),\n\t\t\t})\n\t\t\tcontinue\n\t\t}\n\t\tif (isThematicBreak(line)) {\n\t\t\tblocks.push({ element: 'thematicBreak' })\n\t\t\tindex += 1\n\t\t\tcontinue\n\t\t}\n\t\tconst heading = extractHeading(line)\n\t\tif (heading) {\n\t\t\tblocks.push({\n\t\t\t\telement: 'heading',\n\t\t\t\tlevel: heading.level,\n\t\t\t\tchildren: parseInline(heading.text),\n\t\t\t})\n\t\t\tindex += 1\n\t\t\tcontinue\n\t\t}\n\t\tif (isQuote(line)) {\n\t\t\tconst quoted: string[] = []\n\t\t\twhile (index < lines.length && isQuote(lines[index] ?? '')) {\n\t\t\t\tquoted.push(stripQuote(lines[index] ?? ''))\n\t\t\t\tindex += 1\n\t\t\t}\n\t\t\tblocks.push({ element: 'blockquote', children: parseBlocks(quoted, depth + 1) })\n\t\t\tcontinue\n\t\t}\n\t\tif (isTableStart(line, lines[index + 1])) {\n\t\t\tconst table = collectTable(lines, index)\n\t\t\tblocks.push(table.node)\n\t\t\tindex = table.next\n\t\t\tcontinue\n\t\t}\n\t\tif (extractListItem(line)) {\n\t\t\tconst list = collectList(lines, index, depth)\n\t\t\tblocks.push(list.node)\n\t\t\tindex = list.next\n\t\t\tcontinue\n\t\t}\n\t\tconst paragraph: string[] = []\n\t\twhile (\n\t\t\tindex < lines.length &&\n\t\t\t!isBlankLine(lines[index] ?? '') &&\n\t\t\t!(isNonEmptyArray(paragraph) && startsBlock(lines, index))\n\t\t) {\n\t\t\tparagraph.push((lines[index] ?? '').trim())\n\t\t\tindex += 1\n\t\t}\n\t\tblocks.push({ element: 'paragraph', children: parseInline(paragraph.join('\\n')) })\n\t}\n\treturn blocks\n}\n\n/**\n * Collects a GFM table starting at a header row, parsing the header, the\n * alignment row, and every contiguous body row that follows.\n *\n * @param lines - The markdown lines to scan.\n * @param start - The index of the header row.\n * @returns The parsed table node and the index of the first line after it.\n *\n * @example\n * ```ts\n * collectTable(['| a |', '| - |'], 0) // { node: { element: 'table', ... }, next: 2 }\n * ```\n */\nexport function collectTable(\n\tlines: readonly string[],\n\tstart: number,\n): { readonly node: TableNode; readonly next: number } {\n\tconst headerCells = splitTableRow(lines[start] ?? '')\n\tconst columns = headerCells.length\n\tconst header = headerCells.map((cell) => parseInline(cell.trim()))\n\tconst align = tableAlignments(lines[start + 1] ?? '')\n\tconst padded: TableAlign[] = []\n\tfor (let column = 0; column < columns; column += 1) padded.push(align[column] ?? 'none')\n\tconst rows: (readonly InlineNode[])[][] = []\n\tlet index = start + 2\n\twhile (\n\t\tindex < lines.length &&\n\t\t!isBlankLine(lines[index] ?? '') &&\n\t\t(lines[index] ?? '').includes('|')\n\t) {\n\t\tconst cells = splitTableRow(lines[index] ?? '')\n\t\tconst row: (readonly InlineNode[])[] = []\n\t\tfor (let column = 0; column < columns; column += 1)\n\t\t\trow.push(parseInline((cells[column] ?? '').trim()))\n\t\trows.push(row)\n\t\tindex += 1\n\t}\n\treturn { node: { element: 'table', header, rows, align: padded }, next: index }\n}\n\n/**\n * Collects a list starting at the first item, gathering sibling items at the\n * same indent/ordering and recursing into each item's own block content.\n *\n * @param lines - The markdown lines to scan.\n * @param start - The index of the first list item.\n * @param depth - The current recursion depth (each item recurses at `depth + 1`).\n * @returns The parsed list node and the index of the first line after it.\n *\n * @example\n * ```ts\n * collectList(['- item'], 0, 0) // { node: { element: 'list', ... }, next: 1 }\n * ```\n */\nexport function collectList(\n\tlines: readonly string[],\n\tstart: number,\n\tdepth: number,\n): { readonly node: ListNode; readonly next: number } {\n\tconst first = extractListItem(lines[start] ?? '')\n\tconst ordered = first?.ordered ?? false\n\tconst startOrdinal = first?.start ?? 1\n\tconst topIndent = first?.indent ?? 0\n\tconst items: ListItemNode[] = []\n\tlet index = start\n\twhile (index < lines.length) {\n\t\tconst parsed = extractListItem(lines[index] ?? '')\n\t\t// A sibling item shares the list's (top) indent + ordering; anything else stops\n\t\t// the top loop (a deeper item is a nested list, gathered as continuation below).\n\t\tif (!parsed || parsed.indent > topIndent || parsed.ordered !== ordered) break\n\t\tconst itemLines: string[] = [parsed.content]\n\t\tconst continuation = parsed.marker\n\t\tindex += 1\n\t\twhile (index < lines.length) {\n\t\t\tconst next = lines[index] ?? ''\n\t\t\tif (isBlankLine(next)) {\n\t\t\t\tconst after = lines[index + 1] ?? ''\n\t\t\t\tif (\n\t\t\t\t\tindex + 1 < lines.length &&\n\t\t\t\t\t!isBlankLine(after) &&\n\t\t\t\t\tleadingIndent(after) >= continuation\n\t\t\t\t) {\n\t\t\t\t\titemLines.push('')\n\t\t\t\t\tindex += 1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tif (leadingIndent(next) >= continuation) {\n\t\t\t\titemLines.push(next.slice(continuation))\n\t\t\t\tindex += 1\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (extractListItem(next) || startsBlock(lines, index)) break\n\t\t\titemLines.push(next.trim()) // a lazy paragraph-continuation line\n\t\t\tindex += 1\n\t\t}\n\t\titems.push({ element: 'listItem', children: parseBlocks(itemLines, depth + 1) })\n\t}\n\treturn { node: { element: 'list', ordered, start: startOrdinal, items }, next: index }\n}\n\n/**\n * Parses a markdown string into a typed {@link MarkdownDocument} AST via the\n * block phase.\n *\n * @param markdown - The markdown source to parse.\n * @returns The parsed document.\n */\nexport function parseDocument(markdown: string): MarkdownDocument {\n\treturn { element: 'document', children: parseBlocks(splitLines(markdown), 0) }\n}\n\n/**\n * Parses inline markdown text (emphasis, code spans, links) into inline AST\n * nodes, coalescing adjacent text runs.\n *\n * @param text - The inline markdown text to parse.\n * @returns The parsed inline nodes.\n */\nexport function parseInline(text: string): readonly InlineNode[] {\n\treturn coalesceText(scanInline(text, 0, text.length))\n}\n","import {\n\tbooleanShape,\n\tintegerShape,\n\tliteralShape,\n\tobjectShape,\n\toptionalShape,\n\tstringShape,\n} from '@orkestrel/contract'\n\n// AGENTS section 14 / 4.6.1: shapers are `ContractShape` VALUES, not functions\n// or types - a JSON-Schema blueprint the compilers (factories.ts) turn into a\n// guard / parser / schema / generator in lockstep. Only the NON-recursive\n// parts of the markdown AST (types.ts) can be expressed here: a shape tree has\n// no lazy/self-referential node, so any type whose fields recurse into\n// `BlockNode` / `InlineNode` / `MarkdownNode` (EmphasisNode, LinkNode,\n// HeadingNode, ParagraphNode, ListItemNode, ListNode, TableNode,\n// BlockquoteNode, MarkdownDocument) is skipped here and stays guard-only\n// (validators.ts) via `lazyOf`.\n\n/**\n * The shape of a {@link TextNode} - a plain-text leaf inline run.\n *\n * @example\n * ```ts\n * import { createContract } from '@orkestrel/contract'\n * import { textShape } from '@src/core'\n *\n * const text = createContract(textShape)\n * text.is({ element: 'text', value: 'hi' }) // true\n * ```\n */\nexport const textShape = objectShape({\n\telement: literalShape(['text']),\n\tvalue: stringShape(),\n})\n\n/**\n * The shape of a {@link CodeSpanNode} - an inline code span (`` `code` ``).\n *\n * @example\n * ```ts\n * import { createContract } from '@orkestrel/contract'\n * import { codeSpanShape } from '@src/core'\n *\n * const codeSpan = createContract(codeSpanShape)\n * codeSpan.is({ element: 'codeSpan', value: 'const x = 1' }) // true\n * ```\n */\nexport const codeSpanShape = objectShape({\n\telement: literalShape(['codeSpan']),\n\tvalue: stringShape(),\n})\n\n/**\n * The shape of a {@link CodeBlockNode} - a fenced code block. `lang` is\n * optional (absent when the opening fence carries no info-string).\n *\n * @example\n * ```ts\n * import { createContract } from '@orkestrel/contract'\n * import { codeBlockShape } from '@src/core'\n *\n * const codeBlock = createContract(codeBlockShape)\n * codeBlock.is({ element: 'codeBlock', code: 'x' }) // true\n * codeBlock.is({ element: 'codeBlock', code: 'x', lang: 'ts' }) // true\n * ```\n */\nexport const codeBlockShape = objectShape({\n\telement: literalShape(['codeBlock']),\n\tlang: optionalShape(stringShape()),\n\tcode: stringShape(),\n})\n\n/**\n * The shape of a {@link ThematicBreakNode} - a horizontal rule. Carries no\n * fields beyond its `element` discriminant.\n *\n * @example\n * ```ts\n * import { createContract } from '@orkestrel/contract'\n * import { thematicBreakShape } from '@src/core'\n *\n * const thematicBreak = createContract(thematicBreakShape)\n * thematicBreak.is({ element: 'thematicBreak' }) // true\n * ```\n */\nexport const thematicBreakShape = objectShape({\n\telement: literalShape(['thematicBreak']),\n})\n\n/**\n * The shape of a {@link TableAlign} - the per-column GFM table alignment\n * literal.\n *\n * @example\n * ```ts\n * import { createContract } from '@orkestrel/contract'\n * import { tableAlignShape } from '@src/core'\n *\n * const tableAlign = createContract(tableAlignShape)\n * tableAlign.is('left') // true\n * tableAlign.is('center') // true\n * tableAlign.is('top') // false\n * ```\n */\nexport const tableAlignShape = literalShape(['none', 'left', 'right', 'center'])\n\n/**\n * The shape of {@link ListItemParts} - the parsed parts of a single list-item\n * line the block phase's list detector returns. Fully non-recursive (no\n * nested node fields), so every field shapes directly.\n *\n * @example\n * ```ts\n * import { createContract } from '@orkestrel/contract'\n * import { listItemPartsShape } from '@src/core'\n *\n * const listItemParts = createContract(listItemPartsShape)\n * listItemParts.is({ ordered: false, start: 1, content: 'hi', indent: 0, marker: 2 }) // true\n * ```\n */\nexport const listItemPartsShape = objectShape({\n\tordered: booleanShape(),\n\tstart: integerShape(),\n\tcontent: stringShape(),\n\tindent: integerShape(),\n\tmarker: integerShape(),\n})\n","import type {\n\tBlockNode,\n\tMarkdownDocument,\n\tMarkdownHandlers,\n\tMarkdownInterface,\n\tMarkdownNode,\n\tMarkdownRewriteHandler,\n} from './types.js'\nimport { foldNode, rewriteDocument, walkNodes } from './helpers.js'\nimport { parseDocument } from './parsers.js'\n\n/**\n * A stateful, parsed markdown document - wraps a typed {@link MarkdownDocument} AST\n * with the query (`find` / `filter` / `reduce` / iteration), rewrite (`map`), fold, and\n * streaming operations {@link MarkdownInterface} declares.\n *\n * @remarks\n * - **Construction.** Given a `string`, the constructor runs {@link parseDocument} (the\n * block phase then the inline phase) to build the AST. Given a {@link MarkdownDocument},\n * the document is adopted AS-IS and is NOT re-validated - a caller adopting an\n * untrusted value should gate it with `isMarkdownDocument` first.\n * - **Immutable.** {@link map} never mutates the stored AST - it returns a NEW `Markdown`\n * instance; the document root invariant (`element: 'document'`) always holds.\n * - **Traversal order.** {@link walk} and the `find` / `filter` / `reduce` queries built\n * on it walk the AST depth-first, pre-order, root-inclusive (via {@link walkNodes});\n * `stream` is shallow - only the document's direct block children.\n *\n * @example\n * ```ts\n * import { Markdown, isHeadingNode, renderMarkdown } from '@src/core'\n *\n * const markdown = new Markdown('# Title\\n\\nA **bold** [link](https://x.dev).')\n * const heading = markdown.find(isHeadingNode) // the HeadingNode, or undefined\n * const shouted = markdown.map((node) =>\n * node.element === 'text' ? { element: 'text', value: node.value.toUpperCase() } : node,\n * )\n * renderMarkdown(shouted.document) // '# TITLE\\n\\nA **BOLD** [LINK](https://x.dev).'\n * ```\n */\nexport class Markdown implements MarkdownInterface {\n\treadonly #document: MarkdownDocument\n\n\tconstructor(input: string | MarkdownDocument) {\n\t\tthis.#document = typeof input === 'string' ? parseDocument(input) : input\n\t}\n\n\t/** The stored {@link MarkdownDocument} AST root. */\n\tget document(): MarkdownDocument {\n\t\treturn this.#document\n\t}\n\n\t/**\n\t * THE deep traversal - a lazy, depth-first, pre-order, root-inclusive generator\n\t * over every {@link MarkdownNode} in the document. `find` / `filter` / `reduce`\n\t * all iterate this single traversal.\n\t *\n\t * @example\n\t * ```ts\n\t * for (const node of markdown.walk()) {\n\t * // every node, depth-first, pre-order, root-inclusive\n\t * }\n\t *\n\t * // also consumable by for-await - JS accepts a sync iterable in for-await\n\t * for await (const node of markdown.walk()) {\n\t * // same sequence, no separate async iterator needed\n\t * }\n\t * ```\n\t */\n\t*walk(): Generator<MarkdownNode> {\n\t\tyield* walkNodes(this.#document)\n\t}\n\n\t// Finds the first node (depth-first, pre-order) narrowed by a type guard.\n\tfind<T extends MarkdownNode>(guard: (node: MarkdownNode) => node is T): T | undefined\n\t// Finds the first node (depth-first, pre-order) matching a predicate.\n\tfind(predicate: (node: MarkdownNode) => boolean): MarkdownNode | undefined\n\tfind(predicate: (node: MarkdownNode) => boolean): MarkdownNode | undefined {\n\t\tfor (const node of this.walk()) if (predicate(node)) return node\n\t\treturn undefined\n\t}\n\n\t// Collects every node (depth-first, pre-order) narrowed by a type guard.\n\tfilter<T extends MarkdownNode>(guard: (node: MarkdownNode) => node is T): readonly T[]\n\t// Collects every node (depth-first, pre-order) matching a predicate.\n\tfilter(predicate: (node: MarkdownNode) => boolean): readonly MarkdownNode[]\n\tfilter(predicate: (node: MarkdownNode) => boolean): readonly MarkdownNode[] {\n\t\tconst out: MarkdownNode[] = []\n\t\tfor (const node of this.walk()) if (predicate(node)) out.push(node)\n\t\treturn out\n\t}\n\n\t/** Rewrites the AST bottom-up (copy-on-write) and returns a new {@link Markdown}. */\n\tmap(rewrite: MarkdownRewriteHandler): MarkdownInterface {\n\t\treturn new Markdown(rewriteDocument(this.#document, rewrite))\n\t}\n\n\t/** Folds the AST depth-first, pre-order into an accumulator. */\n\treduce<T>(callback: (accumulator: T, node: MarkdownNode) => T, initial: T): T {\n\t\tlet accumulator = initial\n\t\tfor (const node of this.walk()) accumulator = callback(accumulator, node)\n\t\treturn accumulator\n\t}\n\n\t/** Runs a total catamorphism over the document using a {@link MarkdownHandlers} table. */\n\tfold<T>(handlers: MarkdownHandlers<T>): T {\n\t\treturn foldNode(this.#document, handlers, 0)\n\t}\n\n\t/**\n\t * A web-standard {@link ReadableStream} over the document's top-level block nodes\n\t * (shallow, source order) - a fresh, pull-based source per call: one block is\n\t * enqueued per `pull`, so a slow reader's backpressure is respected. Cancellable,\n\t * async-iterable wherever the platform supports it (Node, Deno), and pipeable\n\t * through any {@link TransformStream} / {@link WritableStream}.\n\t *\n\t * @example\n\t * ```ts\n\t * // universal - works in every ReadableStream-supporting environment\n\t * const reader = markdown.stream().getReader()\n\t * for (let result = await reader.read(); !result.done; result = await reader.read()) {\n\t * console.log(result.value) // one BlockNode\n\t * }\n\t *\n\t * // Node / Deno / Firefox support async iteration of ReadableStream natively;\n\t * // other environments should use the reader loop above instead.\n\t * for await (const block of markdown.stream()) {\n\t * console.log(block)\n\t * }\n\t * ```\n\t */\n\tstream(): ReadableStream<BlockNode> {\n\t\tconst blocks = this.#document.children\n\t\tlet index = 0\n\t\treturn new ReadableStream<BlockNode>({\n\t\t\tpull(controller) {\n\t\t\t\tif (index < blocks.length) {\n\t\t\t\t\tcontroller.enqueue(blocks[index])\n\t\t\t\t\tindex += 1\n\t\t\t\t} else {\n\t\t\t\t\tcontroller.close()\n\t\t\t\t}\n\t\t\t},\n\t\t})\n\t}\n}\n","import type { ContractInterface } from '@orkestrel/contract'\nimport type {\n\tCodeBlockNode,\n\tCodeSpanNode,\n\tMarkdownDocument,\n\tMarkdownInterface,\n\tTextNode,\n\tThematicBreakNode,\n} from './types.js'\nimport { createContract } from '@orkestrel/contract'\nimport { Markdown } from './Markdown.js'\nimport { codeBlockShape, codeSpanShape, textShape, thematicBreakShape } from './shapers.js'\n\n/**\n * Create a stateful markdown handle from a markdown string or an already-parsed\n * {@link MarkdownDocument} - a typed AST plus the query, rewrite, and fold operations\n * {@link MarkdownInterface} exposes.\n *\n * @remarks\n * Given a `string`, runs a block phase (headings / paragraphs / lists / GFM tables /\n * fenced code / blockquotes / thematic breaks) then an inline phase (emphasis /\n * inline code / links) to build a render-agnostic {@link MarkdownDocument}. Given a\n * {@link MarkdownDocument}, adopts it AS-IS without re-validation - gate an untrusted\n * value with `isMarkdownDocument` first. Pure + total parse (malformed markdown\n * degrades to text, never throws) and zero-dependency - a hand-written scanner, no\n * regex-only structural parse, linear-time (no ReDoS).\n *\n * @param input - A markdown string to parse, or an already-parsed {@link MarkdownDocument}\n * @returns A working {@link MarkdownInterface}\n *\n * @example\n * ```ts\n * import { createMarkdown } from '@src/core'\n *\n * const markdown = createMarkdown('# Hi\\n\\nRead the [guide](./guide.md).')\n * markdown.document.children[0] // { element: 'heading', ... }\n * ```\n */\nexport function createMarkdown(input: string | MarkdownDocument): MarkdownInterface {\n\treturn new Markdown(input)\n}\n\n/**\n * Compile the {@link textShape} into a {@link ContractInterface} for\n * {@link TextNode} - a guard, coercing parser, JSON Schema, and seeded\n * generator from one shape declaration (AGENTS §14).\n *\n * @returns A `TextNode` contract bundling `schema` / `is` / `parse` / `generate`\n *\n * @example\n * ```ts\n * import { createTextContract } from '@src/core'\n *\n * const text = createTextContract()\n * text.is({ element: 'text', value: 'hi' }) // true\n * ```\n */\nexport function createTextContract(): ContractInterface<TextNode> {\n\treturn createContract(textShape)\n}\n\n/**\n * Compile the {@link codeSpanShape} into a {@link ContractInterface} for\n * {@link CodeSpanNode} - a guard, coercing parser, JSON Schema, and seeded\n * generator from one shape declaration (AGENTS §14).\n *\n * @returns A `CodeSpanNode` contract bundling `schema` / `is` / `parse` / `generate`\n *\n * @example\n * ```ts\n * import { createCodeSpanContract } from '@src/core'\n *\n * const codeSpan = createCodeSpanContract()\n * codeSpan.is({ element: 'codeSpan', value: 'const x = 1' }) // true\n * ```\n */\nexport function createCodeSpanContract(): ContractInterface<CodeSpanNode> {\n\treturn createContract(codeSpanShape)\n}\n\n/**\n * Compile the {@link codeBlockShape} into a {@link ContractInterface} for\n * {@link CodeBlockNode} - a guard, coercing parser, JSON Schema, and seeded\n * generator from one shape declaration (AGENTS §14).\n *\n * @returns A `CodeBlockNode` contract bundling `schema` / `is` / `parse` / `generate`\n *\n * @example\n * ```ts\n * import { createCodeBlockContract } from '@src/core'\n *\n * const codeBlock = createCodeBlockContract()\n * codeBlock.is({ element: 'codeBlock', code: 'x' }) // true\n * ```\n */\nexport function createCodeBlockContract(): ContractInterface<CodeBlockNode> {\n\treturn createContract(codeBlockShape)\n}\n\n/**\n * Compile the {@link thematicBreakShape} into a {@link ContractInterface} for\n * {@link ThematicBreakNode} - a guard, coercing parser, JSON Schema, and\n * seeded generator from one shape declaration (AGENTS §14).\n *\n * @returns A `ThematicBreakNode` contract bundling `schema` / `is` / `parse` / `generate`\n *\n * @example\n * ```ts\n * import { createThematicBreakContract } from '@src/core'\n *\n * const thematicBreak = createThematicBreakContract()\n * thematicBreak.is({ element: 'thematicBreak' }) // true\n * ```\n */\nexport function createThematicBreakContract(): ContractInterface<ThematicBreakNode> {\n\treturn createContract(thematicBreakShape)\n}\n"],"mappings":";;;;;;;;;AAMA,IAAa,mCAAwC,IAAI,IAAI;CAAC;CAAQ;CAAS;CAAU;AAAK,CAAC;;;;;;;;;;AAW/F,IAAa,YAAY;;;;;;;;;;;;;;;;ACiCzB,SAAgB,aAAa,WAA4B;CACxD,OAAO,cAAc,OAAO,cAAc,OAAQ,cAAc;AACjE;;;;;;;;;;;;;;AAeA,SAAgB,YAAY,WAA4B;CACvD,OAAO,0BAA0B,KAAK,SAAS;AAChD;;;;;;;;;;;;;;AAeA,SAAgB,YAAY,MAAuB;CAClD,QAAA,GAAA,oBAAA,cAAA,CAAqB,KAAK,KAAK,CAAC;AACjC;;;;;;;;;;;;;AAcA,SAAgB,QAAQ,MAAuB;CAC9C,OAAO,YAAY,KAAK,IAAI;AAC7B;;;;;;;;;;;;;;AAeA,SAAgB,aAAa,MAAc,QAAyB;CACnE,MAAM,YAAY,OAAO,OAAO,MAAM,MAAM;CAC5C,IAAI,QAAQ;CACZ,OAAO,QAAQ,KAAK,UAAU,kBAAkB,KAAK,MAAM,GAAG;CAC9D,IAAI,MAAM;CACV,OAAO,QAAQ,KAAK,UAAU,KAAK,WAAW,WAAW;EACxD;EACA;CACD;CACA,IAAI,MAAM,OAAO,QAAQ,OAAO;CAChC,OAAO,QAAQ,KAAK,UAAU,kB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,KAAK,YAAY;GAChB,IAAI,QAAQ,OAAO,QAAQ;IAC1B,WAAW,QAAQ,OAAO,MAAM;IAChC,SAAS;GACV,OACC,WAAW,MAAM;EAEnB,EACD,CAAC;CACF;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC1GA,SAAgB,eAAe,OAAqD;CACnF,OAAO,IAAI,SAAS,KAAK;AAC1B;;;;;;;;;;;;;;;;AAiBA,SAAgB,qBAAkD;CACjE,QAAA,GAAA,oBAAA,eAAA,CAAsB,SAAS;AAChC;;;;;;;;;;;;;;;;AAiBA,SAAgB,yBAA0D;CACzE,QAAA,GAAA,oBAAA,eAAA,CAAsB,aAAa;AACpC;;;;;;;;;;;;;;;;AAiBA,SAAgB,0BAA4D;CAC3E,QAAA,GAAA,oBAAA,eAAA,CAAsB,cAAc;AACrC;;;;;;;;;;;;;;;;AAiBA,SAAgB,8BAAoE;CACnF,QAAA,GAAA,oBAAA,eAAA,CAAsB,kBAAkB;AACzC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["#document"],"sources":["../../../src/core/constants.ts","../../../src/core/validators.ts","../../../src/core/helpers.ts","../../../src/core/parsers.ts","../../../src/core/shapers.ts","../../../src/core/Markdown.ts","../../../src/core/factories.ts"],"sourcesContent":["/**\n * The URL schemes `renderHTML` permits on a link `href` - anything else (notably\n * `javascript:`, `data:`, `vbscript:`, `file:`) is dropped to an empty `href` so a\n * hostile link can never execute. Frozen, lower-case; a relative / anchor /\n * scheme-less `href` (no `scheme:` prefix) is always allowed.\n */\nexport const SAFE_URL_SCHEMES: ReadonlySet<string> = new Set(['http', 'https', 'mailto', 'tel'])\n\n/**\n * The maximum recursion depth the parse pipeline (`parseDocument` and its\n * `parsers.ts` helpers) and the `helpers.ts` traversal / render functions\n * (`renderHTML`, `renderMarkdown`, `walkNodes`, `foldNode`) honor before degrading to\n * literal text - bounds blockquote nesting, inline nesting (emphasis / links), and\n * traversal/render recursion so pathological or hostile input (deeply nested\n * blockquotes, runaway emphasis) cannot exhaust the call stack. Past this depth the\n * parser treats the remaining content as literal text instead of recursing further.\n */\nexport const MAX_DEPTH = 64\n","import type { Guard } from '@orkestrel/contract'\nimport type {\n\tBlockNode,\n\tBlockquoteNode,\n\tCodeBlockNode,\n\tCodeSpanNode,\n\tEmphasisNode,\n\tHeadingNode,\n\tInlineNode,\n\tLinkNode,\n\tListNode,\n\tMarkdownDocument,\n\tMarkdownNode,\n\tParagraphNode,\n\tTableNode,\n\tTextNode,\n\tThematicBreakNode,\n} from './types.js'\nimport {\n\tarrayOf,\n\tisBoolean,\n\tisEmptyString,\n\tisNumber,\n\tisString,\n\tliteralOf,\n\tlazyOf,\n\trecordOf,\n\tunionOf,\n} from '@orkestrel/contract'\nimport { splitTableRow } from './helpers.js'\n\n// AGENTS section 14: guards are total. This file owns two predicate families:\n// line / string structural predicates that test raw strings during parsing\n// (isWhitespace, isEscapable, isQuote, isFenceClose, isThematicBreak,\n// isTableStart), and node guards that narrow a MarkdownNode to one parsed\n// block / inline variant by its element tag.\n\n/**\n * Whether `character` is an inline whitespace character (space / tab / newline) - the\n * emphasis flanking rule's space test.\n *\n * @param character - The character to test\n * @returns `true` when it is inline whitespace\n *\n * @example\n * ```ts\n * isWhitespace(' ') // true\n * isWhitespace('a') // false\n * ```\n */\nexport function isWhitespace(character: string): boolean {\n\treturn character === ' ' || character === '\\t' || character === '\\n'\n}\n\n/**\n * Whether `character` is escapable by a leading backslash - the ASCII punctuation\n * markdown gives meaning to (so `\\*` becomes `*` but `\\.` stays `\\.`).\n *\n * @param character - The single character after a backslash\n * @returns `true` when a backslash before it is an escape\n *\n * @example\n * ```ts\n * isEscapable('*') // true\n * isEscapable('a') // false\n * ```\n */\nexport function isEscapable(character: string): boolean {\n\treturn /[\\\\`*_{}[\\]()#+\\-.!>~|]/.test(character)\n}\n\n/**\n * Whether `line` is blank - empty, or containing only whitespace - the markdown\n * definition of a blank line that block parsing uses to separate paragraphs, skip\n * gaps, and end list continuations.\n *\n * @param line - The candidate line\n * @returns `true` when the line is blank\n *\n * @example\n * ```ts\n * isBlankLine(' ') // true\n * ```\n */\nexport function isBlankLine(line: string): boolean {\n\treturn isEmptyString(line.trim())\n}\n\n/**\n * Whether `line` is a blockquote line (`>` optionally indented up to three spaces) -\n * its content is de-quoted by {@link stripQuote}.\n *\n * @param line - The candidate line\n * @returns `true` when the line begins a blockquote\n *\n * @example\n * ```ts\n * isQuote('> quoted') // true\n * ```\n */\nexport function isQuote(line: string): boolean {\n\treturn /^\\s{0,3}>/.test(line)\n}\n\n/**\n * Whether `line` closes a fence opened by `marker` - the same fence character, a run\n * at least as long, and nothing else but surrounding whitespace.\n *\n * @param line - The candidate closing line\n * @param marker - The opening fence's marker run (from {@link extractFence})\n * @returns `true` when `line` closes the fence\n *\n * @example\n * ```ts\n * isFenceClose('```', '```') // true\n * ```\n */\nexport function isFenceClose(line: string, marker: string): boolean {\n\tconst character = marker[0] === '~' ? '~' : '`'\n\tlet index = 0\n\twhile (index < line.length && isFenceWhitespace(line[index])) index++\n\tlet run = 0\n\twhile (index < line.length && line[index] === character) {\n\t\trun++\n\t\tindex++\n\t}\n\tif (run < marker.length) return false\n\twhile (index < line.length && isFenceWhitespace(line[index])) index++\n\treturn index === line.length\n}\n\n/**\n * Whether `character` is a regex-`\\s`-equivalent whitespace character - the\n * character class {@link isFenceClose}'s scan treats as surrounding padding.\n *\n * @param character - The single character to test, or `undefined` past the end of a line\n * @returns `true` when it is whitespace\n *\n * @example\n * ```ts\n * isFenceWhitespace(' ') // true\n * isFenceWhitespace(undefined) // false\n * ```\n */\nexport function isFenceWhitespace(character: string | undefined): boolean {\n\treturn (\n\t\tcharacter === ' ' ||\n\t\tcharacter === '\\t' ||\n\t\tcharacter === '\\n' ||\n\t\tcharacter === '\\r' ||\n\t\tcharacter === '\\f' ||\n\t\tcharacter === '\\v'\n\t)\n}\n\n/**\n * Whether `line` is a thematic break (horizontal rule) - three or more of the SAME\n * marker `-`, `*`, or `_` (optionally space-separated) and nothing else (`---`,\n * `***`, `___`, `- - -`).\n *\n * @param line - The candidate line\n * @returns `true` when the line is a thematic break\n *\n * @example\n * ```ts\n * isThematicBreak('---') // true\n * ```\n */\nexport function isThematicBreak(line: string): boolean {\n\tconst stripped = line.trim().replace(/\\s+/g, '')\n\tif (stripped.length < 3) return false\n\tconst marker = stripped[0]\n\tif (marker !== '-' && marker !== '*' && marker !== '_') return false\n\treturn [...stripped].every((character) => character === marker)\n}\n\n/**\n * Whether the pair (`header`, `delimiter`) opens a GFM table - `delimiter` is a row of\n * `|`-separated cells each matching `:?-+:?`, the GFM rule that a table requires a\n * header row IMMEDIATELY followed by a delimiter row.\n *\n * @param header - The candidate header line\n * @param delimiter - The line after it (the candidate delimiter)\n * @returns `true` when the two lines open a table\n *\n * @example\n * ```ts\n * isTableStart('| a |', '| - |') // true\n * ```\n */\nexport function isTableStart(header: string, delimiter: string | undefined): boolean {\n\tif (delimiter === undefined || !header.includes('|')) return false\n\tconst cells = splitTableRow(delimiter)\n\tif (cells.length === 0) return false\n\treturn cells.every((cell) => /^:?-+:?$/.test(cell.trim()))\n}\n\n// === Block guards\n\n/** Determine whether a node is a heading block. */\nexport function isHeadingNode(node: MarkdownNode): node is HeadingNode {\n\treturn node.element === 'heading'\n}\n\n/**\n * Determine whether a node is a paragraph block.\n *\n * @example\n * ```ts\n * isParagraphNode({ element: 'paragraph', children: [] }) // true\n * ```\n */\nexport function isParagraphNode(node: MarkdownNode): node is ParagraphNode {\n\treturn node.element === 'paragraph'\n}\n\n/**\n * Determine whether a node is a list block.\n *\n * @example\n * ```ts\n * isListNode({ element: 'list', ordered: false, start: 1, items: [] }) // true\n * ```\n */\nexport function isListNode(node: MarkdownNode): node is ListNode {\n\treturn node.element === 'list'\n}\n\n/** Determine whether a node is a GFM table block. */\nexport function isTableNode(node: MarkdownNode): node is TableNode {\n\treturn node.element === 'table'\n}\n\n/**\n * Determine whether a node is a fenced code block.\n *\n * @example\n * ```ts\n * isCodeBlockNode({ element: 'codeBlock', code: 'x' }) // true\n * ```\n */\nexport function isCodeBlockNode(node: MarkdownNode): node is CodeBlockNode {\n\treturn node.element === 'codeBlock'\n}\n\n/**\n * Determine whether a node is a blockquote block.\n *\n * @example\n * ```ts\n * isBlockquoteNode({ element: 'blockquote', children: [] }) // true\n * ```\n */\nexport function isBlockquoteNode(node: MarkdownNode): node is BlockquoteNode {\n\treturn node.element === 'blockquote'\n}\n\n/**\n * Determine whether a node is a thematic break (horizontal rule) block.\n *\n * @example\n * ```ts\n * isThematicBreakNode({ element: 'thematicBreak' }) // true\n * ```\n */\nexport function isThematicBreakNode(node: MarkdownNode): node is ThematicBreakNode {\n\treturn node.element === 'thematicBreak'\n}\n\n// === Inline guards\n\n/**\n * Determine whether a node is a plain text run.\n *\n * @example\n * ```ts\n * isTextNode({ element: 'text', value: 'hi' }) // true\n * ```\n */\nexport function isTextNode(node: MarkdownNode): node is TextNode {\n\treturn node.element === 'text'\n}\n\n/**\n * Determine whether a node is an emphasis run (`*em*` / `**strong**`).\n *\n * @example\n * ```ts\n * isEmphasisNode({ element: 'emphasis', strong: false, children: [] }) // true\n * ```\n */\nexport function isEmphasisNode(node: MarkdownNode): node is EmphasisNode {\n\treturn node.element === 'emphasis'\n}\n\n/**\n * Determine whether a node is an inline code span.\n *\n * @remarks\n * Narrows to {@link CodeSpanNode} - the node whose `element` discriminant is\n * `'codeSpan'`.\n *\n * @example\n * ```ts\n * isCodeSpanNode({ element: 'codeSpan', value: 'x' }) // true\n * ```\n */\nexport function isCodeSpanNode(node: MarkdownNode): node is CodeSpanNode {\n\treturn node.element === 'codeSpan'\n}\n\n/** Determine whether a node is a link. */\nexport function isLinkNode(node: MarkdownNode): node is LinkNode {\n\treturn node.element === 'link'\n}\n\n// === From-unknown AST guards\n//\n// The node guards above narrow an ALREADY-PARSED MarkdownNode by its `element`\n// tag. The guards below instead validate an arbitrary `unknown` value (untrusted\n// input - a deserialized AST, a value crossing a process/RPC boundary) against\n// the full node shape, field by field, composed from @orkestrel/contract\n// combinators. Each guard IS its own hoisted composed value (compiled once at\n// module init, not per call); inline<->block recursion (emphasis/link children,\n// list items, blockquote children) resolves through `lazyOf`, closing over the\n// exported guard names themselves - legal because `lazyOf`'s thunk resolves per\n// call, strictly after module init has assigned every export. @orkestrel/contract\n// guarantees guard totality (AGENTS §14): `lazyOf`, `unionOf`, `recordOf`, and\n// every built-in guard are throw-contained, so a hostile getter, a structural\n// cycle, or pathologically deep input returns `false` rather than throwing -\n// no additional `attempt` wrapping is needed here.\n\n/**\n * Determine whether an arbitrary value is a valid {@link InlineNode} - a text\n * run, emphasis, code span, or link, recursively validated.\n *\n * @remarks\n * Total: never throws, even on cyclic or pathologically deep input - every\n * combinator involved (`unionOf`, `recordOf`, `arrayOf`, `lazyOf`) is\n * throw-contained per the `@orkestrel/contract` guard contract (AGENTS §14).\n *\n * @param value - The value to test\n * @returns `true` when `value` is a well-formed {@link InlineNode}\n *\n * @example\n * ```ts\n * import { isInlineNode } from '@orkestrel/markdown'\n *\n * isInlineNode({ element: 'text', value: 'hi' }) // true\n * isInlineNode({ element: 'text' }) // false - missing `value`\n * ```\n */\nexport const isInlineNode: Guard<InlineNode> = unionOf(\n\trecordOf({ element: literalOf('text'), value: isString }),\n\trecordOf({\n\t\telement: literalOf('emphasis'),\n\t\tstrong: isBoolean,\n\t\tchildren: arrayOf(lazyOf(() => isInlineNode)),\n\t}),\n\trecordOf({ element: literalOf('codeSpan'), value: isString }),\n\trecordOf({\n\t\telement: literalOf('link'),\n\t\thref: isString,\n\t\tchildren: arrayOf(lazyOf(() => isInlineNode)),\n\t}),\n)\n\n/**\n * Determine whether an arbitrary value is a valid {@link BlockNode} - a\n * heading, paragraph, list, table, code block, blockquote, or thematic break,\n * recursively validated.\n *\n * @remarks\n * Total: never throws, even on cyclic or pathologically deep input - every\n * combinator involved (`unionOf`, `recordOf`, `arrayOf`, `lazyOf`) is\n * throw-contained per the `@orkestrel/contract` guard contract (AGENTS §14).\n * A list item's shape is inlined here (and in {@link isMarkdownNode}) rather\n * than named separately - it is used at exactly these two sites.\n *\n * @param value - The value to test\n * @returns `true` when `value` is a well-formed {@link BlockNode}\n *\n * @example\n * ```ts\n * import { isBlockNode } from '@orkestrel/markdown'\n *\n * isBlockNode({ element: 'thematicBreak' }) // true\n * isBlockNode({ element: 'heading' }) // false - missing `level` / `children`\n * ```\n */\nexport const isBlockNode: Guard<BlockNode> = unionOf(\n\trecordOf({ element: literalOf('heading'), level: isNumber, children: arrayOf(isInlineNode) }),\n\trecordOf({ element: literalOf('paragraph'), children: arrayOf(isInlineNode) }),\n\trecordOf({\n\t\telement: literalOf('list'),\n\t\tordered: isBoolean,\n\t\tstart: isNumber,\n\t\titems: arrayOf(\n\t\t\trecordOf({ element: literalOf('listItem'), children: arrayOf(lazyOf(() => isBlockNode)) }),\n\t\t),\n\t}),\n\trecordOf({\n\t\telement: literalOf('table'),\n\t\theader: arrayOf(arrayOf(isInlineNode)),\n\t\trows: arrayOf(arrayOf(arrayOf(isInlineNode))),\n\t\talign: arrayOf(literalOf('none', 'left', 'right', 'center')),\n\t}),\n\trecordOf({ element: literalOf('codeBlock'), lang: isString, code: isString }, ['lang']),\n\trecordOf({ element: literalOf('blockquote'), children: arrayOf(lazyOf(() => isBlockNode)) }),\n\trecordOf({ element: literalOf('thematicBreak') }),\n)\n\n/**\n * Determine whether an arbitrary value is a valid {@link MarkdownNode} - the\n * {@link MarkdownDocument} root, a {@link BlockNode}, a {@link ListItemNode}, or\n * an {@link InlineNode}, recursively validated.\n *\n * @remarks\n * Total: never throws, even on cyclic or pathologically deep input - every\n * combinator involved (`unionOf`, `recordOf`, `arrayOf`, `lazyOf`) is\n * throw-contained per the `@orkestrel/contract` guard contract (AGENTS §14).\n * A list item's shape is inlined here (and in {@link isBlockNode}) rather than\n * named separately - it is used at exactly these two sites.\n *\n * @param value - The value to test\n * @returns `true` when `value` is a well-formed {@link MarkdownNode}\n *\n * @example\n * ```ts\n * import { isMarkdownNode } from '@orkestrel/markdown'\n *\n * isMarkdownNode({ element: 'text', value: 'hi' }) // true\n * isMarkdownNode({ element: 'bogus' }) // false\n * ```\n */\nexport const isMarkdownNode: Guard<MarkdownNode> = unionOf(\n\tlazyOf(() => isMarkdownDocument),\n\tlazyOf(() => isBlockNode),\n\trecordOf({ element: literalOf('listItem'), children: arrayOf(lazyOf(() => isBlockNode)) }),\n\tlazyOf(() => isInlineNode),\n)\n\n/**\n * Determine whether an arbitrary value is a valid {@link MarkdownDocument} -\n * the parsed-AST root {@link parseDocument} returns, recursively\n * validated.\n *\n * @remarks\n * Total: never throws, even on cyclic or pathologically deep input - every\n * combinator involved (`recordOf`, `arrayOf`) is throw-contained per the\n * `@orkestrel/contract` guard contract (AGENTS §14).\n *\n * @param value - The value to test\n * @returns `true` when `value` is a well-formed {@link MarkdownDocument}\n *\n * @example\n * ```ts\n * import { isMarkdownDocument } from '@orkestrel/markdown'\n *\n * isMarkdownDocument({ element: 'document', children: [] }) // true\n * isMarkdownDocument({ element: 'document' }) // false - missing `children`\n * ```\n */\nexport const isMarkdownDocument: Guard<MarkdownDocument> = recordOf({\n\telement: literalOf('document'),\n\tchildren: arrayOf(isBlockNode),\n})\n","import type {\n\tBlockNode,\n\tEmphasisNode,\n\tInlineNode,\n\tLinkNode,\n\tListItemNode,\n\tListItemParts,\n\tMarkdownDocument,\n\tMarkdownHandlers,\n\tMarkdownNode,\n\tMarkdownRewriteHandler,\n\tTableAlign,\n} from './types.js'\nimport { MAX_DEPTH, SAFE_URL_SCHEMES } from './constants.js'\nimport {\n\tisBlockNode,\n\tisEscapable,\n\tisInlineNode,\n\tisQuote,\n\tisTableStart,\n\tisThematicBreak,\n\tisWhitespace,\n} from './validators.js'\nimport { isEmptyString, isNonEmptyArray, isNonEmptyString, parseInteger } from '@orkestrel/contract'\n\n// Markdown parsing + rendering leaves (pure, total, zero-dependency)\n//\n// The pure leaf primitives {@link parseDocument} composes: the line / block\n// scanners (headings, fences, list items, table rows, quotes, thematic breaks), the\n// inline `scan*` engine (emphasis / links / code with backslash escapes), and the HTML\n// escaping + URL-sanitization the renderer leans on. Every function is PURE, TOTAL, and\n// referentially transparent - malformed input degrades to text, never throws (AGENTS\n// §14) - so each is unit-tested in isolation. The ORCHESTRATION that threads these\n// together (the block / inline / render recursion) lives in parsers.ts's functions,\n// not here (AGENTS §5): a helper is a functional-core leaf, a method is the\n// composition. Inline scanning is index-based (no backtracking regex) so it is\n// linear-time - no ReDoS on adversarial input.\n\n// Text + line utilities\n\n/**\n * Normalize line endings to `\\n` and split a markdown document into its lines - CRLF\n * (`\\r\\n`) and bare CR (`\\r`) both collapse to `\\n` first, so a Windows-origin\n * document parses identically. A single trailing newline does not yield a final\n * empty line.\n *\n * @param markdown - The raw markdown source\n * @returns The document's lines, line-terminators stripped\n *\n * @example\n * ```ts\n * splitLines('a\\r\\nb\\nc') // ['a', 'b', 'c']\n * ```\n */\nexport function splitLines(markdown: string): readonly string[] {\n\tconst lines = markdown.replace(/\\r\\n?/g, '\\n').split('\\n')\n\tif (lines.length > 1 && lines[lines.length - 1] === '') lines.pop()\n\treturn lines\n}\n\n/**\n * The count of leading space / tab characters on `line` (a tab counts as one) - the\n * indent that decides whether a list item's continuation belongs to the item.\n *\n * @param line - The line to measure\n * @returns The number of leading space / tab characters\n *\n * @example\n * ```ts\n * leadingIndent(' text') // 2\n * ```\n */\nexport function leadingIndent(line: string): number {\n\tlet count = 0\n\tfor (const character of line) {\n\t\tif (character === ' ' || character === '\\t') count += 1\n\t\telse break\n\t}\n\treturn count\n}\n\n// Block-level detection\n\n/**\n * Extract an ATX heading line (`#` … `######` followed by text) into its\n * `{ level, text }`, or `undefined` when `line` is not a heading. A run of more than 6\n * `#`s, or `#`s not followed by whitespace + text, is not a\n * heading; an optional closing `###` run is stripped.\n *\n * @param line - The candidate line\n * @returns The heading level (1–6) and its raw inline text, or `undefined`\n *\n * @example\n * ```ts\n * extractHeading('## Title') // { level: 2, text: 'Title' }\n * ```\n */\nexport function extractHeading(\n\tline: string,\n): { readonly level: number; readonly text: string } | undefined {\n\tconst match = /^(#{1,6})(?:\\s+(.*))?$/.exec(line.trimStart())\n\tif (!match || match[1] === undefined) return undefined\n\tconst level = match[1].length\n\tconst text = (match[2] ?? '').replace(/\\s+#+\\s*$/, '').trim()\n\treturn { level, text }\n}\n\n/**\n * Extract a fenced-code opening line (```` ``` ```` or `~~~`, optionally with an info\n * string) into its `{ marker, lang }`, or `undefined` when `line` is not a fence\n * opener. `marker` is the exact fence run (the closer must match the same character +\n * at least the same length); `lang` is the first word of the info string.\n *\n * @param line - The candidate line\n * @returns The fence marker run and its language tag, or `undefined`\n *\n * @example\n * ```ts\n * extractFence('```ts') // { marker: '```', lang: 'ts' }\n * ```\n */\nexport function extractFence(\n\tline: string,\n): { readonly marker: string; readonly lang: string | undefined } | undefined {\n\tconst match = /^\\s*(`{3,}|~{3,})\\s*(.*)$/.exec(line)\n\tif (!match || match[1] === undefined) return undefined\n\tconst info = (match[2] ?? '').trim()\n\t// A backtick in a backtick fence's info string is invalid (ambiguous with a span).\n\tif (match[1].startsWith('`') && info.includes('`')) return undefined\n\tconst lang = isNonEmptyString(info) ? info.split(/\\s+/)[0] : undefined\n\treturn { marker: match[1], lang }\n}\n\n/**\n * Extract a list-item line (`-` / `*` / `+` bullet, or `1.` / `1)` ordinal, followed by\n * a space) into its {@link ListItemParts}, or `undefined` when `line` is not a list\n * item. `content` is the text after the marker; `marker` is the full marker-plus-space\n * width (for measuring a continuation's indent).\n *\n * @param line - The candidate line\n * @returns The list-item parts, or `undefined` when not a list item\n *\n * @example\n * ```ts\n * extractListItem('- item') // { ordered: false, start: 1, content: 'item', indent: 0, marker: 2 }\n * ```\n */\nexport function extractListItem(line: string): ListItemParts | undefined {\n\tconst unordered = /^(\\s*)([-*+])\\s+(.*)$/.exec(line)\n\tif (unordered && unordered[1] !== undefined) {\n\t\tconst indent = unordered[1].length\n\t\tconst content = unordered[3] ?? ''\n\t\treturn { ordered: false, start: 1, content, indent, marker: line.length - content.length }\n\t}\n\tconst ordered = /^(\\s*)(\\d{1,9})[.)]\\s+(.*)$/.exec(line)\n\tif (ordered && ordered[1] !== undefined && ordered[2] !== undefined) {\n\t\tconst indent = ordered[1].length\n\t\tconst content = ordered[3] ?? ''\n\t\treturn {\n\t\t\tordered: true,\n\t\t\tstart: parseInteger(ordered[2]) ?? 1,\n\t\t\tcontent,\n\t\t\tindent,\n\t\t\tmarker: line.length - content.length,\n\t\t}\n\t}\n\treturn undefined\n}\n\n/**\n * Strip one level of blockquote marker (`>` plus one optional following space) from a\n * blockquote line, so the de-quoted lines re-parse as nested blocks.\n *\n * @param line - A blockquote line (per {@link isQuote})\n * @returns The line with its leading `>` (and one space) removed\n *\n * @example\n * ```ts\n * stripQuote('> text') // 'text'\n * ```\n */\nexport function stripQuote(line: string): string {\n\treturn line.replace(/^\\s{0,3}>\\s?/, '')\n}\n\n/**\n * Split one GFM table row into its cell strings - outer pipes are optional, an escaped\n * pipe (`\\|`) inside a cell is NOT a separator (it becomes a literal `|`), and the\n * empty leading / trailing cell produced by an outer `|` is dropped.\n *\n * @param row - The raw table row line\n * @returns The row's cells, in column order\n *\n * @example\n * ```ts\n * splitTableRow('|a|b|') // ['a', 'b']\n * ```\n */\nexport function splitTableRow(row: string): readonly string[] {\n\tconst cells: string[] = []\n\tlet current = ''\n\tconst trimmed = row.trim()\n\tfor (let index = 0; index < trimmed.length; index += 1) {\n\t\tconst character = trimmed[index]\n\t\tif (character === '\\\\' && trimmed[index + 1] === '|') {\n\t\t\tcurrent += '|'\n\t\t\tindex += 1\n\t\t} else if (character === '|') {\n\t\t\tcells.push(current)\n\t\t\tcurrent = ''\n\t\t} else {\n\t\t\tcurrent += character\n\t\t}\n\t}\n\tcells.push(current)\n\tif (isNonEmptyArray<string>(cells) && isEmptyString((cells[0] ?? '').trim())) cells.shift()\n\tif (isNonEmptyArray<string>(cells) && isEmptyString((cells[cells.length - 1] ?? '').trim()))\n\t\tcells.pop()\n\treturn cells\n}\n\n/**\n * Derive the per-column {@link TableAlign} list from a GFM delimiter row - `:---`\n * left, `---:` right, `:---:` center, `---` none.\n *\n * @param delimiter - The table's delimiter row\n * @returns One alignment per column, in column order\n *\n * @example\n * ```ts\n * tableAlignments('| :--- | ---: |') // ['left', 'right']\n * ```\n */\nexport function tableAlignments(delimiter: string): readonly TableAlign[] {\n\treturn splitTableRow(delimiter).map((cell) => {\n\t\tconst text = cell.trim()\n\t\tconst left = text.startsWith(':')\n\t\tconst right = text.endsWith(':')\n\t\tif (left && right) return 'center'\n\t\tif (right) return 'right'\n\t\tif (left) return 'left'\n\t\treturn 'none'\n\t})\n}\n\n// Block phase\n\n/**\n * Whether the line at `index` starts a NEW block kind (heading / fence / thematic\n * break / blockquote / list / table) - the paragraph collector stops at such a line\n * so a block following a paragraph without a blank line still parses (a trusted-input\n * caller writing a `##` heading directly under a paragraph, with no intervening blank\n * line).\n *\n * @param lines - The document's lines\n * @param index - The line index to test\n * @returns `true` when the line begins a different block\n *\n * @example\n * ```ts\n * startsBlock(['text', '## Heading'], 1) // true\n * ```\n */\nexport function startsBlock(lines: readonly string[], index: number): boolean {\n\tconst line = lines[index] ?? ''\n\treturn (\n\t\textractHeading(line) !== undefined ||\n\t\textractFence(line) !== undefined ||\n\t\tisThematicBreak(line) ||\n\t\tisQuote(line) ||\n\t\textractListItem(line) !== undefined ||\n\t\tisTableStart(line, lines[index + 1])\n\t)\n}\n\n// Inline phase\n\n/**\n * Resolve backslash escapes in a raw string to their literal characters - used for a\n * link `href` (which is not otherwise inline-parsed) and any plain text run.\n *\n * @param text - The raw text possibly carrying `\\x` escapes\n * @returns The text with escapable `\\x` reduced to `x`\n *\n * @example\n * ```ts\n * unescapeText('\\\\*hi\\\\*') // '*hi*'\n * ```\n */\nexport function unescapeText(text: string): string {\n\tlet out = ''\n\tfor (let index = 0; index < text.length; index += 1) {\n\t\tconst character = text[index] ?? ''\n\t\tif (character === '\\\\' && isEscapable(text[index + 1] ?? '')) {\n\t\t\tout += text[index + 1] ?? ''\n\t\t\tindex += 1\n\t\t} else {\n\t\t\tout += character\n\t\t}\n\t}\n\treturn out\n}\n\n/**\n * Merge adjacent text nodes into one - the inline scanner emits a text node per\n * unrecognized character, so coalescing keeps the AST clean and assertion-friendly.\n *\n * @param nodes - The inline nodes (possibly with adjacent text runs)\n * @returns The nodes with consecutive text nodes concatenated\n *\n * @example\n * ```ts\n * coalesceText([{ element: 'text', value: 'a' }, { element: 'text', value: 'b' }])\n * // [{ element: 'text', value: 'ab' }]\n * ```\n */\nexport function coalesceText(nodes: readonly InlineNode[]): readonly InlineNode[] {\n\tconst out: InlineNode[] = []\n\tfor (const node of nodes) {\n\t\tconst last = out[out.length - 1]\n\t\tif (node.element === 'text' && last !== undefined && last.element === 'text') {\n\t\t\tout[out.length - 1] = { element: 'text', value: last.value + node.value }\n\t\t} else {\n\t\t\tout.push(node)\n\t\t}\n\t}\n\treturn out\n}\n\n/**\n * Scan an inline code span at `start` (a `` ` ``-run … a matching `` ` ``-run of the\n * SAME length, the CommonMark rule that lets a span contain backticks). Returns the\n * span's literal text + end index, or `undefined` when no matching closer exists (it\n * then degrades to literal backticks).\n *\n * @param source - The inline source text\n * @param start - The index of the opening backtick\n * @param to - The exclusive end of the scan window\n * @returns The span text + end index, or `undefined`\n *\n * @example\n * ```ts\n * scanCode('`code`', 0, 6) // { value: 'code', end: 6 }\n * ```\n */\nexport function scanCode(\n\tsource: string,\n\tstart: number,\n\tto: number,\n): { readonly value: string; readonly end: number } | undefined {\n\tlet run = 0\n\twhile (start + run < to && source[start + run] === '`') run += 1\n\tconst open = '`'.repeat(run)\n\tlet search = start + run\n\tfor (;;) {\n\t\tconst closeAt = source.indexOf(open, search)\n\t\tif (closeAt === -1 || closeAt + run > to) return undefined\n\t\t// The closer must be EXACTLY `run` backticks (not bordered by another backtick).\n\t\tif (source[closeAt - 1] !== '`' && source[closeAt + run] !== '`') {\n\t\t\tlet value = source.slice(start + run, closeAt)\n\t\t\tif (\n\t\t\t\tvalue.length > 2 &&\n\t\t\t\tvalue.startsWith(' ') &&\n\t\t\t\tvalue.endsWith(' ') &&\n\t\t\t\tvalue.trim().length > 0\n\t\t\t) {\n\t\t\t\tvalue = value.slice(1, -1)\n\t\t\t}\n\t\t\treturn { value, end: closeAt + run }\n\t\t}\n\t\tsearch = closeAt + 1\n\t}\n}\n\n/**\n * Scan a link `[text](href)` at `start` - the text runs to a BALANCED `]`, then `(`\n * must immediately follow and the destination runs to the matching `)` (both respect\n * nested delimiters + escapes). Returns the link node, or `undefined` when the shape\n * does not hold (it then degrades to a literal `[`).\n *\n * @param source - The inline source text\n * @param start - The index of the opening `[`\n * @param to - The exclusive end of the scan window\n * @param depth - The current inline-recursion depth (defaults to 0 at the entry point);\n * at {@link MAX_DEPTH} the link's text children degrade to literal text instead of\n * recursing further\n * @returns The parsed {@link LinkNode} + end index, or `undefined`\n *\n * @example\n * ```ts\n * scanLink('[text](url)', 0, 11)\n * // { node: { element: 'link', href: 'url', children: [...] }, end: 11 }\n * ```\n */\nexport function scanLink(\n\tsource: string,\n\tstart: number,\n\tto: number,\n\tdepth = 0,\n): { readonly node: LinkNode; readonly end: number } | undefined {\n\tlet bracketDepth = 0\n\tlet close = -1\n\tfor (let index = start; index < to; index += 1) {\n\t\tconst character = source[index] ?? ''\n\t\tif (character === '\\\\') {\n\t\t\tindex += 1\n\t\t\tcontinue\n\t\t}\n\t\tif (character === '[') bracketDepth += 1\n\t\telse if (character === ']') {\n\t\t\tbracketDepth -= 1\n\t\t\tif (bracketDepth === 0) {\n\t\t\t\tclose = index\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\tif (close === -1 || source[close + 1] !== '(') return undefined\n\tlet parenDepth = 0\n\tlet parenClose = -1\n\tfor (let index = close + 1; index < to; index += 1) {\n\t\tconst character = source[index] ?? ''\n\t\tif (character === '\\\\') {\n\t\t\tindex += 1\n\t\t\tcontinue\n\t\t}\n\t\tif (character === '(') parenDepth += 1\n\t\telse if (character === ')') {\n\t\t\tparenDepth -= 1\n\t\t\tif (parenDepth === 0) {\n\t\t\t\tparenClose = index\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\tif (parenClose === -1) return undefined\n\tconst href = unescapeText(source.slice(close + 2, parenClose).trim())\n\tconst children = scanInline(source, start + 1, close, depth + 1)\n\treturn { node: { element: 'link', href, children }, end: parenClose + 1 }\n}\n\n/**\n * Scan an emphasis run at `start` (`*` / `_`, doubled for strong) - finds the nearest\n * matching closing run of the same marker + width, requiring non-space immediately\n * inside both delimiters (the CommonMark flanking simplification that blocks `* x *`).\n * Returns the emphasis node, or `undefined` when no valid closer exists (it then\n * degrades to a literal marker).\n *\n * @param source - The inline source text\n * @param start - The index of the opening marker\n * @param to - The exclusive end of the scan window\n * @param depth - The current inline-recursion depth (defaults to 0 at the entry point);\n * at {@link MAX_DEPTH} the emphasis's children degrade to literal text instead of\n * recursing further\n * @returns The parsed {@link EmphasisNode} + end index, or `undefined`\n *\n * @example\n * ```ts\n * scanEmphasis('*em*', 0, 4)\n * // { node: { element: 'emphasis', strong: false, children: [...] }, end: 4 }\n * ```\n */\nexport function scanEmphasis(\n\tsource: string,\n\tstart: number,\n\tto: number,\n\tdepth = 0,\n): { readonly node: EmphasisNode; readonly end: number } | undefined {\n\tconst marker = source[start] ?? ''\n\tlet run = 0\n\twhile (start + run < to && source[start + run] === marker && run < 2) run += 1\n\tconst strong = run === 2\n\tconst openEnd = start + run\n\tif (openEnd >= to || isWhitespace(source[openEnd] ?? '')) return undefined\n\tlet index = openEnd\n\twhile (index < to) {\n\t\tconst character = source[index] ?? ''\n\t\tif (character === '\\\\') {\n\t\t\tindex += 2\n\t\t\tcontinue\n\t\t}\n\t\tif (character === '`') {\n\t\t\tconst span = scanCode(source, index, to)\n\t\t\tindex = span ? span.end : index + 1\n\t\t\tcontinue\n\t\t}\n\t\tif (character === marker) {\n\t\t\tlet closeRun = 0\n\t\t\twhile (index + closeRun < to && source[index + closeRun] === marker) closeRun += 1\n\t\t\tif (closeRun >= run && !isWhitespace(source[index - 1] ?? '')) {\n\t\t\t\treturn {\n\t\t\t\t\tnode: {\n\t\t\t\t\t\telement: 'emphasis',\n\t\t\t\t\t\tstrong,\n\t\t\t\t\t\tchildren: scanInline(source, openEnd, index, depth + 1),\n\t\t\t\t\t},\n\t\t\t\t\tend: index + run,\n\t\t\t\t}\n\t\t\t}\n\t\t\tindex += closeRun\n\t\t\tcontinue\n\t\t}\n\t\tindex += 1\n\t}\n\treturn undefined\n}\n\n/**\n * Scan the window `[from, to)` of `source` into inline nodes - the single recursive\n * engine the inline phase runs on (emphasis / link text recurse through it). Linear:\n * each character is consumed once; a failed construct emits its opening character as\n * text and advances by one, so there is no re-scan (no ReDoS).\n *\n * @param source - The inline source text\n * @param from - The inclusive start of the scan window\n * @param to - The exclusive end of the scan window\n * @param depth - The current inline-recursion depth (defaults to 0 at the entry point);\n * incremented by one on every recursive descent through {@link scanLink} /\n * {@link scanEmphasis}. At {@link MAX_DEPTH} the window is never scanned for markup -\n * it emits as a single literal text node - so pathological nesting (`[[[[…`,\n * `****…`) cannot exhaust the call stack.\n * @returns The parsed inline nodes (NOT yet coalesced)\n *\n * @example\n * ```ts\n * scanInline('hi *there*', 0, 10) // [{ element: 'text', value: 'hi ' }, { element: 'emphasis', ... }]\n * ```\n */\nexport function scanInline(\n\tsource: string,\n\tfrom: number,\n\tto: number,\n\tdepth = 0,\n): readonly InlineNode[] {\n\tif (depth >= MAX_DEPTH)\n\t\treturn from < to ? [{ element: 'text', value: source.slice(from, to) }] : []\n\tconst nodes: InlineNode[] = []\n\tlet index = from\n\tlet pending = ''\n\twhile (index < to) {\n\t\tconst character = source[index] ?? ''\n\t\tif (character === '\\\\' && index + 1 < to && isEscapable(source[index + 1] ?? '')) {\n\t\t\tpending += source[index + 1] ?? ''\n\t\t\tindex += 2\n\t\t\tcontinue\n\t\t}\n\t\tlet scanned: InlineNode | undefined\n\t\tlet end = index\n\t\tif (character === '`') {\n\t\t\tconst span = scanCode(source, index, to)\n\t\t\tif (span) {\n\t\t\t\tscanned = { element: 'codeSpan', value: span.value }\n\t\t\t\tend = span.end\n\t\t\t}\n\t\t}\n\t\tif (character === '[') {\n\t\t\tconst link = scanLink(source, index, to, depth)\n\t\t\tif (link) {\n\t\t\t\tscanned = link.node\n\t\t\t\tend = link.end\n\t\t\t}\n\t\t}\n\t\tif (character === '*' || character === '_') {\n\t\t\tconst emphasis = scanEmphasis(source, index, to, depth)\n\t\t\tif (emphasis) {\n\t\t\t\tscanned = emphasis.node\n\t\t\t\tend = emphasis.end\n\t\t\t}\n\t\t}\n\t\tif (scanned !== undefined) {\n\t\t\tif (pending.length > 0) {\n\t\t\t\tnodes.push({ element: 'text', value: pending })\n\t\t\t\tpending = ''\n\t\t\t}\n\t\t\tnodes.push(scanned)\n\t\t\tindex = end\n\t\t\tcontinue\n\t\t}\n\t\tpending += character\n\t\tindex += 1\n\t}\n\tif (pending.length > 0) nodes.push({ element: 'text', value: pending })\n\treturn nodes\n}\n\n// Rendering (AST HTML string)\n\n/**\n * HTML-escape text content - `&` / `<` / `>` / `\"` / `'` to their entities - so text\n * from a markdown document can never inject markup. The renderer applies this to every\n * text run, code body, and (escaped further) attribute value.\n *\n * @param text - The raw text\n * @returns The HTML-escaped text\n *\n * @example\n * ```ts\n * escapeHtml('<a>&\"\\'') // '<a>&"''\n * ```\n */\nexport function escapeHtml(text: string): string {\n\treturn text\n\t\t.replace(/&/g, '&')\n\t\t.replace(/</g, '<')\n\t\t.replace(/>/g, '>')\n\t\t.replace(/\"/g, '"')\n\t\t.replace(/'/g, ''')\n}\n\n/**\n * Sanitize + HTML-attribute-escape a link `href` - a destination whose scheme is not\n * in {@link SAFE_URL_SCHEMES} (notably `javascript:` / `data:` / `vbscript:`), or that\n * is protocol-relative (`//host/path`, or a backslash variant a browser normalizes to\n * the same effect - `\\\\host`, `/\\host`, `\\/host` - inherits whatever scheme the\n * embedding page is served over, including an unsafe one), is dropped to an empty\n * string; a relative / anchor / scheme-less (and non-protocol-relative) destination\n * (including a SINGLE leading `/` or `\\`) is kept;\n * the surviving value is then HTML-escaped. Defence-in-depth against an XSS `href`,\n * even though the input is trusted.\n *\n * @param href - The raw link destination\n * @returns A safe, escaped `href` (empty when the scheme is unsafe or protocol-relative)\n *\n * @example\n * ```ts\n * sanitizeUrl('javascript:alert(1)') // ''\n * sanitizeUrl('/path') // '/path'\n * ```\n */\nexport function sanitizeUrl(href: string): string {\n\t// Strip every whitespace + C0/C1 control codepoint (≤ U+0020 or U+007F–U+009F)\n\t// anywhere - a `java\\tscript:` / embedded-newline scheme-spoofing evasion - by\n\t// codepoint, not a control-character regex class (AGENTS §1: no disables).\n\tlet cleaned = ''\n\tfor (const character of href) {\n\t\tconst code = character.codePointAt(0) ?? 0\n\t\tif (code > 0x20 && !(code >= 0x7f && code <= 0x9f)) cleaned += character\n\t}\n\tif (/^[/\\\\]{2}/.exec(cleaned)) return ''\n\tconst scheme = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(cleaned)\n\tif (scheme && scheme[1] !== undefined && !SAFE_URL_SCHEMES.has(scheme[1].toLowerCase())) return ''\n\treturn escapeHtml(cleaned)\n}\n\n/**\n * Render a {@link MarkdownNode} (typically a {@link MarkdownDocument}) to a safe HTML\n * string - the recursive AST → HTML engine (headings, paragraphs, lists, GFM tables,\n * fenced code, blockquotes, links, emphasis, inline code), escaping every text run and\n * sanitizing every link `href`.\n *\n * @remarks\n * Total: never throws. At {@link MAX_DEPTH} a value-bearing node (`text` / `codeSpan`)\n * degrades to its escaped `value`; any other node degrades to `''` instead of\n * recursing further, so pathologically deep input cannot exhaust the call stack.\n *\n * @param node - The AST node to render (a full document, or any sub-node)\n * @returns The rendered, XSS-safe HTML string\n *\n * @example\n * ```ts\n * renderHTML({ element: 'document', children: [\n * { element: 'heading', level: 1, children: [{ element: 'text', value: 'Hi' }] },\n * ] })\n * // '<h1>Hi</h1>'\n * ```\n */\nexport function renderHTML(node: MarkdownNode): string {\n\tconst stack: {\n\t\treadonly node: MarkdownNode\n\t\treadonly depth: number\n\t\treadonly expanded: boolean\n\t\treadonly count: number\n\t}[] = [{ node, depth: 0, expanded: false, count: 0 }]\n\tconst values: string[] = []\n\twhile (stack.length > 0) {\n\t\tconst frame = stack.pop()\n\t\tif (frame === undefined) continue\n\t\tconst current = frame.node\n\t\tif (!frame.expanded) {\n\t\t\tif (frame.depth >= MAX_DEPTH) {\n\t\t\t\tvalues.push(\n\t\t\t\t\t'value' in current && typeof current.value === 'string' ? escapeHtml(current.value) : '',\n\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst children: MarkdownNode[] = []\n\t\t\tlet depth = frame.depth + 1\n\t\t\tswitch (current.element) {\n\t\t\t\tcase 'document':\n\t\t\t\tcase 'heading':\n\t\t\t\tcase 'paragraph':\n\t\t\t\tcase 'blockquote':\n\t\t\t\t\tfor (const child of current.children) if (child !== undefined) children.push(child)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'listItem': {\n\t\t\t\t\tconst only = current.children[0]\n\t\t\t\t\tif (current.children.length === 1 && only !== undefined && only.element === 'paragraph') {\n\t\t\t\t\t\tfor (const child of only.children) if (child !== undefined) children.push(child)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfor (const child of current.children) if (child !== undefined) children.push(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'emphasis':\n\t\t\t\tcase 'link':\n\t\t\t\t\tfor (const child of current.children) if (child !== undefined) children.push(child)\n\t\t\t\t\tdepth += 1\n\t\t\t\t\tbreak\n\t\t\t\tcase 'list':\n\t\t\t\t\tfor (const child of current.items) if (child !== undefined) children.push(child)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'table':\n\t\t\t\t\tfor (const cell of current.header)\n\t\t\t\t\t\tif (cell !== undefined)\n\t\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) children.push(child)\n\t\t\t\t\tfor (const row of current.rows)\n\t\t\t\t\t\tif (row !== undefined)\n\t\t\t\t\t\t\tfor (const cell of row)\n\t\t\t\t\t\t\t\tif (cell !== undefined)\n\t\t\t\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) children.push(child)\n\t\t\t\t\tdepth += 1\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t\tstack.push({ ...frame, expanded: true, count: children.length })\n\t\t\tfor (let index = children.length - 1; index >= 0; index -= 1) {\n\t\t\t\tconst child = children[index]\n\t\t\t\tif (child !== undefined) stack.push({ node: child, depth, expanded: false, count: 0 })\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tconst children =\n\t\t\tframe.count === 0 ? [] : values.splice(values.length - frame.count, frame.count)\n\t\tlet value = ''\n\t\tswitch (current.element) {\n\t\t\tcase 'document':\n\t\t\t\tvalue = children.join('\\n')\n\t\t\t\tbreak\n\t\t\tcase 'heading':\n\t\t\t\tvalue = `<h${current.level}>${children.join('')}</h${current.level}>`\n\t\t\t\tbreak\n\t\t\tcase 'paragraph':\n\t\t\t\tvalue = `<p>${children.join('')}</p>`\n\t\t\t\tbreak\n\t\t\tcase 'thematicBreak':\n\t\t\t\tvalue = '<hr>'\n\t\t\t\tbreak\n\t\t\tcase 'blockquote':\n\t\t\t\tvalue = `<blockquote>\\n${children.join('\\n')}\\n</blockquote>`\n\t\t\t\tbreak\n\t\t\tcase 'codeBlock': {\n\t\t\t\tconst open =\n\t\t\t\t\tcurrent.lang === undefined\n\t\t\t\t\t\t? '<code>'\n\t\t\t\t\t\t: `<code class=\"language-${escapeHtml(current.lang)}\">`\n\t\t\t\tvalue = `<pre>${open}${escapeHtml(current.code)}</code></pre>`\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'list': {\n\t\t\t\tconst items = children.join('\\n')\n\t\t\t\tif (!current.ordered) {\n\t\t\t\t\tvalue = `<ul>\\n${items}\\n</ul>`\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tconst start = current.start !== 1 ? ` start=\"${current.start}\"` : ''\n\t\t\t\tvalue = `<ol${start}>\\n${items}\\n</ol>`\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'listItem':\n\t\t\t\tvalue = `<li>${children.join(\n\t\t\t\t\tcurrent.children.length === 1 && current.children[0]?.element === 'paragraph' ? '' : '\\n',\n\t\t\t\t)}</li>`\n\t\t\t\tbreak\n\t\t\tcase 'table': {\n\t\t\t\tlet offset = 0\n\t\t\t\tconst header: string[] = []\n\t\t\t\tfor (const [column, cell] of current.header.entries()) {\n\t\t\t\t\tif (cell === undefined) continue\n\t\t\t\t\tconst align = current.align[column]\n\t\t\t\t\tconst style =\n\t\t\t\t\t\talign === 'left' || align === 'right' || align === 'center'\n\t\t\t\t\t\t\t? ` style=\"text-align:${align}\"`\n\t\t\t\t\t\t\t: ''\n\t\t\t\t\tlet count = 0\n\t\t\t\t\tfor (const child of cell) if (child !== undefined) count += 1\n\t\t\t\t\theader.push(`<th${style}>${children.slice(offset, offset + count).join('')}</th>`)\n\t\t\t\t\toffset += count\n\t\t\t\t}\n\t\t\t\tconst rows: string[] = []\n\t\t\t\tfor (const row of current.rows) {\n\t\t\t\t\tconst cells: string[] = []\n\t\t\t\t\tfor (const [column, cell] of row.entries()) {\n\t\t\t\t\t\tif (cell === undefined) continue\n\t\t\t\t\t\tconst align = current.align[column]\n\t\t\t\t\t\tconst style =\n\t\t\t\t\t\t\talign === 'left' || align === 'right' || align === 'center'\n\t\t\t\t\t\t\t\t? ` style=\"text-align:${align}\"`\n\t\t\t\t\t\t\t\t: ''\n\t\t\t\t\t\tlet count = 0\n\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) count += 1\n\t\t\t\t\t\tcells.push(`<td${style}>${children.slice(offset, offset + count).join('')}</td>`)\n\t\t\t\t\t\toffset += count\n\t\t\t\t\t}\n\t\t\t\t\trows.push(`<tr>${cells.join('')}</tr>`)\n\t\t\t\t}\n\t\t\t\tconst body = rows.join('\\n')\n\t\t\t\tconst bodyHtml = isNonEmptyArray(current.rows) ? `\\n<tbody>\\n${body}\\n</tbody>` : ''\n\t\t\t\tvalue = `<table>\\n<thead>\\n<tr>${header.join('')}</tr>\\n</thead>${bodyHtml}\\n</table>`\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'text':\n\t\t\t\tvalue = escapeHtml(current.value)\n\t\t\t\tbreak\n\t\t\tcase 'emphasis':\n\t\t\t\tvalue = current.strong\n\t\t\t\t\t? `<strong>${children.join('')}</strong>`\n\t\t\t\t\t: `<em>${children.join('')}</em>`\n\t\t\t\tbreak\n\t\t\tcase 'codeSpan':\n\t\t\t\tvalue = `<code>${escapeHtml(current.value)}</code>`\n\t\t\t\tbreak\n\t\t\tcase 'link':\n\t\t\t\tvalue = `<a href=\"${sanitizeUrl(current.href)}\">${children.join('')}</a>`\n\t\t\t\tbreak\n\t\t\tdefault:\n\t\t\t\tvalue = ''\n\t\t\t\tbreak\n\t\t}\n\t\tif (stack.length === 0) return value\n\t\tvalues.push(value)\n\t}\n\treturn ''\n}\n\n/**\n * Render a {@link MarkdownNode} to its CANONICAL markdown source - the inverse\n * projection of `renderHTML`, and the serializer a `parse(renderMarkdown(doc))`\n * round-trip is built on. Canonical forms: `*em*` / `**strong**` (underscore emphasis\n * normalizes to asterisks), `- ` bullets, `N. ` sequential ordinals (from the list's\n * `start`), `---` thematic breaks, fenced code blocks (backtick run widened past any\n * 3+ backtick run inside the body), ATX headings, `> `-prefixed blockquote lines, GFM\n * tables (1-space-padded cells, `\\|`-escaped pipes, an alignment delimiter row), and\n * `[text](href)` links. A `text` node's literal content is backslash-escaped wherever\n * it would otherwise re-parse as markup (AGENTS §14 parse↔render soundness).\n *\n * @remarks\n * Total: never throws. At {@link MAX_DEPTH} a value-bearing node degrades to its\n * escaped `value`; any other node degrades to `''`. Blocks are joined by exactly one\n * blank line; a document with zero blocks renders `''`.\n *\n * @param node - The AST node to render (a full document, or any sub-node)\n * @returns The canonical markdown source\n *\n * @example\n * ```ts\n * renderMarkdown({ element: 'document', children: [\n * { element: 'heading', level: 2, children: [{ element: 'text', value: 'Hi' }] },\n * ] })\n * // '## Hi'\n * ```\n */\nexport function renderMarkdown(node: MarkdownNode): string {\n\tconst stack: {\n\t\treadonly node: MarkdownNode\n\t\treadonly depth: number\n\t\treadonly expanded: boolean\n\t\treadonly count: number\n\t\treadonly escaped: string\n\t}[] = [{ node, depth: 0, expanded: false, count: 0, escaped: '' }]\n\tconst values: string[] = []\n\twhile (stack.length > 0) {\n\t\tconst frame = stack.pop()\n\t\tif (frame === undefined) continue\n\t\tconst current = frame.node\n\t\tif (!frame.expanded) {\n\t\t\tlet escaped = ''\n\t\t\tif (\n\t\t\t\t(frame.depth >= MAX_DEPTH || current.element === 'text') &&\n\t\t\t\t'value' in current &&\n\t\t\t\ttypeof current.value === 'string'\n\t\t\t) {\n\t\t\t\tfor (let index = 0; index < current.value.length; index += 1) {\n\t\t\t\t\tconst character = current.value[index] ?? ''\n\t\t\t\t\tconst atLineStart = index === 0 || current.value[index - 1] === '\\n'\n\t\t\t\t\tif (\n\t\t\t\t\t\tcharacter === '\\\\' ||\n\t\t\t\t\t\tcharacter === '*' ||\n\t\t\t\t\t\tcharacter === '_' ||\n\t\t\t\t\t\tcharacter === '`' ||\n\t\t\t\t\t\tcharacter === '[' ||\n\t\t\t\t\t\tcharacter === ']'\n\t\t\t\t\t) {\n\t\t\t\t\t\tescaped += `\\\\${character}`\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tif (atLineStart) {\n\t\t\t\t\t\tif (character === '#' || character === '>') {\n\t\t\t\t\t\t\tescaped += `\\\\${character}`\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t(character === '-' || character === '+') &&\n\t\t\t\t\t\t\t(current.value[index + 1] ?? ' ') === ' '\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tescaped += `\\\\${character}`\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (/[0-9]/.test(character)) {\n\t\t\t\t\t\t\tlet end = index\n\t\t\t\t\t\t\twhile (end < current.value.length && /[0-9]/.test(current.value[end] ?? '')) end += 1\n\t\t\t\t\t\t\tconst marker = current.value[end]\n\t\t\t\t\t\t\tif ((marker === '.' || marker === ')') && current.value[end + 1] === ' ') {\n\t\t\t\t\t\t\t\tescaped += `${current.value.slice(index, end)}\\\\${marker}`\n\t\t\t\t\t\t\t\tindex = end\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tescaped += character\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (frame.depth >= MAX_DEPTH) {\n\t\t\t\tvalues.push(escaped)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst children: MarkdownNode[] = []\n\t\t\tlet depth = frame.depth + 1\n\t\t\tswitch (current.element) {\n\t\t\t\tcase 'document':\n\t\t\t\tcase 'heading':\n\t\t\t\tcase 'paragraph':\n\t\t\t\tcase 'blockquote':\n\t\t\t\tcase 'listItem':\n\t\t\t\tcase 'emphasis':\n\t\t\t\tcase 'link':\n\t\t\t\t\tfor (const child of current.children) if (child !== undefined) children.push(child)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'list':\n\t\t\t\t\tfor (const child of current.items) if (child !== undefined) children.push(child)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'table':\n\t\t\t\t\tfor (const cell of current.header)\n\t\t\t\t\t\tif (cell !== undefined)\n\t\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) children.push(child)\n\t\t\t\t\tfor (const row of current.rows) {\n\t\t\t\t\t\tif (row === undefined) continue\n\t\t\t\t\t\tfor (let column = 0; column < current.header.length; column += 1) {\n\t\t\t\t\t\t\tconst cell = row[column]\n\t\t\t\t\t\t\tif (cell !== undefined)\n\t\t\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) children.push(child)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdepth += 1\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t\tstack.push({ ...frame, expanded: true, count: children.length, escaped })\n\t\t\tfor (let index = children.length - 1; index >= 0; index -= 1) {\n\t\t\t\tconst child = children[index]\n\t\t\t\tif (child !== undefined)\n\t\t\t\t\tstack.push({ node: child, depth, expanded: false, count: 0, escaped: '' })\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tconst children =\n\t\t\tframe.count === 0 ? [] : values.splice(values.length - frame.count, frame.count)\n\t\tlet value = ''\n\t\tswitch (current.element) {\n\t\t\tcase 'codeBlock':\n\t\t\tcase 'codeSpan': {\n\t\t\t\tconst body = current.element === 'codeBlock' ? current.code : current.value\n\t\t\t\tlet longest = 0\n\t\t\t\tlet run = 0\n\t\t\t\tfor (const character of body) {\n\t\t\t\t\tif (character === '`') {\n\t\t\t\t\t\trun += 1\n\t\t\t\t\t\tlongest = Math.max(longest, run)\n\t\t\t\t\t} else {\n\t\t\t\t\t\trun = 0\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconst fence = '`'.repeat(Math.max(current.element === 'codeBlock' ? 3 : 1, longest + 1))\n\t\t\t\tif (current.element === 'codeBlock') {\n\t\t\t\t\tconst lang = current.lang === undefined ? '' : current.lang\n\t\t\t\t\tvalue = `${fence}${lang}\\n${current.code}\\n${fence}`\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tconst pad = current.value.startsWith('`') || current.value.endsWith('`') ? ' ' : ''\n\t\t\t\tvalue = `${fence}${pad}${current.value}${pad}${fence}`\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'document':\n\t\t\t\tvalue = children.join('\\n\\n')\n\t\t\t\tbreak\n\t\t\tcase 'heading': {\n\t\t\t\tconst text = children.join('')\n\t\t\t\tconst escaped = text.replace(/(^|[^\\\\])(#+)$/, (_match, before: string, hashes: string) => {\n\t\t\t\t\tconst first = hashes[0] ?? ''\n\t\t\t\t\treturn `${before}\\\\${first}${hashes.slice(1)}`\n\t\t\t\t})\n\t\t\t\tvalue = `${'#'.repeat(current.level)} ${escaped}`\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'paragraph':\n\t\t\t\tvalue = children.join('')\n\t\t\t\tbreak\n\t\t\tcase 'thematicBreak':\n\t\t\t\tvalue = '---'\n\t\t\t\tbreak\n\t\t\tcase 'blockquote':\n\t\t\t\tvalue = children\n\t\t\t\t\t.join('\\n\\n')\n\t\t\t\t\t.split('\\n')\n\t\t\t\t\t.map((line) => (line === '' ? '>' : `> ${line}`))\n\t\t\t\t\t.join('\\n')\n\t\t\t\tbreak\n\t\t\tcase 'list': {\n\t\t\t\tconst items: string[] = []\n\t\t\t\tlet ordinal = current.start\n\t\t\t\tfor (const body of children) {\n\t\t\t\t\tconst marker = current.ordered ? `${ordinal}. ` : '- '\n\t\t\t\t\tordinal += 1\n\t\t\t\t\tconst pad = ' '.repeat(marker.length)\n\t\t\t\t\titems.push(\n\t\t\t\t\t\tbody\n\t\t\t\t\t\t\t.split('\\n')\n\t\t\t\t\t\t\t.map((line, index) => (index === 0 ? marker + line : line === '' ? '' : pad + line))\n\t\t\t\t\t\t\t.join('\\n'),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tvalue = items.join('\\n')\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'listItem':\n\t\t\t\tvalue = children.join('\\n\\n')\n\t\t\t\tbreak\n\t\t\tcase 'table': {\n\t\t\t\tlet offset = 0\n\t\t\t\tconst header: string[] = []\n\t\t\t\tfor (const cell of current.header) {\n\t\t\t\t\tif (cell === undefined) {\n\t\t\t\t\t\theader.push('')\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tlet count = 0\n\t\t\t\t\tfor (const child of cell) if (child !== undefined) count += 1\n\t\t\t\t\theader.push(\n\t\t\t\t\t\tchildren\n\t\t\t\t\t\t\t.slice(offset, offset + count)\n\t\t\t\t\t\t\t.join('')\n\t\t\t\t\t\t\t.replace(/\\|/g, '\\\\|'),\n\t\t\t\t\t)\n\t\t\t\t\toffset += count\n\t\t\t\t}\n\t\t\t\tconst delimiter = current.align.map((align) => {\n\t\t\t\t\tif (align === 'left') return ':--'\n\t\t\t\t\tif (align === 'right') return '--:'\n\t\t\t\t\tif (align === 'center') return ':-:'\n\t\t\t\t\treturn '---'\n\t\t\t\t})\n\t\t\t\tconst rows: string[] = []\n\t\t\t\tfor (const row of current.rows) {\n\t\t\t\t\tconst cells: string[] = []\n\t\t\t\t\tfor (let column = 0; column < current.header.length; column += 1) {\n\t\t\t\t\t\tconst cell = row[column]\n\t\t\t\t\t\tif (cell === undefined) {\n\t\t\t\t\t\t\tcells.push('')\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet count = 0\n\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) count += 1\n\t\t\t\t\t\tcells.push(\n\t\t\t\t\t\t\tchildren\n\t\t\t\t\t\t\t\t.slice(offset, offset + count)\n\t\t\t\t\t\t\t\t.join('')\n\t\t\t\t\t\t\t\t.replace(/\\|/g, '\\\\|'),\n\t\t\t\t\t\t)\n\t\t\t\t\t\toffset += count\n\t\t\t\t\t}\n\t\t\t\t\trows.push(`| ${cells.join(' | ')} |`)\n\t\t\t\t}\n\t\t\t\tvalue = [`| ${header.join(' | ')} |`, `| ${delimiter.join(' | ')} |`, ...rows].join('\\n')\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'text':\n\t\t\t\tvalue = frame.escaped\n\t\t\t\tbreak\n\t\t\tcase 'emphasis': {\n\t\t\t\tconst marker = current.strong ? '**' : '*'\n\t\t\t\tvalue = `${marker}${children.join('')}${marker}`\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'link': {\n\t\t\t\tconst href = current.href.replace(/[\\\\()]/g, (character) => `\\\\${character}`)\n\t\t\t\tvalue = `[${children.join('')}](${href})`\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tvalue = ''\n\t\t\t\tbreak\n\t\t}\n\t\tif (stack.length === 0) return value\n\t\tvalues.push(value)\n\t}\n\treturn ''\n}\n\n/**\n * Depth-first, pre-order, root-inclusive traversal of a {@link MarkdownNode} - yields\n * the node itself, then recurses into its children (block children, list items, table\n * header/row cells' inline nodes) in walk order.\n *\n * @remarks\n * Total: never throws. Descent stops at {@link MAX_DEPTH} (the node at the cap is\n * still yielded; its children are not) so pathologically deep input cannot exhaust\n * the call stack.\n *\n * @param node - The AST node to walk (a full document, or any sub-node)\n * @returns A generator yielding every visited node, pre-order\n *\n * @example\n * ```ts\n * const doc = { element: 'document', children: [{ element: 'thematicBreak' }] } as const\n * [...walkNodes(doc)].map((node) => node.element) // ['document', 'thematicBreak']\n * ```\n */\nexport function* walkNodes(node: MarkdownNode): Generator<MarkdownNode> {\n\tconst stack: { readonly node: MarkdownNode; readonly depth: number }[] = [{ node, depth: 0 }]\n\twhile (stack.length > 0) {\n\t\tconst frame = stack.pop()\n\t\tif (frame === undefined) continue\n\t\tyield frame.node\n\t\tif (frame.depth >= MAX_DEPTH) continue\n\t\tconst children: MarkdownNode[] = []\n\t\tswitch (frame.node.element) {\n\t\t\tcase 'document':\n\t\t\tcase 'heading':\n\t\t\tcase 'paragraph':\n\t\t\tcase 'blockquote':\n\t\t\tcase 'listItem':\n\t\t\tcase 'emphasis':\n\t\t\tcase 'link':\n\t\t\t\tfor (const child of frame.node.children) if (child !== undefined) children.push(child)\n\t\t\t\tbreak\n\t\t\tcase 'list':\n\t\t\t\tfor (const child of frame.node.items) if (child !== undefined) children.push(child)\n\t\t\t\tbreak\n\t\t\tcase 'table':\n\t\t\t\tfor (const cell of frame.node.header)\n\t\t\t\t\tif (cell !== undefined)\n\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) children.push(child)\n\t\t\t\tfor (const row of frame.node.rows)\n\t\t\t\t\tif (row !== undefined)\n\t\t\t\t\t\tfor (const cell of row)\n\t\t\t\t\t\t\tif (cell !== undefined)\n\t\t\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) children.push(child)\n\t\t\t\tbreak\n\t\t}\n\t\tfor (let index = children.length - 1; index >= 0; index -= 1) {\n\t\t\tconst child = children[index]\n\t\t\tif (child !== undefined) stack.push({ node: child, depth: frame.depth + 1 })\n\t\t}\n\t}\n}\n\n/**\n * Fold a {@link MarkdownNode} into a `T` via a total catamorphism - children are\n * folded first (post-order), then the node's own {@link MarkdownHandler} is invoked\n * with the already-folded children.\n *\n * @remarks\n * **Table contract.** A {@link TableNode} has no single `children` array - its cells\n * live in `header` (one inline-node list per column) and `rows` (a list of such\n * rows). The `table` handler receives ONE folded `T` per inline node, flattened in\n * walk order across ALL cells - every header cell's inline nodes (column order), then\n * every body row's cells' inline nodes (row order, then column order) - and reads\n * `node.header[c].length` / `node.rows[r][c].length` off the table node itself to\n * recover cell boundaries within the flat list.\n *\n * Total: never throws. At `depth >= {@link MAX_DEPTH}` the node's handler is invoked\n * with an empty children list instead of recursing further.\n *\n * @param node - The AST node to fold\n * @param handlers - The total {@link MarkdownHandlers} table, one handler per element\n * @param depth - The starting recursion depth (pass `0` at the entry point)\n * @returns The folded `T`\n *\n * @example\n * ```ts\n * const countHandlers: MarkdownHandlers<number> = {\n * document: (_, children) => children.reduce((a, b) => a + b, 1),\n * // ...one handler per element, each summing its folded children\n * }\n * foldNode(document, countHandlers, 0) // total node count\n * ```\n */\nexport function foldNode<T>(node: MarkdownNode, handlers: MarkdownHandlers<T>, depth: number): T {\n\tconst stack: {\n\t\treadonly node: MarkdownNode\n\t\treadonly depth: number\n\t\treadonly expanded: boolean\n\t\treadonly count: number\n\t}[] = [{ node, depth, expanded: false, count: 0 }]\n\tconst values: T[] = []\n\twhile (stack.length > 0) {\n\t\tconst frame = stack.pop()\n\t\tif (frame === undefined) continue\n\t\tif (!frame.expanded) {\n\t\t\tconst children: MarkdownNode[] = []\n\t\t\tif (frame.depth < MAX_DEPTH) {\n\t\t\t\tswitch (frame.node.element) {\n\t\t\t\t\tcase 'document':\n\t\t\t\t\tcase 'heading':\n\t\t\t\t\tcase 'paragraph':\n\t\t\t\t\tcase 'blockquote':\n\t\t\t\t\tcase 'listItem':\n\t\t\t\t\tcase 'emphasis':\n\t\t\t\t\tcase 'link':\n\t\t\t\t\t\tfor (const child of frame.node.children) if (child !== undefined) children.push(child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'list':\n\t\t\t\t\t\tfor (const child of frame.node.items) if (child !== undefined) children.push(child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'table':\n\t\t\t\t\t\tfor (const cell of frame.node.header)\n\t\t\t\t\t\t\tif (cell !== undefined)\n\t\t\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) children.push(child)\n\t\t\t\t\t\tfor (const row of frame.node.rows)\n\t\t\t\t\t\t\tif (row !== undefined)\n\t\t\t\t\t\t\t\tfor (const cell of row)\n\t\t\t\t\t\t\t\t\tif (cell !== undefined)\n\t\t\t\t\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) children.push(child)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tstack.push({ ...frame, expanded: true, count: children.length })\n\t\t\tfor (let index = children.length - 1; index >= 0; index -= 1) {\n\t\t\t\tconst child = children[index]\n\t\t\t\tif (child !== undefined) {\n\t\t\t\t\tstack.push({\n\t\t\t\t\t\tnode: child,\n\t\t\t\t\t\tdepth: frame.depth + 1,\n\t\t\t\t\t\texpanded: false,\n\t\t\t\t\t\tcount: 0,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tconst children =\n\t\t\tframe.count === 0 ? [] : values.splice(values.length - frame.count, frame.count)\n\t\tlet value: T\n\t\tswitch (frame.node.element) {\n\t\t\tcase 'document':\n\t\t\t\tvalue = handlers.document(frame.node, children)\n\t\t\t\tbreak\n\t\t\tcase 'heading':\n\t\t\t\tvalue = handlers.heading(frame.node, children)\n\t\t\t\tbreak\n\t\t\tcase 'paragraph':\n\t\t\t\tvalue = handlers.paragraph(frame.node, children)\n\t\t\t\tbreak\n\t\t\tcase 'thematicBreak':\n\t\t\t\tvalue = handlers.thematicBreak(frame.node, children)\n\t\t\t\tbreak\n\t\t\tcase 'blockquote':\n\t\t\t\tvalue = handlers.blockquote(frame.node, children)\n\t\t\t\tbreak\n\t\t\tcase 'codeBlock':\n\t\t\t\tvalue = handlers.codeBlock(frame.node, children)\n\t\t\t\tbreak\n\t\t\tcase 'list':\n\t\t\t\tvalue = handlers.list(frame.node, children)\n\t\t\t\tbreak\n\t\t\tcase 'listItem':\n\t\t\t\tvalue = handlers.listItem(frame.node, children)\n\t\t\t\tbreak\n\t\t\tcase 'table':\n\t\t\t\tvalue = handlers.table(frame.node, children)\n\t\t\t\tbreak\n\t\t\tcase 'text':\n\t\t\t\tvalue = handlers.text(frame.node, children)\n\t\t\t\tbreak\n\t\t\tcase 'emphasis':\n\t\t\t\tvalue = handlers.emphasis(frame.node, children)\n\t\t\t\tbreak\n\t\t\tcase 'codeSpan':\n\t\t\t\tvalue = handlers.codeSpan(frame.node, children)\n\t\t\t\tbreak\n\t\t\tcase 'link':\n\t\t\t\tvalue = handlers.link(frame.node, children)\n\t\t\t\tbreak\n\t\t}\n\t\tif (stack.length === 0) return value\n\t\tvalues.push(value)\n\t}\n\tswitch (node.element) {\n\t\tcase 'document':\n\t\t\treturn handlers.document(node, [])\n\t\tcase 'heading':\n\t\t\treturn handlers.heading(node, [])\n\t\tcase 'paragraph':\n\t\t\treturn handlers.paragraph(node, [])\n\t\tcase 'thematicBreak':\n\t\t\treturn handlers.thematicBreak(node, [])\n\t\tcase 'blockquote':\n\t\t\treturn handlers.blockquote(node, [])\n\t\tcase 'codeBlock':\n\t\t\treturn handlers.codeBlock(node, [])\n\t\tcase 'list':\n\t\t\treturn handlers.list(node, [])\n\t\tcase 'listItem':\n\t\t\treturn handlers.listItem(node, [])\n\t\tcase 'table':\n\t\t\treturn handlers.table(node, [])\n\t\tcase 'text':\n\t\t\treturn handlers.text(node, [])\n\t\tcase 'emphasis':\n\t\t\treturn handlers.emphasis(node, [])\n\t\tcase 'codeSpan':\n\t\t\treturn handlers.codeSpan(node, [])\n\t\tcase 'link':\n\t\t\treturn handlers.link(node, [])\n\t}\n}\n\n/**\n * Rewrite a {@link MarkdownDocument} bottom-up (copy-on-write) - each node's children\n * are rewritten first (post-order), then `rewrite` is applied to the node itself; the\n * document ROOT is never passed to `rewrite` (the `element: 'document'` invariant\n * always holds). A table's inline cells and a list's items ARE rewritten.\n *\n * @remarks\n * Never mutates `document` - every level is rebuilt into a fresh object/array, even\n * when `rewrite` returns its input unchanged. When `rewrite` returns a node whose\n * `element` does not fit the slot it was called for (a block slot handed a\n * non-{@link BlockNode}, an inline slot handed a non-{@link InlineNode}, a list-item\n * slot handed a non-`listItem`), the ill-fitting result is discarded and the\n * freshly-rebuilt (unrewritten-at-this-level) node is kept instead - `rewriteDocument`\n * stays total and never produces a structurally invalid document.\n *\n * Descent is capped at {@link MAX_DEPTH}, the same cap {@link walkNodes} and\n * {@link foldNode} observe: at `depth >= MAX_DEPTH` the subtree is passed through\n * UNCHANGED (by reference, not rebuilt, and `rewrite` is not invoked on it) instead of\n * recursing further, so a pathologically deep adopted document cannot exhaust the\n * call stack. {@link MarkdownInterface.map} inherits this cap since it delegates here.\n *\n * @param document - The document AST to rewrite\n * @param rewrite - The bottom-up {@link MarkdownRewriteHandler}\n * @returns A new, rewritten {@link MarkdownDocument}\n *\n * @example\n * ```ts\n * rewriteDocument(document, (node) =>\n * node.element === 'text' ? { element: 'text', value: node.value.toUpperCase() } : node,\n * )\n * ```\n */\nexport function rewriteDocument(\n\tdocument: MarkdownDocument,\n\trewrite: MarkdownRewriteHandler,\n): MarkdownDocument {\n\tconst stack: {\n\t\treadonly node: MarkdownNode\n\t\treadonly depth: number\n\t\treadonly expanded: boolean\n\t\treadonly count: number\n\t}[] = [{ node: document, depth: -1, expanded: false, count: 0 }]\n\tconst values: MarkdownNode[] = []\n\twhile (stack.length > 0) {\n\t\tconst frame = stack.pop()\n\t\tif (frame === undefined) continue\n\t\tconst current = frame.node\n\t\tif (!frame.expanded) {\n\t\t\tif (current.element !== 'document' && frame.depth >= MAX_DEPTH) {\n\t\t\t\tvalues.push(current)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst children: MarkdownNode[] = []\n\t\t\tswitch (current.element) {\n\t\t\t\tcase 'document':\n\t\t\t\tcase 'heading':\n\t\t\t\tcase 'paragraph':\n\t\t\t\tcase 'blockquote':\n\t\t\t\tcase 'listItem':\n\t\t\t\tcase 'emphasis':\n\t\t\t\tcase 'link':\n\t\t\t\t\tfor (const child of current.children) if (child !== undefined) children.push(child)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'list':\n\t\t\t\t\tfor (const child of current.items) if (child !== undefined) children.push(child)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'table':\n\t\t\t\t\tfor (const cell of current.header)\n\t\t\t\t\t\tif (cell !== undefined)\n\t\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) children.push(child)\n\t\t\t\t\tfor (const row of current.rows)\n\t\t\t\t\t\tif (row !== undefined)\n\t\t\t\t\t\t\tfor (const cell of row)\n\t\t\t\t\t\t\t\tif (cell !== undefined)\n\t\t\t\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) children.push(child)\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t\tstack.push({ ...frame, expanded: true, count: children.length })\n\t\t\tconst depth = current.element === 'document' ? 0 : frame.depth + 1\n\t\t\tfor (let index = children.length - 1; index >= 0; index -= 1) {\n\t\t\t\tconst child = children[index]\n\t\t\t\tif (child !== undefined) stack.push({ node: child, depth, expanded: false, count: 0 })\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tconst children =\n\t\t\tframe.count === 0 ? [] : values.splice(values.length - frame.count, frame.count)\n\t\tlet rebuilt: MarkdownNode = current\n\t\tswitch (current.element) {\n\t\t\tcase 'document': {\n\t\t\t\tconst blocks: BlockNode[] = []\n\t\t\t\tlet offset = 0\n\t\t\t\tfor (const block of current.children) {\n\t\t\t\t\tif (block === undefined) continue\n\t\t\t\t\tconst child = children[offset]\n\t\t\t\t\tblocks.push(child !== undefined && isBlockNode(child) ? child : block)\n\t\t\t\t\toffset += 1\n\t\t\t\t}\n\t\t\t\tconst result: MarkdownDocument = { element: 'document', children: blocks }\n\t\t\t\tif (stack.length === 0) return result\n\t\t\t\tvalues.push(result)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tcase 'heading':\n\t\t\tcase 'paragraph': {\n\t\t\t\tconst inlines: InlineNode[] = []\n\t\t\t\tlet offset = 0\n\t\t\t\tfor (const inline of current.children) {\n\t\t\t\t\tif (inline === undefined) continue\n\t\t\t\t\tconst child = children[offset]\n\t\t\t\t\tinlines.push(child !== undefined && isInlineNode(child) ? child : inline)\n\t\t\t\t\toffset += 1\n\t\t\t\t}\n\t\t\t\trebuilt = { ...current, children: inlines }\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'blockquote': {\n\t\t\t\tconst blocks: BlockNode[] = []\n\t\t\t\tlet offset = 0\n\t\t\t\tfor (const block of current.children) {\n\t\t\t\t\tif (block === undefined) continue\n\t\t\t\t\tconst child = children[offset]\n\t\t\t\t\tblocks.push(child !== undefined && isBlockNode(child) ? child : block)\n\t\t\t\t\toffset += 1\n\t\t\t\t}\n\t\t\t\trebuilt = { ...current, children: blocks }\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'listItem': {\n\t\t\t\tconst blocks: BlockNode[] = []\n\t\t\t\tlet offset = 0\n\t\t\t\tfor (const block of current.children) {\n\t\t\t\t\tif (block === undefined) continue\n\t\t\t\t\tconst child = children[offset]\n\t\t\t\t\tblocks.push(child !== undefined && isBlockNode(child) ? child : block)\n\t\t\t\t\toffset += 1\n\t\t\t\t}\n\t\t\t\trebuilt = { element: 'listItem', children: blocks }\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'emphasis':\n\t\t\tcase 'link': {\n\t\t\t\tconst inlines: InlineNode[] = []\n\t\t\t\tlet offset = 0\n\t\t\t\tfor (const inline of current.children) {\n\t\t\t\t\tif (inline === undefined) continue\n\t\t\t\t\tconst child = children[offset]\n\t\t\t\t\tinlines.push(child !== undefined && isInlineNode(child) ? child : inline)\n\t\t\t\t\toffset += 1\n\t\t\t\t}\n\t\t\t\trebuilt = { ...current, children: inlines }\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'list': {\n\t\t\t\tconst items: ListItemNode[] = []\n\t\t\t\tlet offset = 0\n\t\t\t\tfor (const item of current.items) {\n\t\t\t\t\tif (item === undefined) continue\n\t\t\t\t\tconst child = children[offset]\n\t\t\t\t\titems.push(child?.element === 'listItem' ? child : item)\n\t\t\t\t\toffset += 1\n\t\t\t\t}\n\t\t\t\trebuilt = { ...current, items }\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'table': {\n\t\t\t\tlet offset = 0\n\t\t\t\tconst header: (readonly InlineNode[])[] = []\n\t\t\t\tfor (const cell of current.header) {\n\t\t\t\t\tif (cell === undefined) continue\n\t\t\t\t\tconst inlines: InlineNode[] = []\n\t\t\t\t\tfor (const inline of cell) {\n\t\t\t\t\t\tif (inline === undefined) continue\n\t\t\t\t\t\tconst child = children[offset]\n\t\t\t\t\t\tinlines.push(child !== undefined && isInlineNode(child) ? child : inline)\n\t\t\t\t\t\toffset += 1\n\t\t\t\t\t}\n\t\t\t\t\theader.push(inlines)\n\t\t\t\t}\n\t\t\t\tconst rows: (readonly (readonly InlineNode[])[])[] = []\n\t\t\t\tfor (const row of current.rows) {\n\t\t\t\t\tif (row === undefined) continue\n\t\t\t\t\tconst cells: (readonly InlineNode[])[] = []\n\t\t\t\t\tfor (const cell of row) {\n\t\t\t\t\t\tif (cell === undefined) continue\n\t\t\t\t\t\tconst inlines: InlineNode[] = []\n\t\t\t\t\t\tfor (const inline of cell) {\n\t\t\t\t\t\t\tif (inline === undefined) continue\n\t\t\t\t\t\t\tconst child = children[offset]\n\t\t\t\t\t\t\tinlines.push(child !== undefined && isInlineNode(child) ? child : inline)\n\t\t\t\t\t\t\toffset += 1\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcells.push(inlines)\n\t\t\t\t\t}\n\t\t\t\t\trows.push(cells)\n\t\t\t\t}\n\t\t\t\trebuilt = { ...current, header, rows }\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tconst result = rewrite(rebuilt)\n\t\tlet accepted = rebuilt\n\t\tswitch (current.element) {\n\t\t\tcase 'text':\n\t\t\tcase 'emphasis':\n\t\t\tcase 'codeSpan':\n\t\t\tcase 'link':\n\t\t\t\tif (isInlineNode(result)) accepted = result\n\t\t\t\tbreak\n\t\t\tcase 'heading':\n\t\t\tcase 'paragraph':\n\t\t\tcase 'list':\n\t\t\tcase 'table':\n\t\t\tcase 'codeBlock':\n\t\t\tcase 'blockquote':\n\t\t\tcase 'thematicBreak':\n\t\t\t\tif (isBlockNode(result)) accepted = result\n\t\t\t\tbreak\n\t\t\tcase 'listItem':\n\t\t\t\tif (result.element === 'listItem') accepted = result\n\t\t\t\tbreak\n\t\t}\n\t\tvalues.push(accepted)\n\t}\n\treturn { element: 'document', children: [...document.children] }\n}\n\n/**\n * Concatenate the `value` / `code` content of every descendant text / code-span /\n * code-block node under `node`, in walk order - the plain-text projection of an AST\n * (search indexing, word counts, a text-only preview).\n *\n * @remarks\n * Total: never throws. Descent stops at {@link MAX_DEPTH} (contributes `''` past the\n * cap instead of recursing further).\n *\n * @param node - The AST node to flatten (a full document, or any sub-node)\n * @returns The concatenated text content\n *\n * @example\n * ```ts\n * flattenText({ element: 'paragraph', children: [\n * { element: 'text', value: 'a ' },\n * { element: 'codeSpan', value: 'b' },\n * ] })\n * // 'a b'\n * ```\n */\nexport function flattenText(node: MarkdownNode): string {\n\tconst stack: { readonly node: MarkdownNode; readonly depth: number }[] = [{ node, depth: 0 }]\n\tlet value = ''\n\twhile (stack.length > 0) {\n\t\tconst frame = stack.pop()\n\t\tif (frame === undefined || frame.depth >= MAX_DEPTH) continue\n\t\tconst children: MarkdownNode[] = []\n\t\tswitch (frame.node.element) {\n\t\t\tcase 'text':\n\t\t\tcase 'codeSpan':\n\t\t\t\tvalue += frame.node.value\n\t\t\t\tbreak\n\t\t\tcase 'codeBlock':\n\t\t\t\tvalue += frame.node.code\n\t\t\t\tbreak\n\t\t\tcase 'document':\n\t\t\tcase 'heading':\n\t\t\tcase 'paragraph':\n\t\t\tcase 'blockquote':\n\t\t\tcase 'listItem':\n\t\t\tcase 'emphasis':\n\t\t\tcase 'link':\n\t\t\t\tfor (const child of frame.node.children) if (child !== undefined) children.push(child)\n\t\t\t\tbreak\n\t\t\tcase 'list':\n\t\t\t\tfor (const child of frame.node.items) if (child !== undefined) children.push(child)\n\t\t\t\tbreak\n\t\t\tcase 'table':\n\t\t\t\tfor (const cell of frame.node.header)\n\t\t\t\t\tif (cell !== undefined)\n\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) children.push(child)\n\t\t\t\tfor (const row of frame.node.rows)\n\t\t\t\t\tif (row !== undefined)\n\t\t\t\t\t\tfor (const cell of row)\n\t\t\t\t\t\t\tif (cell !== undefined)\n\t\t\t\t\t\t\t\tfor (const child of cell) if (child !== undefined) children.push(child)\n\t\t\t\tbreak\n\t\t}\n\t\tfor (let index = children.length - 1; index >= 0; index -= 1) {\n\t\t\tconst child = children[index]\n\t\t\tif (child !== undefined) stack.push({ node: child, depth: frame.depth + 1 })\n\t\t}\n\t}\n\treturn value\n}\n","import type {\n\tBlockNode,\n\tInlineNode,\n\tListItemNode,\n\tListItemParts,\n\tListNode,\n\tMarkdownDocument,\n\tTableAlign,\n\tTableNode,\n} from './types.js'\nimport {\n\tcoalesceText,\n\tleadingIndent,\n\textractFence,\n\textractHeading,\n\textractListItem,\n\tscanInline,\n\tsplitLines,\n\tsplitTableRow,\n\tstartsBlock,\n\tstripQuote,\n\ttableAlignments,\n} from './helpers.js'\nimport { isBlankLine, isFenceClose, isQuote, isTableStart, isThematicBreak } from './validators.js'\nimport { MAX_DEPTH } from './constants.js'\nimport { isNonEmptyArray } from '@orkestrel/contract'\n\n/**\n * Parses a run of markdown lines into a block AST, recursing into nested\n * blockquotes, list items, and depth-capped degrade paragraphs.\n *\n * @param lines - The markdown lines to parse.\n * @param depth - The current recursion depth (blockquotes/lists increment it).\n * @returns The parsed block nodes.\n *\n * @example\n * ```ts\n * parseBlocks(['# Hi'], 0) // [{ element: 'heading', level: 1, children: [...] }]\n * ```\n */\nexport function parseBlocks(lines: readonly string[], depth: number): readonly BlockNode[] {\n\tif (depth >= MAX_DEPTH) {\n\t\treturn lines.length > 0\n\t\t\t? [{ element: 'paragraph', children: [{ element: 'text', value: lines.join('\\n') }] }]\n\t\t\t: []\n\t}\n\tconst blocks: BlockNode[] = []\n\tlet index = 0\n\twhile (index < lines.length) {\n\t\tconst line = lines[index] ?? ''\n\t\tif (isBlankLine(line)) {\n\t\t\tindex += 1\n\t\t\tcontinue\n\t\t}\n\t\tconst fence = extractFence(line)\n\t\tif (fence) {\n\t\t\tconst body: string[] = []\n\t\t\tindex += 1\n\t\t\twhile (index < lines.length && !isFenceClose(lines[index] ?? '', fence.marker)) {\n\t\t\t\tbody.push(lines[index] ?? '')\n\t\t\t\tindex += 1\n\t\t\t}\n\t\t\tindex += 1 // step past the closing fence (a no-op past EOF)\n\t\t\tblocks.push({\n\t\t\t\telement: 'codeBlock',\n\t\t\t\t...(fence.lang === undefined ? {} : { lang: fence.lang }),\n\t\t\t\tcode: body.join('\\n'),\n\t\t\t})\n\t\t\tcontinue\n\t\t}\n\t\tif (isThematicBreak(line)) {\n\t\t\tblocks.push({ element: 'thematicBreak' })\n\t\t\tindex += 1\n\t\t\tcontinue\n\t\t}\n\t\tconst heading = extractHeading(line)\n\t\tif (heading) {\n\t\t\tblocks.push({\n\t\t\t\telement: 'heading',\n\t\t\t\tlevel: heading.level,\n\t\t\t\tchildren: parseInline(heading.text),\n\t\t\t})\n\t\t\tindex += 1\n\t\t\tcontinue\n\t\t}\n\t\tif (isQuote(line)) {\n\t\t\tconst quoted: string[] = []\n\t\t\twhile (index < lines.length && isQuote(lines[index] ?? '')) {\n\t\t\t\tquoted.push(stripQuote(lines[index] ?? ''))\n\t\t\t\tindex += 1\n\t\t\t}\n\t\t\tblocks.push({ element: 'blockquote', children: parseBlocks(quoted, depth + 1) })\n\t\t\tcontinue\n\t\t}\n\t\tif (isTableStart(line, lines[index + 1])) {\n\t\t\tconst table = collectTable(lines, index)\n\t\t\tblocks.push(table.node)\n\t\t\tindex = table.next\n\t\t\tcontinue\n\t\t}\n\t\tif (extractListItem(line)) {\n\t\t\tconst list = collectList(lines, index, depth)\n\t\t\tblocks.push(list.node)\n\t\t\tindex = list.next\n\t\t\tcontinue\n\t\t}\n\t\tconst paragraph: string[] = []\n\t\twhile (\n\t\t\tindex < lines.length &&\n\t\t\t!isBlankLine(lines[index] ?? '') &&\n\t\t\t!(isNonEmptyArray(paragraph) && startsBlock(lines, index))\n\t\t) {\n\t\t\tparagraph.push((lines[index] ?? '').trim())\n\t\t\tindex += 1\n\t\t}\n\t\tblocks.push({ element: 'paragraph', children: parseInline(paragraph.join('\\n')) })\n\t}\n\treturn blocks\n}\n\n/**\n * Collects a GFM table starting at a header row, parsing the header, the\n * alignment row, and every contiguous body row that follows.\n *\n * @param lines - The markdown lines to scan.\n * @param start - The index of the header row.\n * @returns The parsed table node and the index of the first line after it.\n *\n * @example\n * ```ts\n * collectTable(['| a |', '| - |'], 0) // { node: { element: 'table', ... }, next: 2 }\n * ```\n */\nexport function collectTable(\n\tlines: readonly string[],\n\tstart: number,\n): { readonly node: TableNode; readonly next: number } {\n\tconst headerCells = splitTableRow(lines[start] ?? '')\n\tconst columns = headerCells.length\n\tconst header = headerCells.map((cell) => parseInline(cell.trim()))\n\tconst align = tableAlignments(lines[start + 1] ?? '')\n\tconst padded: TableAlign[] = []\n\tfor (let column = 0; column < columns; column += 1) padded.push(align[column] ?? 'none')\n\tconst rows: (readonly InlineNode[])[][] = []\n\tlet index = start + 2\n\twhile (\n\t\tindex < lines.length &&\n\t\t!isBlankLine(lines[index] ?? '') &&\n\t\t(lines[index] ?? '').includes('|')\n\t) {\n\t\tconst cells = splitTableRow(lines[index] ?? '')\n\t\tconst row: (readonly InlineNode[])[] = []\n\t\tfor (let column = 0; column < columns; column += 1)\n\t\t\trow.push(parseInline((cells[column] ?? '').trim()))\n\t\trows.push(row)\n\t\tindex += 1\n\t}\n\treturn { node: { element: 'table', header, rows, align: padded }, next: index }\n}\n\n/**\n * Collects a list starting at the first item, gathering sibling items at the\n * same indent/ordering and recursing into each item's own block content.\n *\n * @param lines - The markdown lines to scan.\n * @param start - The index of the first list item.\n * @param depth - The current recursion depth (each item recurses at `depth + 1`).\n * @returns The parsed list node and the index of the first line after it.\n *\n * @example\n * ```ts\n * collectList(['- item'], 0, 0) // { node: { element: 'list', ... }, next: 1 }\n * ```\n */\nexport function collectList(\n\tlines: readonly string[],\n\tstart: number,\n\tdepth: number,\n): { readonly node: ListNode; readonly next: number } {\n\tconst first = extractListItem(lines[start] ?? '')\n\tconst ordered = first?.ordered ?? false\n\tconst startOrdinal = first?.start ?? 1\n\tconst topIndent = first?.indent ?? 0\n\tconst items: ListItemNode[] = []\n\t// A single nested-item chain would otherwise rescan and slice the whole suffix\n\t// once per level before reaching the cap. Recognize that shape in one pass and\n\t// build the same bounded AST bottom-up.\n\tconst chain: ListItemParts[] = []\n\tlet nested = true\n\tfor (let cursor = start; cursor < lines.length; cursor += 1) {\n\t\tconst parsed = extractListItem(lines[cursor] ?? '')\n\t\tconst previous = chain[chain.length - 1]\n\t\tif (\n\t\t\tparsed === undefined ||\n\t\t\t(previous !== undefined && (previous.content.length > 0 || parsed.indent !== previous.marker))\n\t\t) {\n\t\t\tnested = false\n\t\t\tbreak\n\t\t}\n\t\tchain.push(parsed)\n\t}\n\tconst remaining = MAX_DEPTH - depth\n\tif (nested && remaining > 0 && chain.length > remaining) {\n\t\tconst terminal = chain[remaining - 1]\n\t\tif (terminal !== undefined) {\n\t\t\tconst source = [terminal.content]\n\t\t\tfor (let cursor = start + remaining; cursor < lines.length; cursor += 1) {\n\t\t\t\tsource.push((lines[cursor] ?? '').slice(terminal.marker))\n\t\t\t}\n\t\t\tlet children: readonly BlockNode[] = [\n\t\t\t\t{ element: 'paragraph', children: [{ element: 'text', value: source.join('\\n') }] },\n\t\t\t]\n\t\t\tlet node: ListNode | undefined\n\t\t\tfor (let cursor = remaining - 1; cursor >= 0; cursor -= 1) {\n\t\t\t\tconst parsed = chain[cursor]\n\t\t\t\tif (parsed === undefined) continue\n\t\t\t\tnode = {\n\t\t\t\t\telement: 'list',\n\t\t\t\t\tordered: parsed.ordered,\n\t\t\t\t\tstart: parsed.start,\n\t\t\t\t\titems: [{ element: 'listItem', children }],\n\t\t\t\t}\n\t\t\t\tchildren = [node]\n\t\t\t}\n\t\t\tif (node !== undefined) return { node, next: lines.length }\n\t\t}\n\t}\n\tlet index = start\n\twhile (index < lines.length) {\n\t\tconst parsed = extractListItem(lines[index] ?? '')\n\t\t// A sibling item shares the list's (top) indent + ordering; anything else stops\n\t\t// the top loop (a deeper item is a nested list, gathered as continuation below).\n\t\tif (!parsed || parsed.indent > topIndent || parsed.ordered !== ordered) break\n\t\tconst itemLines: string[] = [parsed.content]\n\t\tconst continuation = parsed.marker\n\t\tindex += 1\n\t\twhile (index < lines.length) {\n\t\t\tconst next = lines[index] ?? ''\n\t\t\tif (isBlankLine(next)) {\n\t\t\t\tconst after = lines[index + 1] ?? ''\n\t\t\t\tif (\n\t\t\t\t\tindex + 1 < lines.length &&\n\t\t\t\t\t!isBlankLine(after) &&\n\t\t\t\t\tleadingIndent(after) >= continuation\n\t\t\t\t) {\n\t\t\t\t\titemLines.push('')\n\t\t\t\t\tindex += 1\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tif (leadingIndent(next) >= continuation) {\n\t\t\t\titemLines.push(next.slice(continuation))\n\t\t\t\tindex += 1\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (extractListItem(next) || startsBlock(lines, index)) break\n\t\t\titemLines.push(next.trim()) // a lazy paragraph-continuation line\n\t\t\tindex += 1\n\t\t}\n\t\titems.push({ element: 'listItem', children: parseBlocks(itemLines, depth + 1) })\n\t}\n\treturn { node: { element: 'list', ordered, start: startOrdinal, items }, next: index }\n}\n\n/**\n * Parses a markdown string into a typed {@link MarkdownDocument} AST via the\n * block phase.\n *\n * @param markdown - The markdown source to parse.\n * @returns The parsed document.\n */\nexport function parseDocument(markdown: string): MarkdownDocument {\n\treturn { element: 'document', children: parseBlocks(splitLines(markdown), 0) }\n}\n\n/**\n * Parses inline markdown text (emphasis, code spans, links) into inline AST\n * nodes, coalescing adjacent text runs.\n *\n * @param text - The inline markdown text to parse.\n * @returns The parsed inline nodes.\n */\nexport function parseInline(text: string): readonly InlineNode[] {\n\treturn coalesceText(scanInline(text, 0, text.length))\n}\n","import {\n\tbooleanShape,\n\tintegerShape,\n\tliteralShape,\n\tobjectShape,\n\toptionalShape,\n\tstringShape,\n} from '@orkestrel/contract'\n\n// AGENTS section 14 / 4.6.1: shapers are `ContractShape` VALUES, not functions\n// or types - a JSON-Schema blueprint the compilers (factories.ts) turn into a\n// guard / parser / schema / generator in lockstep. Only the NON-recursive\n// parts of the markdown AST (types.ts) can be expressed here: a shape tree has\n// no lazy/self-referential node, so any type whose fields recurse into\n// `BlockNode` / `InlineNode` / `MarkdownNode` (EmphasisNode, LinkNode,\n// HeadingNode, ParagraphNode, ListItemNode, ListNode, TableNode,\n// BlockquoteNode, MarkdownDocument) is skipped here and stays guard-only\n// (validators.ts) via `lazyOf`.\n\n/**\n * The shape of a {@link TextNode} - a plain-text leaf inline run.\n *\n * @example\n * ```ts\n * import { createContract } from '@orkestrel/contract'\n * import { textShape } from '@src/core'\n *\n * const text = createContract(textShape)\n * text.is({ element: 'text', value: 'hi' }) // true\n * ```\n */\nexport const textShape = objectShape({\n\telement: literalShape(['text']),\n\tvalue: stringShape(),\n})\n\n/**\n * The shape of a {@link CodeSpanNode} - an inline code span (`` `code` ``).\n *\n * @example\n * ```ts\n * import { createContract } from '@orkestrel/contract'\n * import { codeSpanShape } from '@src/core'\n *\n * const codeSpan = createContract(codeSpanShape)\n * codeSpan.is({ element: 'codeSpan', value: 'const x = 1' }) // true\n * ```\n */\nexport const codeSpanShape = objectShape({\n\telement: literalShape(['codeSpan']),\n\tvalue: stringShape(),\n})\n\n/**\n * The shape of a {@link CodeBlockNode} - a fenced code block. `lang` is\n * optional (absent when the opening fence carries no info-string).\n *\n * @example\n * ```ts\n * import { createContract } from '@orkestrel/contract'\n * import { codeBlockShape } from '@src/core'\n *\n * const codeBlock = createContract(codeBlockShape)\n * codeBlock.is({ element: 'codeBlock', code: 'x' }) // true\n * codeBlock.is({ element: 'codeBlock', code: 'x', lang: 'ts' }) // true\n * ```\n */\nexport const codeBlockShape = objectShape({\n\telement: literalShape(['codeBlock']),\n\tlang: optionalShape(stringShape()),\n\tcode: stringShape(),\n})\n\n/**\n * The shape of a {@link ThematicBreakNode} - a horizontal rule. Carries no\n * fields beyond its `element` discriminant.\n *\n * @example\n * ```ts\n * import { createContract } from '@orkestrel/contract'\n * import { thematicBreakShape } from '@src/core'\n *\n * const thematicBreak = createContract(thematicBreakShape)\n * thematicBreak.is({ element: 'thematicBreak' }) // true\n * ```\n */\nexport const thematicBreakShape = objectShape({\n\telement: literalShape(['thematicBreak']),\n})\n\n/**\n * The shape of a {@link TableAlign} - the per-column GFM table alignment\n * literal.\n *\n * @example\n * ```ts\n * import { createContract } from '@orkestrel/contract'\n * import { tableAlignShape } from '@src/core'\n *\n * const tableAlign = createContract(tableAlignShape)\n * tableAlign.is('left') // true\n * tableAlign.is('center') // true\n * tableAlign.is('top') // false\n * ```\n */\nexport const tableAlignShape = literalShape(['none', 'left', 'right', 'center'])\n\n/**\n * The shape of {@link ListItemParts} - the parsed parts of a single list-item\n * line the block phase's list detector returns. Fully non-recursive (no\n * nested node fields), so every field shapes directly.\n *\n * @example\n * ```ts\n * import { createContract } from '@orkestrel/contract'\n * import { listItemPartsShape } from '@src/core'\n *\n * const listItemParts = createContract(listItemPartsShape)\n * listItemParts.is({ ordered: false, start: 1, content: 'hi', indent: 0, marker: 2 }) // true\n * ```\n */\nexport const listItemPartsShape = objectShape({\n\tordered: booleanShape(),\n\tstart: integerShape(),\n\tcontent: stringShape(),\n\tindent: integerShape(),\n\tmarker: integerShape(),\n})\n","import type {\n\tBlockNode,\n\tMarkdownDocument,\n\tMarkdownHandlers,\n\tMarkdownInterface,\n\tMarkdownNode,\n\tMarkdownRewriteHandler,\n} from './types.js'\nimport { foldNode, rewriteDocument, walkNodes } from './helpers.js'\nimport { parseDocument } from './parsers.js'\n\n/**\n * A stateful, parsed markdown document - wraps a typed {@link MarkdownDocument} AST\n * with the query (`find` / `filter` / `reduce` / iteration), rewrite (`map`), fold, and\n * streaming operations {@link MarkdownInterface} declares.\n *\n * @remarks\n * - **Construction.** Given a `string`, the constructor runs {@link parseDocument} (the\n * block phase then the inline phase) to build the AST. Given a {@link MarkdownDocument},\n * the document is adopted AS-IS and is NOT re-validated - a caller adopting an\n * untrusted value should gate it with `isMarkdownDocument` first.\n * - **Immutable.** {@link map} never mutates the stored AST - it returns a NEW `Markdown`\n * instance; the document root invariant (`element: 'document'`) always holds.\n * - **Traversal order.** {@link walk} and the `find` / `filter` / `reduce` queries built\n * on it walk the AST depth-first, pre-order, root-inclusive (via {@link walkNodes});\n * `stream` is shallow - only the document's direct block children.\n *\n * @example\n * ```ts\n * import { Markdown, isHeadingNode, renderMarkdown } from '@src/core'\n *\n * const markdown = new Markdown('# Title\\n\\nA **bold** [link](https://x.dev).')\n * const heading = markdown.find(isHeadingNode) // the HeadingNode, or undefined\n * const shouted = markdown.map((node) =>\n * node.element === 'text' ? { element: 'text', value: node.value.toUpperCase() } : node,\n * )\n * renderMarkdown(shouted.document) // '# TITLE\\n\\nA **BOLD** [LINK](https://x.dev).'\n * ```\n */\nexport class Markdown implements MarkdownInterface {\n\treadonly #document: MarkdownDocument\n\n\tconstructor(input: string | MarkdownDocument) {\n\t\tthis.#document = typeof input === 'string' ? parseDocument(input) : input\n\t}\n\n\t/** The stored {@link MarkdownDocument} AST root. */\n\tget document(): MarkdownDocument {\n\t\treturn this.#document\n\t}\n\n\t/**\n\t * THE deep traversal - a lazy, depth-first, pre-order, root-inclusive generator\n\t * over every {@link MarkdownNode} in the document. `find` / `filter` / `reduce`\n\t * all iterate this single traversal.\n\t *\n\t * @example\n\t * ```ts\n\t * for (const node of markdown.walk()) {\n\t * // every node, depth-first, pre-order, root-inclusive\n\t * }\n\t *\n\t * // also consumable by for-await - JS accepts a sync iterable in for-await\n\t * for await (const node of markdown.walk()) {\n\t * // same sequence, no separate async iterator needed\n\t * }\n\t * ```\n\t */\n\t*walk(): Generator<MarkdownNode> {\n\t\tyield* walkNodes(this.#document)\n\t}\n\n\t// Finds the first node (depth-first, pre-order) narrowed by a type guard.\n\tfind<T extends MarkdownNode>(guard: (node: MarkdownNode) => node is T): T | undefined\n\t// Finds the first node (depth-first, pre-order) matching a predicate.\n\tfind(predicate: (node: MarkdownNode) => boolean): MarkdownNode | undefined\n\tfind(predicate: (node: MarkdownNode) => boolean): MarkdownNode | undefined {\n\t\tfor (const node of this.walk()) if (predicate(node)) return node\n\t\treturn undefined\n\t}\n\n\t// Collects every node (depth-first, pre-order) narrowed by a type guard.\n\tfilter<T extends MarkdownNode>(guard: (node: MarkdownNode) => node is T): readonly T[]\n\t// Collects every node (depth-first, pre-order) matching a predicate.\n\tfilter(predicate: (node: MarkdownNode) => boolean): readonly MarkdownNode[]\n\tfilter(predicate: (node: MarkdownNode) => boolean): readonly MarkdownNode[] {\n\t\tconst out: MarkdownNode[] = []\n\t\tfor (const node of this.walk()) if (predicate(node)) out.push(node)\n\t\treturn out\n\t}\n\n\t/** Rewrites the AST bottom-up (copy-on-write) and returns a new {@link Markdown}. */\n\tmap(rewrite: MarkdownRewriteHandler): MarkdownInterface {\n\t\treturn new Markdown(rewriteDocument(this.#document, rewrite))\n\t}\n\n\t/** Folds the AST depth-first, pre-order into an accumulator. */\n\treduce<T>(callback: (accumulator: T, node: MarkdownNode) => T, initial: T): T {\n\t\tlet accumulator = initial\n\t\tfor (const node of this.walk()) accumulator = callback(accumulator, node)\n\t\treturn accumulator\n\t}\n\n\t/** Runs a total catamorphism over the document using a {@link MarkdownHandlers} table. */\n\tfold<T>(handlers: MarkdownHandlers<T>): T {\n\t\treturn foldNode(this.#document, handlers, 0)\n\t}\n\n\t/**\n\t * A web-standard {@link ReadableStream} over the document's top-level block nodes\n\t * (shallow, source order) - a fresh, pull-based source per call: one block is\n\t * enqueued per `pull`, so a slow reader's backpressure is respected. Cancellable,\n\t * async-iterable wherever the platform supports it (Node, Deno), and pipeable\n\t * through any {@link TransformStream} / {@link WritableStream}.\n\t *\n\t * @example\n\t * ```ts\n\t * // universal - works in every ReadableStream-supporting environment\n\t * const reader = markdown.stream().getReader()\n\t * for (let result = await reader.read(); !result.done; result = await reader.read()) {\n\t * console.log(result.value) // one BlockNode\n\t * }\n\t *\n\t * // Node / Deno / Firefox support async iteration of ReadableStream natively;\n\t * // other environments should use the reader loop above instead.\n\t * for await (const block of markdown.stream()) {\n\t * console.log(block)\n\t * }\n\t * ```\n\t */\n\tstream(): ReadableStream<BlockNode> {\n\t\tconst blocks = this.#document.children\n\t\tlet index = 0\n\t\treturn new ReadableStream<BlockNode>({\n\t\t\tpull(controller) {\n\t\t\t\tif (index < blocks.length) {\n\t\t\t\t\tconst block = blocks[index]\n\t\t\t\t\tif (block === undefined) {\n\t\t\t\t\t\tcontroller.close()\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tcontroller.enqueue(block)\n\t\t\t\t\tindex += 1\n\t\t\t\t} else {\n\t\t\t\t\tcontroller.close()\n\t\t\t\t}\n\t\t\t},\n\t\t})\n\t}\n}\n","import type { ContractInterface } from '@orkestrel/contract'\nimport type {\n\tCodeBlockNode,\n\tCodeSpanNode,\n\tMarkdownDocument,\n\tMarkdownInterface,\n\tTextNode,\n\tThematicBreakNode,\n} from './types.js'\nimport { createContract } from '@orkestrel/contract'\nimport { Markdown } from './Markdown.js'\nimport { codeBlockShape, codeSpanShape, textShape, thematicBreakShape } from './shapers.js'\n\n/**\n * Create a stateful markdown handle from a markdown string or an already-parsed\n * {@link MarkdownDocument} - a typed AST plus the query, rewrite, and fold operations\n * {@link MarkdownInterface} exposes.\n *\n * @remarks\n * Given a `string`, runs a block phase (headings / paragraphs / lists / GFM tables /\n * fenced code / blockquotes / thematic breaks) then an inline phase (emphasis /\n * inline code / links) to build a render-agnostic {@link MarkdownDocument}. Given a\n * {@link MarkdownDocument}, adopts it AS-IS without re-validation - gate an untrusted\n * value with `isMarkdownDocument` first. Pure + total parse (malformed markdown\n * degrades to text, never throws) and zero-dependency - a hand-written scanner, no\n * regex-only structural parse, linear-time (no ReDoS).\n *\n * @param input - A markdown string to parse, or an already-parsed {@link MarkdownDocument}\n * @returns A working {@link MarkdownInterface}\n *\n * @example\n * ```ts\n * import { createMarkdown } from '@src/core'\n *\n * const markdown = createMarkdown('# Hi\\n\\nRead the [guide](./guide.md).')\n * markdown.document.children[0] // { element: 'heading', ... }\n * ```\n */\nexport function createMarkdown(input: string | MarkdownDocument): MarkdownInterface {\n\treturn new Markdown(input)\n}\n\n/**\n * Compile the {@link textShape} into a {@link ContractInterface} for\n * {@link TextNode} - a guard, coercing parser, JSON Schema, and seeded\n * generator from one shape declaration (AGENTS §14).\n *\n * @returns A `TextNode` contract bundling `schema` / `is` / `parse` / `generate`\n *\n * @example\n * ```ts\n * import { createTextContract } from '@src/core'\n *\n * const text = createTextContract()\n * text.is({ element: 'text', value: 'hi' }) // true\n * ```\n */\nexport function createTextContract(): ContractInterface<TextNode> {\n\treturn createContract(textShape)\n}\n\n/**\n * Compile the {@link codeSpanShape} into a {@link ContractInterface} for\n * {@link CodeSpanNode} - a guard, coercing parser, JSON Schema, and seeded\n * generator from one shape declaration (AGENTS §14).\n *\n * @returns A `CodeSpanNode` contract bundling `schema` / `is` / `parse` / `generate`\n *\n * @example\n * ```ts\n * import { createCodeSpanContract } from '@src/core'\n *\n * const codeSpan = createCodeSpanContract()\n * codeSpan.is({ element: 'codeSpan', value: 'const x = 1' }) // true\n * ```\n */\nexport function createCodeSpanContract(): ContractInterface<CodeSpanNode> {\n\treturn createContract(codeSpanShape)\n}\n\n/**\n * Compile the {@link codeBlockShape} into a {@link ContractInterface} for\n * {@link CodeBlockNode} - a guard, coercing parser, JSON Schema, and seeded\n * generator from one shape declaration (AGENTS §14).\n *\n * @returns A `CodeBlockNode` contract bundling `schema` / `is` / `parse` / `generate`\n *\n * @example\n * ```ts\n * import { createCodeBlockContract } from '@src/core'\n *\n * const codeBlock = createCodeBlockContract()\n * codeBlock.is({ element: 'codeBlock', code: 'x' }) // true\n * ```\n */\nexport function createCodeBlockContract(): ContractInterface<CodeBlockNode> {\n\treturn createContract(codeBlockShape)\n}\n\n/**\n * Compile the {@link thematicBreakShape} into a {@link ContractInterface} for\n * {@link ThematicBreakNode} - a guard, coercing parser, JSON Schema, and\n * seeded generator from one shape declaration (AGENTS §14).\n *\n * @returns A `ThematicBreakNode` contract bundling `schema` / `is` / `parse` / `generate`\n *\n * @example\n * ```ts\n * import { createThematicBreakContract } from '@src/core'\n *\n * const thematicBreak = createThematicBreakContract()\n * thematicBreak.is({ element: 'thematicBreak' }) // true\n * ```\n */\nexport function createThematicBreakContract(): ContractInterface<ThematicBreakNode> {\n\treturn createContract(thematicBreakShape)\n}\n"],"mappings":";;;;;;;;;AAMA,IAAa,mCAAwC,IAAI,IAAI;CAAC;CAAQ;CAAS;CAAU;AAAK,CAAC;;;;;;;;;;AAW/F,IAAa,YAAY;;;;;;;;;;;;;;;;ACiCzB,SAAgB,aAAa,WAA4B;CACxD,OAAO,cAAc,OAAO,cAAc,OAAQ,cAAc;AACjE;;;;;;;;;;;;;;AAeA,SAAgB,YAAY,WAA4B;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