@ai-matrx/print 0.8.9 → 0.8.10

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/markdown.ts","../src/core.ts","../src/safe-html.ts","../src/markdown-css.ts","../src/directives.ts"],"sourcesContent":["/**\n * @ai-matrx/print/markdown — the SHIPPED DEFAULT markdown→HTML converter and\n * print stylesheet.\n *\n * Why this entry exists: `markdownToPdfBlob` used to declare its converter and\n * its stylesheet as REQUIRED injected ports (\"bring your own converter +\n * stylesheet\"). That is the exact failure THE ALL-INCLUSIVE LAW names — every\n * host had to build the hard half itself, and both hosts that tried ended up\n * with a different converter, a different stylesheet, and a different set of\n * bugs. The package now ships a complete, working default for both ports; the\n * injection seam survives as the OVERRIDE path, never as a prerequisite.\n *\n * Two skins, one vocabulary:\n * • \"document\" — `markdownToHtml` emits `.matrx-*`-classed HTML (tables,\n * nested lists, images, links, code, FAQ blocks, flashcards) and\n * `MARKDOWN_DOCUMENT_CSS` styles it. This is the PDF/publish/WordPress\n * lane.\n * • \"article\" — `markdownToArticleHtml` emits bare semantic tags and\n * `MARKDOWN_ARTICLE_CSS` gives them the serif AI-response look. This is\n * the print-window lane.\n *\n * Nothing here touches `window`/`document` at import time, and nothing here is\n * heavy — but it IS ~20KB of CSS, so `markdownToPdfBlob` reaches it through a\n * lazy `import(\"./markdown\")` and a consumer that never prints markdown pays\n * nothing.\n *\n * NOTHING FAILS SILENTLY: every case where the converter drops input it cannot\n * represent (a malformed flashcard, an empty document) is reported through the\n * optional `onNotice` sink with a concrete remedy, instead of vanishing.\n */\n\nimport { openPrintWindow, type PrintOutcome } from \"./core\";\nimport { escapeHtml } from \"@ai-matrx/kit/html-escape\";\nimport { findTableEnd, rowCells, tableStartsAt, unescapeCellPipes } from \"@ai-matrx/content-ir/source\";\nimport { PRINT_HTML_SCHEMA, sanitizePrintHtml } from \"./safe-html\";\nimport {\n MARKDOWN_ARTICLE_CSS,\n MARKDOWN_ARTICLE_TOKENS_CSS,\n MARKDOWN_DOCUMENT_CSS,\n MARKDOWN_DOCUMENT_TOKENS_CSS,\n MARKDOWN_PAGE_CSS,\n MARKDOWN_PAGE_PLAIN_CSS,\n MARKDOWN_SHARED_CSS,\n} from \"./markdown-css\";\nimport {\n PAGE_BREAK_CLASS,\n PAGE_BREAK_LABEL,\n PAGE_BREAK_MARKDOWN,\n isBibliographyLine,\n isBreakLine,\n isPageBreakLine,\n isTocLine,\n splitAtPageBreaks,\n} from \"./directives\";\n\nexport {\n MARKDOWN_ARTICLE_CSS,\n MARKDOWN_ARTICLE_TOKENS_CSS,\n MARKDOWN_DOCUMENT_CSS,\n MARKDOWN_DOCUMENT_TOKENS_CSS,\n MARKDOWN_PAGE_CSS,\n MARKDOWN_SHARED_CSS,\n PAGE_BREAK_CLASS,\n PAGE_BREAK_MARKDOWN,\n isPageBreakLine,\n splitAtPageBreaks,\n};\n\n/** Which shipped look to render markdown in. */\nexport type MarkdownSkin = \"document\" | \"article\";\n\n/**\n * A thing the converter could not represent, with the remedy. Announced, never\n * swallowed — a dropped card that says nothing is indistinguishable from a card\n * the author never wrote.\n */\nexport interface MarkdownNotice {\n code: \"flashcard-malformed\" | \"empty-output\" | \"html-stripped\";\n message: string;\n /** What the caller (or the author of the markdown) should do about it. */\n remedy: string;\n}\n\nexport interface MarkdownToHtmlOptions {\n /** Keep `<thinking>` / `<think>` / `<reasoning>` blocks. Default: false. */\n includeThinking?: boolean;\n /** Where dropped/degraded content is announced. */\n onNotice?: (notice: MarkdownNotice) => void;\n}\n\n// ─── thinking-block stripping ────────────────────────────────────────────────\n\n/**\n * Strip `<thinking>` / `<think>` / `<reasoning>` blocks from model output.\n *\n * All three tags are treated as equivalent — a host that handled only\n * `<thinking>` leaked raw reasoning into printed documents the moment a model\n * switched tag names, which is exactly the bug this package exists to stop\n * being re-solved per app.\n */\nexport function removeThinkingContent(content: string): string {\n if (!content) return \"\";\n\n // A hidden section leaves the paragraph structure around it intact: when it\n // sat between blank lines (its own paragraph), the text on either side stays\n // two paragraphs; only a section inside a paragraph collapses to a line\n // break. Replacing every section with one \"\\n\" merged two stored paragraphs\n // into one on screen (verify-RC-B5 round 3 F6).\n const hide = (_match: string, before: string, after: string) =>\n before.length >= 2 || after.length >= 2 ? \"\\n\\n\" : \"\\n\";\n let result = content\n .replace(/(\\n*)<thinking>[\\s\\S]*?<\\/thinking>(\\n*)/gi, hide)\n .replace(/(\\n*)<think>[\\s\\S]*?<\\/think>(\\n*)/gi, hide)\n .replace(/(\\n*)<reasoning>[\\s\\S]*?<\\/reasoning>(\\n*)/gi, hide);\n\n // 3+ newlines collapse to 2 — intentional paragraph breaks survive.\n result = result.replace(/\\n{3,}/g, \"\\n\\n\");\n return result.trim();\n}\n\n/** Does this content carry any reasoning block? */\nexport function hasThinkingContent(content: string): boolean {\n if (!content) return false;\n return /<thinking>|<think>|<reasoning>/i.test(content);\n}\n\n// ─── shared machinery: ONE pre-pass, ONE table/list/rule grammar ────────────\n//\n// Both skins used to carry their own table parser, their own list builder,\n// their own rule regex, and their own (or no) code-fence handling — and they\n// had drifted: the article skin had no nested lists, the document skin ran the\n// emphasis pass over code, neither understood a page break, and both pasted an\n// `<artifact>`'s raw HTML (its <html>, <body> and <script>) straight into the\n// host page. Everything below is shared; a skin supplies only class names and\n// the HTML for a code block / flashcard deck.\n\n// Private-use delimiters: they cannot collide with author text (the input is\n// scrubbed of them first) and no markdown pass treats them as syntax.\nconst TOKEN_OPEN = \"\\uE000\";\nconst TOKEN_CLOSE = \"\\uE001\";\nconst BLOCK_TOKEN = (i: number): string => `${TOKEN_OPEN}B${i}${TOKEN_CLOSE}`;\nconst INLINE_TOKEN = (i: number): string => `${TOKEN_OPEN}I${i}${TOKEN_CLOSE}`;\nconst TOKEN_RE = /\\uE000([BI])(\\d+)\\uE001/g;\nconst PARAGRAPH_WRAPPED_BLOCK_RE = /<p[^>]*>\\s*(\\uE000B\\d+\\uE001)\\s*<\\/p>/g;\n\n/** Converted HTML parked behind a placeholder so later passes cannot touch it. */\nclass Stash {\n private readonly items: string[] = [];\n\n block(html: string): string {\n return BLOCK_TOKEN(this.items.push(html) - 1);\n }\n\n inline(html: string): string {\n return INLINE_TOKEN(this.items.push(html) - 1);\n }\n\n restore(html: string): string {\n // Items can hold tokens of their own (inline code inside a link), so\n // restore until nothing is left — bounded, since items never self-nest.\n let out = html;\n for (let pass = 0; pass < 8 && out.includes(TOKEN_OPEN); pass++) {\n out = out\n .replace(PARAGRAPH_WRAPPED_BLOCK_RE, \"$1\")\n .replace(TOKEN_RE, (_m: string, _k: string, i: string) => this.items[Number(i)] ?? \"\");\n }\n return out;\n }\n}\n\ninterface SkinGrammar {\n skin: MarkdownSkin;\n table: string;\n thead: string;\n tbody: string;\n tr: string;\n th: string;\n td: string;\n ul: string;\n ol: string;\n ulNested: string;\n olNested: string;\n li: string;\n hr: string;\n del: string;\n strong: string;\n em: string;\n inlineCode: string;\n}\n\nconst DOCUMENT_GRAMMAR: SkinGrammar = {\n skin: \"document\",\n table: \"matrx-table\",\n thead: \"matrx-table-head\",\n tbody: \"matrx-table-body\",\n tr: \"matrx-table-row\",\n th: \"matrx-table-header\",\n td: \"matrx-table-cell\",\n ul: \"matrx-list matrx-bullet-list\",\n ol: \"matrx-list matrx-numbered-list\",\n ulNested: \"matrx-list matrx-bullet-list matrx-nested-list\",\n olNested: \"matrx-list matrx-numbered-list matrx-nested-list\",\n li: \"matrx-list-item\",\n hr: \"matrx-hr\",\n del: \"matrx-del\",\n strong: \"matrx-strong\",\n em: \"matrx-em\",\n inlineCode: \"matrx-inline-code\",\n};\n\nconst ARTICLE_GRAMMAR: SkinGrammar = {\n skin: \"article\",\n table: \"print-table\",\n thead: \"\",\n tbody: \"\",\n tr: \"\",\n th: \"\",\n td: \"\",\n ul: \"\",\n ol: \"\",\n ulNested: \"\",\n olNested: \"\",\n li: \"\",\n hr: \"\",\n del: \"\",\n strong: \"\",\n em: \"\",\n inlineCode: \"inline-code\",\n};\n\nconst cls = (...names: string[]): string => {\n const joined = names.filter(Boolean).join(\" \");\n return joined ? ` class=\"${joined}\"` : \"\";\n};\n\n/** The rendered page break — identical markup in both skins. */\nconst PAGE_BREAK_HTML = `<div class=\"${PAGE_BREAK_CLASS}\" role=\"separator\" aria-label=\"${PAGE_BREAK_LABEL}\" data-label=\"${PAGE_BREAK_LABEL}\"></div>`;\n\nfunction codeBlockHtml(g: SkinGrammar, code: string, language: string): string {\n const body = escapeHtml(code.replace(/\\n$/, \"\"));\n const lang = language.trim();\n if (g.skin === \"article\") {\n const label = lang ? `<span class=\"code-lang\">${escapeHtml(lang)}</span>` : \"\";\n return `<div class=\"code-block-wrapper\">${label}<pre class=\"code-block\"><code>${body}</code></pre></div>`;\n }\n const dataLang = lang ? ` data-language=\"${escapeHtml(lang)}\"` : \"\";\n return `<pre class=\"matrx-code-block\"${dataLang}><code class=\"matrx-code\">${body}</code></pre>`;\n}\n\n// ── artifacts ───────────────────────────────────────────────────────────────\n\n/** Artifact types whose body is source code, printed as its source. */\nconst CODE_ARTIFACT_LANGUAGE: Readonly<Record<string, string>> = {\n html: \"html\",\n react: \"tsx\",\n svg: \"svg\",\n mermaid: \"mermaid\",\n diff: \"diff\",\n iframe: \"html\",\n code: \"\",\n};\n\nconst ARTIFACT_TYPE_LABEL: Readonly<Record<string, string>> = {\n html: \"HTML\",\n svg: \"SVG\",\n react: \"React\",\n iframe: \"Embed\",\n};\n\nfunction parseTagAttributes(tag: string): Record<string, string> {\n const attrs: Record<string, string> = {};\n for (const m of tag.matchAll(/([a-zA-Z_][\\w-]*)\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)')/g)) {\n attrs[(m[1] as string).toLowerCase()] = m[2] ?? m[3] ?? \"\";\n }\n return attrs;\n}\n\nfunction artifactLabel(type: string): string {\n if (!type) return \"Artifact\";\n return (\n ARTIFACT_TYPE_LABEL[type] ??\n type.replace(/[-_]+/g, \" \").replace(/\\b\\w/g, (c) => c.toUpperCase())\n );\n}\n\n/**\n * `<artifact …>body</artifact>` envelopes as plain markdown — the SAME rules the\n * skins use for their titled panels, for pipelines that parse markdown (the\n * document writer): source-code types and JSON bodies become fenced code;\n * every other body (tables, checklists, notes) is markdown and is kept as is.\n * Fenced code is never touched.\n */\nexport function unwrapArtifactsToMarkdown(markdown: string): string {\n if (!/<artifact\\b/i.test(markdown)) return markdown;\n return markdown\n .split(/(^[ \\t]*(?:`{3,}|~{3,})[\\s\\S]*?^[ \\t]*(?:`{3,}|~{3,})[ \\t]*$)/m)\n .map((part, i) =>\n i % 2 === 1\n ? part\n : part.replace(/<artifact\\b((?:[^>\"']|\"[^\"]*\"|'[^']*')*?)>([\\s\\S]*?)<\\/artifact>/gi, (_m, tag: string, body: string) => {\n const attrs = parseTagAttributes(tag);\n const type = (attrs.type ?? \"\").toLowerCase();\n const trimmed = body.replace(/^\\n+|\\n+$/g, \"\");\n if (!trimmed.trim()) return \"\";\n if (/^\\s*(`{3,}|~{3,})/.test(trimmed)) return `\\n\\n${trimmed}\\n\\n`;\n if (type in CODE_ARTIFACT_LANGUAGE) {\n const lang = CODE_ARTIFACT_LANGUAGE[type] || attrs.language || attrs.lang || \"\";\n return `\\n\\n\\`\\`\\`\\`${lang}\\n${trimmed}\\n\\`\\`\\`\\`\\n\\n`;\n }\n if (looksLikeJson(trimmed)) return `\\n\\n\\`\\`\\`\\`json\\n${JSON.stringify(JSON.parse(trimmed), null, 2)}\\n\\`\\`\\`\\`\\n\\n`;\n return `\\n\\n${trimmed}\\n\\n`;\n }),\n )\n .join(\"\");\n}\n\nfunction looksLikeJson(body: string): boolean {\n const t = body.trim();\n if (!/^[[{]/.test(t)) return false;\n try {\n JSON.parse(t);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * An `<artifact type id version title>body</artifact>` block, rendered as a\n * titled panel. Source-code artifacts (html, react, svg, mermaid, diff, code)\n * and JSON bodies print as escaped source — never as live markup, which is\n * what used to inject a whole `<html>…<script>` document into the host page.\n * Everything else (checklists, flashcards, research, notes) is markdown and is\n * converted in the same skin.\n */\nfunction artifactHtml(\n g: SkinGrammar,\n attrs: Record<string, string>,\n body: string | null,\n ctx: ConvertContext,\n): string {\n const type = (attrs.type ?? \"\").toLowerCase();\n const title = attrs.title?.trim() ?? \"\";\n const header = `<div class=\"matrx-artifact-header\"><span class=\"matrx-artifact-kind\">${escapeHtml(\n artifactLabel(type),\n )}</span>${title ? `<span class=\"matrx-artifact-title\">${escapeHtml(title)}</span>` : \"\"}</div>`;\n\n let inner: string;\n const trimmed = (body ?? \"\").replace(/^\\n+|\\n+$/g, \"\");\n if (body === null || !trimmed.trim()) {\n inner = `<p class=\"matrx-artifact-empty\">Saved artifact — open it in AI Matrx to view its content.</p>`;\n } else if (/^\\s*(`{3,}|~{3,})/.test(trimmed)) {\n inner = convertBody(g.skin, trimmed, ctx);\n } else if (type in CODE_ARTIFACT_LANGUAGE) {\n inner = codeBlockHtml(g, trimmed, CODE_ARTIFACT_LANGUAGE[type] || attrs.language || attrs.lang || \"\");\n } else if (looksLikeJson(trimmed)) {\n inner = codeBlockHtml(g, JSON.stringify(JSON.parse(trimmed), null, 2), \"json\");\n } else {\n inner = convertBody(g.skin, trimmed, ctx);\n }\n\n return `<section class=\"matrx-artifact\" data-artifact-type=\"${escapeHtml(type || \"artifact\")}\">${header}<div class=\"matrx-artifact-body\">${inner}</div></section>`;\n}\n\n// ── flashcards ──────────────────────────────────────────────────────────────\n\ninterface ParsedCard {\n front: string;\n back: string;\n}\n\nfunction parseFlashcards(content: string, notice: MarkdownToHtmlOptions[\"onNotice\"]): ParsedCard[] {\n const cards: ParsedCard[] = [];\n for (const card of content.split(/\\n*---\\n*/g).map((c) => c.trim()).filter(Boolean)) {\n const front = card.match(/Front:\\s*(.+?)(?=\\n|$)/i)?.[1]?.trim();\n const back = card.match(/Back:\\s*([\\s\\S]+?)$/i)?.[1]?.trim();\n if (!front || !back) {\n // A card that silently disappears from a printed deck is a defect the\n // printer can see and the author cannot.\n notice?.({\n code: \"flashcard-malformed\",\n message: `A flashcard was skipped: it is missing a ${front ? \"Back:\" : \"Front:\"} line.`,\n remedy:\n 'Every card inside <flashcards> needs both \"Front: …\" and \"Back: …\", separated from the next card by ---.',\n });\n continue;\n }\n cards.push({ front, back });\n }\n return cards;\n}\n\nfunction flashcardsHtml(g: SkinGrammar, cards: ParsedCard[], ctx: ConvertContext): string {\n if (g.skin === \"article\") {\n // Paper cannot flip: print the deck as question / answer pairs.\n return `<div class=\"matrx-flashcards-print\">${cards\n .map(\n (c, i) =>\n `<div class=\"matrx-fc\"><div class=\"matrx-fc-front\"><span class=\"matrx-fc-num\">${\n i + 1\n }</span>${c.front}</div><div class=\"matrx-fc-back\">${c.back}</div></div>`,\n )\n .join(\"\")}</div>`;\n }\n let out = '<div class=\"matrx-flashcards-container\">\\n';\n for (const { front, back } of cards) {\n ctx.cardIndex++;\n const cardId = `card${ctx.cardIndex}`;\n out += ` <div class=\"matrx-flashcard\">\n <input type=\"checkbox\" class=\"matrx-flashcard-input\" id=\"${cardId}\">\n <label for=\"${cardId}\" class=\"matrx-flashcard-label\"></label>\n <div class=\"matrx-flashcard-inner\">\n <div class=\"matrx-flashcard-front\">\n <div class=\"matrx-flashcard-content\">\n <strong>${front}</strong>\n </div>\n <span class=\"matrx-flashcard-indicator\">CLICK TO FLIP</span>\n </div>\n <div class=\"matrx-flashcard-back\">\n <div class=\"matrx-flashcard-content\">\n ${back}\n </div>\n <span class=\"matrx-flashcard-indicator\">CLICK TO FLIP</span>\n </div>\n </div>\n </div>\n\n`;\n }\n return `${out}</div>\\n`;\n}\n\n// ── the pre-pass ────────────────────────────────────────────────────────────\n\ninterface ConvertContext {\n options: MarkdownToHtmlOptions;\n depth: number;\n cardIndex: number;\n strippedAnnounced: boolean;\n}\n\nconst FENCE_OPEN = /^(\\s*)(`{3,}|~{3,})\\s*([^\\s`]*)[^`]*$/;\n\n/**\n * Pull every region the markdown passes must not touch out of the text:\n * fenced code, `<artifact>` blocks, page-break directives, `<flashcards>`,\n * inline code — and remove what must never reach a printed page (scripts,\n * styles, a document shell, HTML comments). Returns the text with\n * placeholders; `stash.restore` puts the finished HTML back.\n */\nfunction protectRegions(markdown: string, g: SkinGrammar, stash: Stash, ctx: ConvertContext): string {\n const lines = markdown.split(/\\r?\\n/);\n const out: string[] = [];\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i] as string;\n\n // Fenced code (``` or ~~~, any indent, unclosed = to the end).\n const fence = FENCE_OPEN.exec(line);\n if (fence) {\n const marker = fence[2] as string;\n const code: string[] = [];\n let j = i + 1;\n for (; j < lines.length; j++) {\n const close = /^\\s*(`{3,}|~{3,})\\s*$/.exec(lines[j] as string);\n if (close && (close[1] as string)[0] === marker[0] && (close[1] as string).length >= marker.length) break;\n code.push(lines[j] as string);\n }\n const indent = (fence[1] as string).length;\n const dedented = code.map((l) => l.slice(Math.min(indent, l.length - l.trimStart().length)));\n out.push(stash.block(codeBlockHtml(g, dedented.join(\"\\n\"), fence[3] ?? \"\")));\n i = j;\n continue;\n }\n\n if (isBreakLine(line)) {\n out.push(stash.block(PAGE_BREAK_HTML));\n continue;\n }\n // Placement directives only mean something to the document pipeline\n // (@ai-matrx/print/document); a skin never prints them as literal text.\n if (isTocLine(line) || isBibliographyLine(line)) continue;\n\n // <artifact …>body</artifact> — the canonical materialized wire form.\n const open = /^\\s*<artifact\\b((?:[^>\"']|\"[^\"]*\"|'[^']*')*?)(\\/?)>(.*)$/i.exec(line);\n if (open) {\n const attrs = parseTagAttributes(open[1] ?? \"\");\n if (open[2] === \"/\") {\n out.push(stash.block(artifactHtml(g, attrs, null, ctx)));\n if (open[3]?.trim()) out.push(open[3]);\n continue;\n }\n const bodyLines: string[] = [];\n let rest = open[3] ?? \"\";\n let after = \"\";\n let j = i;\n let inFence: string | null = null;\n for (;;) {\n const closeAt = inFence ? -1 : rest.search(/<\\/artifact\\s*>/i);\n if (closeAt >= 0) {\n bodyLines.push(rest.slice(0, closeAt));\n after = rest.slice(closeAt).replace(/^<\\/artifact\\s*>/i, \"\");\n break;\n }\n bodyLines.push(rest);\n const f = /^\\s*(`{3,}|~{3,})/.exec(rest);\n if (f) {\n const m = f[1] as string;\n if (inFence === null) inFence = m;\n else if (m[0] === inFence[0] && m.length >= inFence.length) inFence = null;\n }\n j++;\n if (j >= lines.length) break;\n rest = lines[j] as string;\n }\n const html =\n ctx.depth >= 3\n ? codeBlockHtml(g, bodyLines.join(\"\\n\"), \"\")\n : artifactHtml(g, attrs, bodyLines.join(\"\\n\"), { ...ctx, depth: ctx.depth + 1 });\n out.push(stash.block(html));\n if (after.trim()) out.push(after);\n i = j;\n continue;\n }\n\n out.push(line);\n }\n\n let text = out.join(\"\\n\");\n\n // Inline code FIRST: prose about HTML (\"put it in a `<script>` tag\") must\n // reach the page as code, not be read as markup by the passes below.\n text = text.replace(/`([^`\\n]+)`/g, (_m: string, code: string) =>\n stash.inline(`<code${cls(g.inlineCode)}>${escapeHtml(code)}</code>`),\n );\n\n // Comments are invisible by definition — page-break comments were already\n // taken above, so what remains is safe to drop without a notice.\n text = text.replace(/<!--[\\s\\S]*?-->/g, \"\");\n\n // A printed page and a published HTML page are not a place to run someone\n // else's script or restyle the host. Paired regions go whole; a stray\n // opening/closing tag goes alone (never \"everything to the end\"). Repeat\n // until stable so a split `<scr<script></script>ipt>` cannot reassemble.\n const before = text;\n for (let pass = 0; pass < 8; pass++) {\n const next = text\n .replace(/<(script|style|head)\\b[^>]*>[\\s\\S]*?<\\/\\1\\s*>/gi, \"\")\n .replace(/<\\/?(?:script|style|head|html|body)\\b[^>]*>/gi, \"\")\n .replace(/<!DOCTYPE[^>]*>/gi, \"\");\n if (next === text) break;\n text = next;\n }\n text = sanitizeRawTags(text);\n // The allow-list (`./safe-html`) is what actually guards the output; this\n // only decides whether the author is told something of theirs was dropped.\n if ((text !== before || hasDisallowedTag(text)) && !ctx.strippedAnnounced) {\n ctx.strippedAnnounced = true;\n ctx.options.onNotice?.({\n code: \"html-stripped\",\n message:\n \"Markup that is not on the safe list (a <script>, <style>, <iframe>, <form>, <object>/<embed>, <meta>, <link>, an on… event handler, inline style, or a javascript: URL) was removed from the rendered copy.\",\n remedy:\n 'To show a full HTML page, put it in an ```html fence or an <artifact type=\"html\"> block — it is printed as its source.',\n });\n }\n\n // Flashcard decks — behind placeholders so no markdown pass re-processes them.\n text = text.replace(/<flashcards>([\\s\\S]*?)<\\/flashcards>/gi, (_m: string, content: string) => {\n const cards = parseFlashcards(content, ctx.options.onNotice);\n return cards.length ? `\\n${stash.block(flashcardsHtml(g, cards, ctx))}\\n` : \"\";\n });\n\n return text;\n}\n\nconst ALLOWED_TAGS = new Set(PRINT_HTML_SCHEMA.tagNames ?? []);\n\n/** A raw tag the allow-list will drop (our own `<flashcards>` island excepted). */\nfunction hasDisallowedTag(text: string): boolean {\n for (const m of text.matchAll(/<\\/?([a-zA-Z][\\w:-]*)/g)) {\n const tag = (m[1] as string).toLowerCase();\n if (tag !== \"flashcards\" && !ALLOWED_TAGS.has(tag)) return true;\n }\n return false;\n}\n\nconst URL_ATTRS = new Set([\"href\", \"src\", \"action\", \"formaction\", \"xlink:href\", \"poster\", \"background\"]);\n\nfunction decodeForSchemeCheck(value: string): string {\n return value\n .replace(/&#x([0-9a-f]+);?/gi, (_m: string, h: string) => String.fromCharCode(parseInt(h, 16)))\n .replace(/&#(\\d+);?/g, (_m: string, d: string) => String.fromCharCode(Number(d)))\n .replace(/&colon;/gi, \":\")\n .replace(/[\\u0000-\\u0020]+/g, \"\")\n .toLowerCase();\n}\n\n/**\n * Author raw HTML survives (the document skin feeds WordPress), but never with\n * an `on…` handler, a `srcdoc`, or a script-scheme URL — entity- and\n * whitespace-obfuscated forms included.\n */\nfunction sanitizeRawTags(text: string): string {\n return text.replace(\n /<([a-zA-Z][\\w:-]*)((?:[^>\"']|\"[^\"]*\"|'[^']*')*)>/g,\n (whole: string, tag: string, rawAttrs: string) => {\n if (!/[=\\s]/.test(rawAttrs)) return whole;\n let changed = false;\n const attrs = rawAttrs.replace(\n /(\\s+)([^\\s\"'=<>/]+)(\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'>]+)))?/g,\n (m: string, _sp: string, name: string, _eq: string, dq?: string, sq?: string, bare?: string) => {\n const lower = name.toLowerCase();\n if (lower.startsWith(\"on\") || lower === \"srcdoc\") {\n changed = true;\n return \"\";\n }\n if (URL_ATTRS.has(lower)) {\n const value = decodeForSchemeCheck(dq ?? sq ?? bare ?? \"\");\n if (/^(?:javascript|vbscript):|^data:text\\/html/.test(value)) {\n changed = true;\n return ` ${name}=\"#\"`;\n }\n }\n return m;\n },\n );\n return changed ? `<${tag}${attrs}>` : whole;\n },\n );\n}\n\n/** A URL that can go in an attribute: no script schemes, no attribute breakout. */\nfunction safeUrl(url: string): string {\n const u = url.trim();\n if (/^(?:javascript|vbscript):|^data:text\\/html/.test(decodeForSchemeCheck(u))) return \"#\";\n return u.replace(/\"/g, \"%22\");\n}\n\n/**\n * Bold / italic / strikethrough, shared by both skins. Underscores follow the\n * CommonMark intraword rule — `snake_case_name` stays literal.\n */\nfunction convertEmphasis(html: string, g: SkinGrammar): string {\n const strong = `<strong${cls(g.strong)}>`;\n const em = `<em${cls(g.em)}>`;\n return html\n .replace(/\\*\\*\\*(?!\\s)(.+?)(?<!\\s)\\*\\*\\*/g, `${strong}${em}$1</em></strong>`)\n .replace(/\\*\\*(?!\\s)(.+?)(?<!\\s)\\*\\*/g, `${strong}$1</strong>`)\n .replace(/(?<![\\w*])\\*(?![\\s*])(.+?)(?<![\\s*])\\*(?![\\w*])/g, `${em}$1</em>`)\n .replace(/(?<![\\w_])___(?!\\s)(.+?)(?<!\\s)___(?![\\w_])/g, `${strong}${em}$1</em></strong>`)\n .replace(/(?<![\\w_])__(?!\\s)(.+?)(?<!\\s)__(?![\\w_])/g, `${strong}$1</strong>`)\n .replace(/(?<![\\w_])_(?![\\s_])(.+?)(?<![\\s_])_(?![\\w_])/g, `${em}$1</em>`)\n .replace(/~~(?!\\s)(.+?)(?<!\\s)~~/g, `<del${cls(g.del)}>$1</del>`);\n}\n\n/** `[text](url)` / `![alt](url \"title\")` with one level of parentheses in the URL. */\nconst LINK_URL = String.raw`((?:[^()\\s]|\\([^()\\s]*\\))+)(?:\\s+\"[^\"]*\")?`;\nconst IMAGE_RE = new RegExp(String.raw`!\\[([^\\]]*)\\]\\(` + LINK_URL + String.raw`\\)`, \"g\");\nconst LINK_RE = new RegExp(String.raw`\\[([^\\]]+)\\]\\(` + LINK_URL + String.raw`\\)`, \"g\");\n\n/** `***` accent rule, `#===` heavy rule, `---` / `___` plain rule. */\nfunction convertRules(html: string, g: SkinGrammar): string {\n return html\n .replace(/^\\s{0,3}#\\s*={3,}\\s*$/gm, `<hr${cls(g.hr, \"matrx-hr-heavy\")}>`)\n .replace(/^\\s{0,3}\\*(?:\\s*\\*){2,}\\s*$/gm, `<hr${cls(g.hr, \"matrx-hr-accent\")}>`)\n .replace(/^\\s{0,3}(?:-\\s*){3,}$/gm, `<hr${cls(g.hr)}>`)\n .replace(/^\\s{0,3}(?:_\\s*){3,}$/gm, `<hr${cls(g.hr)}>`);\n}\n\nfunction cellAlign(separator: string): string {\n const s = separator.trim();\n const left = s.startsWith(\":\");\n const right = s.endsWith(\":\");\n if (left && right) return ' style=\"text-align:center\"';\n if (right) return ' style=\"text-align:right\"';\n return \"\";\n}\n\n/**\n * GFM tables by THE rule (@ai-matrx/content-ir/source — the same rule chat,\n * the editor and the server read tables by): edge pipes optional, `\\|` stays in\n * its cell and prints as `|`, a line that starts another block ends the table,\n * every row printed at the header's width (empty cells kept — columns never\n * shift), `:---:` alignment honoured.\n */\nfunction convertTables(html: string, g: SkinGrammar): string {\n const lines = html.split(\"\\n\");\n const out: string[] = [];\n for (let i = 0; i < lines.length; i += 1) {\n if (!tableStartsAt(lines, i)) {\n out.push(lines[i] ?? \"\");\n continue;\n }\n const end = findTableEnd(lines, i);\n const cellsOf = (line: string) => rowCells(line).map(unescapeCellPipes);\n const headers = cellsOf(lines[i] ?? \"\");\n const aligns = rowCells(lines[i + 1] ?? \"\").map(cellAlign);\n const rows = lines.slice(i + 2, end).map((line) => {\n const cells = cellsOf(line);\n return headers.map((_h, k) => cells[k] ?? \"\");\n });\n\n let t = `<table${cls(g.table)}>\\n<thead${cls(g.thead)}>\\n<tr${cls(g.tr)}>\\n`;\n headers.forEach((h, k) => {\n t += `<th${cls(g.th)}${aligns[k] ?? \"\"}>${h}</th>\\n`;\n });\n t += \"</tr>\\n</thead>\\n\";\n if (rows.length > 0) {\n t += `<tbody${cls(g.tbody)}>\\n`;\n for (const row of rows) {\n t += `<tr${cls(g.tr)}>\\n`;\n row.forEach((c, k) => {\n t += `<td${cls(g.td)}${aligns[k] ?? \"\"}>${c}</td>\\n`;\n });\n t += \"</tr>\\n\";\n }\n t += \"</tbody>\\n\";\n }\n out.push(`${t}</table>`);\n i = end - 1;\n }\n return out.join(\"\\n\");\n}\n\ninterface OpenList {\n type: \"ul\" | \"ol\";\n indent: number;\n}\n\n/** Nested ordered/bullet lists — indentation-driven open/close bookkeeping. */\nfunction convertLists(html: string, g: SkinGrammar): string {\n const lines = html.split(\"\\n\");\n let processed = \"\";\n const listStack: OpenList[] = [];\n let lastListItem: \"\" | \"ul\" | \"ol\" = \"\";\n const li = `<li${cls(g.li)}>`;\n\n const top = (): OpenList | undefined => listStack[listStack.length - 1];\n const openTag = (type: \"ul\" | \"ol\", nested: boolean): string =>\n type === \"ol\"\n ? `<ol${cls(nested ? g.olNested : g.ol)}>\\n`\n : `<ul${cls(nested ? g.ulNested : g.ul)}>\\n`;\n\n const popOne = (): void => {\n if (lastListItem) {\n processed += \"</li>\\n\";\n lastListItem = \"\";\n }\n const closing = listStack.pop();\n if (!closing) return;\n processed += closing.type === \"ol\" ? \"</ol>\\n\" : \"</ul>\\n\";\n if (listStack.length > 0) processed += \"</li>\\n\";\n };\n\n const closeDeeperThan = (indent: number): void => {\n while (listStack.length > 0 && (top() as OpenList).indent > indent) popOne();\n };\n\n for (const line of lines) {\n const numbered = line.match(/^(\\s*)(\\d+)[.)]\\s+(.+)$/);\n const bullet = numbered ? null : line.match(/^(\\s*)[*\\-+]\\s+(.+)$/);\n if (numbered || bullet) {\n const type: \"ul\" | \"ol\" = numbered ? \"ol\" : \"ul\";\n const indent = ((numbered ?? bullet) as RegExpMatchArray)[1]?.length ?? 0;\n const content = (numbered ? numbered[3] : (bullet as RegExpMatchArray)[2]) ?? \"\";\n const current = top();\n\n if (current && indent > current.indent) {\n processed += `\\n${openTag(type, true)}`;\n listStack.push({ type, indent });\n } else {\n closeDeeperThan(indent);\n if (lastListItem && top()?.indent === indent) processed += \"</li>\\n\";\n const now = top();\n if (now && now.indent === indent && now.type !== type) {\n // Same depth, other list type: close the old list, open the new one.\n const closing = listStack.pop() as OpenList;\n processed += closing.type === \"ol\" ? \"</ol>\\n\" : \"</ul>\\n\";\n }\n const after = top();\n if (!after || after.indent !== indent || after.type !== type) {\n processed += openTag(type, listStack.length > 0);\n listStack.push({ type, indent });\n }\n }\n processed += `${li}${content}`;\n lastListItem = type;\n continue;\n }\n\n if (line.trim() !== \"\") {\n while (listStack.length > 0) popOne();\n }\n processed += `${line}\\n`;\n }\n while (listStack.length > 0) popOne();\n\n // GFM task items: `- [ ] todo` / `- [x] done` print as real boxes.\n return processed.replace(\n /<li( class=\"([^\"]*)\")?>\\s*\\[([ xX])\\]\\s+/g,\n (_m: string, _c: string | undefined, classes: string | undefined, mark: string) =>\n `<li${cls(classes ?? \"\", \"matrx-task-item\")}><span class=\"matrx-task-box${\n mark === \" \" ? \"\" : \" is-checked\"\n }\" aria-hidden=\"true\"></span>`,\n );\n}\n\nfunction convertBody(skin: MarkdownSkin, markdown: string, ctx: ConvertContext): string {\n return skin === \"article\" ? articleBody(markdown, ctx) : documentBody(markdown, ctx);\n}\n\n/** Author text can never forge a placeholder. */\nfunction scrubTokens(markdown: string): string {\n return markdown.replace(/[\\uE000\\uE001]/g, \"\");\n}\n\nfunction newContext(options: MarkdownToHtmlOptions): ConvertContext {\n return { options, depth: 0, cardIndex: 0, strippedAnnounced: false };\n}\n\n// ─── document skin: markdown → `.matrx-*` HTML ───────────────────────────────\n\n/**\n * markdown → `.matrx-*`-classed HTML wrapped in `.matrx-content-container`.\n *\n * The class vocabulary is deliberate and non-configurable: it is what\n * `MARKDOWN_DOCUMENT_CSS` styles, what the PDF lane renders, and what a\n * WordPress theme targets. Handles (in this order, because the order is the\n * whole trick): the shared pre-pass (code, artifacts, page breaks, flashcards,\n * inline code, unsafe page markup) → rules → images → links → headings →\n * emphasis → nested/task lists → blockquotes → tables → block elements →\n * paragraphs → FAQ promotion → placeholder restoration.\n */\nexport function markdownToHtml(\n markdown: string,\n options: MarkdownToHtmlOptions = {},\n): string {\n if (!markdown) {\n options.onNotice?.({\n code: \"empty-output\",\n message: \"markdownToHtml received an empty string.\",\n remedy: \"Check the content is loaded before converting; nothing was rendered.\",\n });\n return \"\";\n }\n const source = scrubTokens(options.includeThinking ? markdown : removeThinkingContent(markdown));\n return sanitizePrintHtml(\n `<div class=\"matrx-content-container\">${documentBody(source, newContext(options))}</div>`,\n );\n}\n\nfunction documentBody(markdown: string, ctx: ConvertContext): string {\n const g = DOCUMENT_GRAMMAR;\n const stash = new Stash();\n let html = protectRegions(markdown, g, stash, ctx);\n\n // Rules before headings/lists so `---` / `#===` / `***` are never eaten.\n html = convertRules(html, g);\n\n // Images BEFORE links — `![a](u)` is a superset of `[a](u)`.\n html = html.replace(IMAGE_RE, (_m: string, alt: string, url: string) =>\n stash.block(`<img class=\"matrx-image\" src=\"${safeUrl(url)}\" alt=\"${escapeHtml(alt)}\" />`),\n );\n html = html.replace(LINK_RE, (_m: string, text: string, url: string) =>\n stash.inline(`<a class=\"matrx-link\" href=\"${safeUrl(url)}\">${convertEmphasis(text, g)}</a>`),\n );\n\n html = html\n .replace(/^# (.+)$/gm, '<h1 class=\"matrx-h1\">$1</h1>')\n .replace(/^## (.+)$/gm, '<h2 class=\"matrx-h2\">$1</h2>')\n .replace(/^### (.+)$/gm, '<h3 class=\"matrx-h3\">$1</h3>')\n .replace(/^#### (.+)$/gm, '<h4 class=\"matrx-h4\">$1</h4>')\n .replace(/^##### (.+)$/gm, '<h5 class=\"matrx-h5\">$1</h5>')\n .replace(/^###### (.+)$/gm, '<h6 class=\"matrx-h6\">$1</h6>');\n\n // Lists BEFORE emphasis, so a bullet opening with bold (`* **A** and *b*`)\n // is still a bullet.\n html = convertLists(html, g);\n html = convertEmphasis(html, g);\n\n html = html.replace(/^> ?(.+)$/gm, '<blockquote class=\"matrx-blockquote\">$1</blockquote>');\n\n html = convertTables(html, g);\n\n html = html\n .replace(/<table>/g, '<table class=\"matrx-table\">')\n .replace(/<thead>/g, '<thead class=\"matrx-table-head\">')\n .replace(/<tbody>/g, '<tbody class=\"matrx-table-body\">')\n .replace(/<tr>/g, '<tr class=\"matrx-table-row\">')\n .replace(/<th>/g, '<th class=\"matrx-table-header\">')\n .replace(/<td>/g, '<td class=\"matrx-table-cell\">');\n\n html = html.replace(/<img(?![^>]*class=)([^>]*)>/g, '<img class=\"matrx-image\"$1>');\n // Author divs join the vocabulary without losing their own class\n // (the old rewrite emitted two class attributes and the browser kept one).\n html = html.replace(/<div\\b([^>]*)>/g, (m: string, attrs: string) => {\n if (/\\bclass=\"matrx-/.test(attrs)) return m;\n if (/\\bclass=\"/.test(attrs)) return `<div${attrs.replace(/\\bclass=\"/, 'class=\"matrx-div ')}>`;\n return `<div class=\"matrx-div\"${attrs}>`;\n });\n html = html.replace(/<span(?![^>]*class=)([^>]*)>/g, '<span class=\"matrx-span\"$1>');\n\n html = html.replace(/^([^<\\n].+)$/gm, '<p class=\"matrx-paragraph\">$1</p>');\n html = html.replace(/<\\/p>\\s*<p class=\"matrx-paragraph\">/g, '</p><p class=\"matrx-paragraph\">');\n\n // Intro paragraph (first <p> after the h1) — before FAQ promotion.\n html = html.replace(\n /(<h1 class=\"matrx-h1\">[\\s\\S]*?<\\/h1>\\s*)<p class=\"matrx-paragraph\">((?:(?!\\uE000B)[\\s\\S])*?)<\\/p>/g,\n '$1<p class=\"matrx-intro\">$2</p>',\n );\n\n // FAQ promotion: bold questions and question headings become FAQ items.\n html = html.replace(\n /^<strong class=\"matrx-strong\">([^<]*\\?[^<]*)<\\/strong>$/gm,\n '<h3 class=\"matrx-h3\">$1</h3>',\n );\n html = html.replace(\n /<p class=\"matrx-paragraph\"><strong class=\"matrx-strong\">([^<]*\\?[^<]*)<\\/strong><\\/p>/g,\n '<h3 class=\"matrx-h3\">$1</h3>',\n );\n html = html.replace(\n /<h3 class=\"matrx-h3\">([^<]*\\?[^<]*)<\\/h3>/g,\n '<div class=\"matrx-faq-question\">$1</div>',\n );\n html = html.replace(\n /(<div class=\"matrx-faq-question\">[^<]*<\\/div>)\\s*(<p class=\"matrx-paragraph\">[\\s\\S]*?<\\/p>)/g,\n '<div class=\"matrx-faq-item\">$1<div class=\"matrx-faq-answer\">$2</div></div>',\n );\n html = html.replace(\n /(<div class=\"matrx-faq-question\">[^<]*<\\/div>)(?!\\s*<div class=\"matrx-faq-answer\">)/g,\n '<div class=\"matrx-faq-item\">$1<div class=\"matrx-faq-answer\"></div></div>',\n );\n html = html.replace(\n /(<div class=\"matrx-faq-answer\">)<p class=\"matrx-paragraph\">([\\s\\S]*?)<\\/p>(<\\/div>)/g,\n \"$1$2$3\",\n );\n\n return stash.restore(html);\n}\n\n// ─── article skin: markdown → bare semantic HTML ─────────────────────────────\n\n/**\n * markdown → bare semantic HTML (`h1`…`h6`, `p`, `ul`/`ol`, `blockquote`,\n * `.code-block-wrapper`, `.print-table`) for the article skin.\n *\n * Code is HTML-escaped in both skins (the shared pre-pass); a print window\n * never re-escapes, so unescaped code would render as markup.\n */\nexport function markdownToArticleHtml(\n markdown: string,\n options: MarkdownToHtmlOptions = {},\n): string {\n if (!markdown) {\n options.onNotice?.({\n code: \"empty-output\",\n message: \"markdownToArticleHtml received an empty string.\",\n remedy: \"Check the content is loaded before printing; nothing was rendered.\",\n });\n return \"\";\n }\n const source = scrubTokens(options.includeThinking ? markdown : removeThinkingContent(markdown));\n return sanitizePrintHtml(articleBody(source, newContext(options)));\n}\n\nfunction articleBody(markdown: string, ctx: ConvertContext): string {\n const g = ARTICLE_GRAMMAR;\n const stash = new Stash();\n let html = protectRegions(markdown, g, stash, ctx);\n html = convertTables(html, g);\n html = convertRules(html, g);\n\n // Images BEFORE links — `![a](u)` is a superset of `[a](u)`. Without this\n // pass an image fell through to the link pass and printed as a literal\n // \"!\" followed by a link (chat \"Print\", 2026-09-21).\n html = html.replace(IMAGE_RE, (_m: string, alt: string, url: string) =>\n stash.block(\n `<figure class=\"print-figure\"><img class=\"print-image\" src=\"${safeUrl(url)}\" alt=\"${escapeHtml(alt)}\" />${\n alt ? `<figcaption>${escapeHtml(alt)}</figcaption>` : \"\"\n }</figure>`,\n ),\n );\n html = html.replace(LINK_RE, (_m: string, text: string, url: string) =>\n stash.inline(`<a href=\"${safeUrl(url)}\">${convertEmphasis(text, g)}</a>`),\n );\n\n html = html\n .replace(/^#{6}\\s+(.+)$/gm, \"<h6>$1</h6>\")\n .replace(/^#{5}\\s+(.+)$/gm, \"<h5>$1</h5>\")\n .replace(/^#{4}\\s+(.+)$/gm, \"<h4>$1</h4>\")\n .replace(/^#{3}\\s+(.+)$/gm, \"<h3>$1</h3>\")\n .replace(/^#{2}\\s+(.+)$/gm, \"<h2>$1</h2>\")\n .replace(/^#{1}\\s+(.+)$/gm, \"<h1>$1</h1>\");\n\n html = html.replace(/^> ?(.+)$/gm, \"<blockquote>$1</blockquote>\");\n html = convertLists(html, g);\n html = convertEmphasis(html, g);\n\n html = html\n .split(\"\\n\")\n .map((line) => {\n const t = line.trim();\n if (!t) return \"\";\n if (\n /^<\\/?(h[1-6]|ul|ol|li|blockquote|pre|hr|table|thead|tbody|tr|th|td|div|figure|section)/.test(t) ||\n /^\\uE000B\\d+\\uE001$/.test(t)\n ) {\n return line;\n }\n return `<p>${t}</p>`;\n })\n .join(\"\\n\");\n\n return stash.restore(html).replace(/\\n{3,}/g, \"\\n\\n\").trim();\n}\n\n// ─── stylesheet + document composition ───────────────────────────────────────\n\n/**\n * The Print / Close action bar. The article sheet styles it already; the\n * document sheet is a content stylesheet with no chrome, so this ships beside\n * it — otherwise every host printing document-skin markdown gets two unstyled\n * browser buttons at the top of the page.\n */\nexport const PRINT_ACTIONS_CSS = `\n.print-actions { display: flex; gap: 10px; margin: 0 auto 28px; max-width: 800px; padding: 0 2rem 20px; border-bottom: 2px solid var(--matrx-print-border, #e1e1e1); }\n.print-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 20px; border-radius: 8px; font-size: 13px; font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif; cursor: pointer; border: none; font-weight: 600; }\n.print-btn-primary { background: var(--matrx-print-accent, #667eea); color: var(--matrx-print-bg, #ffffff); }\n.print-btn-secondary { background: var(--matrx-print-surface, #f8f9fa); color: var(--matrx-print-fg-strong, #374151); border: 1px solid var(--matrx-print-border-muted, #d1d5db); }\n@media print { .print-actions { display: none !important; } }\n`;\n\nexport interface MarkdownStylesheetOptions {\n /** Which shipped look. Default: `\"document\"`. */\n skin?: MarkdownSkin;\n /**\n * Host brand overrides — a CSS string appended AFTER the package's default\n * token values, so `:root { --matrx-print-accent: #0f766e; }` wins. Token\n * VALUES are host-owned; the token CONTRACT and the structural CSS are not.\n */\n tokens?: string;\n /** Extra rules appended after everything else. */\n extraCss?: string;\n /**\n * Number printed pages (\"3 / 12\", bottom centre) via `@page` margin boxes.\n * Default: true. Page margins are set either way.\n */\n pageNumbers?: boolean;\n}\n\n/**\n * The complete default stylesheet for a skin: default token values, the\n * structural sheet, the rules both skins share (page breaks, artifacts, task\n * boxes, print hard parts), page geometry, then the host's overrides. Never returns an empty string.\n */\nexport function getMarkdownStylesheet(\n options: MarkdownStylesheetOptions = {},\n): string {\n const skin: MarkdownSkin = options.skin ?? \"document\";\n const base =\n skin === \"article\"\n ? `${MARKDOWN_ARTICLE_TOKENS_CSS}\\n${MARKDOWN_ARTICLE_CSS}`\n : `${MARKDOWN_DOCUMENT_TOKENS_CSS}\\n${MARKDOWN_DOCUMENT_CSS}`;\n const page = options.pageNumbers === false ? MARKDOWN_PAGE_PLAIN_CSS : MARKDOWN_PAGE_CSS;\n return [base, MARKDOWN_SHARED_CSS, page, options.tokens ?? \"\", options.extraCss ?? \"\"]\n .filter((part) => part.trim().length > 0)\n .join(\"\\n\");\n}\n\n/** Convert markdown with the converter that matches a skin. */\nexport function markdownToHtmlForSkin(\n markdown: string,\n skin: MarkdownSkin,\n options: MarkdownToHtmlOptions = {},\n): string {\n return skin === \"article\"\n ? markdownToArticleHtml(markdown, options)\n : markdownToHtml(markdown, options);\n}\n\nexport interface RenderMarkdownDocumentOptions extends MarkdownStylesheetOptions {\n title?: string;\n /** Override the shipped converter. The seam survives; it is no longer required. */\n convertToHtml?: (markdown: string) => string;\n /** Replace the whole stylesheet (not merely the tokens). */\n css?: string;\n onNotice?: (notice: MarkdownNotice) => void;\n /** Include the Print / Close action bar (hidden by `@media print`). */\n withPrintActions?: boolean;\n}\n\n/**\n * markdown → a complete, standalone, styled HTML document string.\n *\n * This is the one composition every lane uses — the print window, the PDF\n * capture host, and \"copy a full HTML page\". A host that builds its own\n * `<!DOCTYPE html>` wrapper around package CSS is re-implementing this.\n */\nexport function renderMarkdownDocument(\n markdown: string,\n options: RenderMarkdownDocumentOptions = {},\n): string {\n const skin: MarkdownSkin = options.skin ?? \"document\";\n const title = options.title ?? \"AI Response\";\n const convert =\n options.convertToHtml ??\n ((md: string) =>\n markdownToHtmlForSkin(\n md,\n skin,\n options.onNotice ? { onNotice: options.onNotice } : {},\n ));\n const bodyHtml = convert(markdown);\n const css =\n options.css ??\n getMarkdownStylesheet({\n skin,\n ...(options.tokens === undefined ? {} : { tokens: options.tokens }),\n ...(options.extraCss === undefined ? {} : { extraCss: options.extraCss }),\n });\n\n // The article sheet already styles the action bar; the document sheet is a\n // pure content stylesheet, so it gets the shared chrome appended.\n const chrome =\n options.withPrintActions && skin !== \"article\" ? PRINT_ACTIONS_CSS : \"\";\n\n const actions = options.withPrintActions\n ? '<div class=\"print-actions\"><button class=\"print-btn print-btn-primary\" onclick=\"window.print()\">Print / Save as PDF</button><button class=\"print-btn print-btn-secondary\" onclick=\"window.close()\">Close</button></div>'\n : \"\";\n\n return `<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0\"><title>${escapeHtml(\n title,\n )}</title>\n<style>${css}${chrome}</style></head>\n<body>${actions}<div class=\"content\">${bodyHtml}</div></body></html>`;\n}\n\nexport interface PrintMarkdownOptions extends RenderMarkdownDocumentOptions {\n /** Window features for the print window. */\n windowFeatures?: string;\n}\n\n/**\n * Open a print window for a markdown string, in one call.\n *\n * Returns the `PrintOutcome` so the host can tell the user when the popup was\n * blocked and the `.html` download fallback fired instead — a silent fallback\n * is indistinguishable from \"print did nothing\".\n */\nexport function printMarkdown(\n markdown: string,\n options: PrintMarkdownOptions = {},\n): PrintOutcome {\n const title = options.title ?? \"AI Response\";\n const doc = renderMarkdownDocument(markdown, {\n ...options,\n title,\n withPrintActions: options.withPrintActions ?? true,\n });\n return options.windowFeatures === undefined\n ? openPrintWindow(doc, title)\n : openPrintWindow(doc, title, options.windowFeatures);\n}\n","/**\n * @ai-matrx/print/core — the Block Print contract & print-window composition.\n *\n * Ported VERBATIM from matrx-frontend `lib/block-print/block-print-utils.ts`\n * (2026-08-29 state, including the `number` and `select` PrintSetting types the\n * commerce label lane added). Zero dependencies; touches `window` only at call\n * time, so the module stays import-inert and RSC-safe.\n *\n * BlockPrinter is the only interface a host system needs to know about.\n * Each printable unit exports its own BlockPrinter alongside its render\n * component; host code only ever calls print(data, variantId, settings).\n *\n * `buildFitTextScript` is the ONE auto-shrink script (the flashcards\n * FIT_TEXT pattern, parameterized by selector so the label lane shares it).\n */\n\n// THE ONE HTML escaper (duplication census row 14). Nine copies of\n// `escapeHtml` were live across the fleet and THEY DID NOT ESCAPE THE SAME\n// CHARACTERS — a string safe through one was an attribute break-out through\n// another. It moved to `@ai-matrx/kit/html-escape` with a decided character\n// set: an HTML escaper must not require this package's jspdf + html2canvas\n// graph. Not re-exported from here; import `@ai-matrx/kit/html-escape`.\nimport { escapeHtml } from \"@ai-matrx/kit/html-escape\";\n\n// ─── Contract ────────────────────────────────────────────────────────────────\n\nexport interface PrintVariant {\n id: string;\n label: string;\n description?: string;\n}\n\n/**\n * A single user-configurable setting shown in the print dialog.\n * Extend the discriminated union for new control types\n * without breaking existing printers.\n */\nexport type PrintSetting =\n | {\n type: \"boolean\";\n id: string;\n label: string;\n description?: string;\n /** Default value shown when the dialog first opens */\n defaultValue: boolean;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n }\n | {\n /**\n * A numeric \"from → to\" range control, rendered as two small number inputs.\n * Writes two entries into the resolved PrintSettings map — one under fromId,\n * one under toId. Printers interpret 0 (or missing) as \"no bound\" by convention.\n */\n type: \"range\";\n /** Stable id used as React key — not written to the settings map */\n id: string;\n label: string;\n description?: string;\n /** Settings map key for the lower bound value */\n fromId: string;\n /** Settings map key for the upper bound value */\n toId: string;\n defaultFrom: number;\n defaultTo: number;\n /** Minimum accepted value for each input (inclusive). Default 0. */\n min?: number;\n /** Placeholder shown when the input is empty (0). Default \"start\" / \"end\". */\n fromPlaceholder?: string;\n toPlaceholder?: string;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n }\n | {\n /** A single numeric input (e.g. \"start at label #\", \"copies\"). */\n type: \"number\";\n id: string;\n label: string;\n description?: string;\n defaultValue: number;\n /** Minimum accepted value (inclusive). Default 0. */\n min?: number;\n /** Maximum accepted value (inclusive). Omit = unbounded. */\n max?: number;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n }\n | {\n /** A one-of-N choice rendered as a compact segmented row. */\n type: \"select\";\n id: string;\n label: string;\n description?: string;\n options: { value: string; label: string }[];\n defaultValue: string;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n };\n\n/** A resolved map of setting id → current value, passed to print(). */\nexport type PrintSettings = Record<string, boolean | string | number>;\n\n/**\n * The self-contained print capability that each block can export.\n * Host code only ever calls print(data, variantId, settings) — it never inspects internals.\n */\nexport interface BlockPrinter {\n /** Tooltip / aria-label for the print button in the block header */\n label: string;\n\n /**\n * Variants offered to the user before printing.\n * Empty array = no options dialog shown; prints immediately with defaults.\n */\n variants: PrintVariant[];\n\n /**\n * Optional user-configurable settings shown below the variant picker.\n * Omit entirely if the block has no configurable settings.\n */\n settings?: PrintSetting[];\n\n /**\n * Execute the print.\n * data — the block's structured data (serverData or parsed content)\n * variantId — which variant was chosen (undefined = default / no variants)\n * settings — resolved setting values chosen by the user\n *\n * MAY resolve to a PrintOutcome (\"opened\" | \"downloaded\") so the host can\n * tell the user when the popup-blocked download fallback fired; `void`\n * stays legal for printers that don't go through a print window.\n */\n print: (\n data: unknown,\n variantId?: string,\n settings?: PrintSettings,\n ) => void | PrintOutcome | Promise<void | PrintOutcome>;\n}\n\n// ─── Shared Utilities ─────────────────────────────────────────────────────────\n\nconst PRINT_STYLES = `\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;\n font-size: 11pt;\n line-height: 1.6;\n color: #1a1a1a;\n background: #fff;\n max-width: 860px;\n margin: 0 auto;\n padding: 28px 36px;\n }\n\n .print-actions {\n display: flex;\n gap: 10px;\n margin-bottom: 24px;\n padding-bottom: 18px;\n border-bottom: 2px solid #e5e7eb;\n }\n\n .print-btn {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n padding: 8px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-family: inherit;\n cursor: pointer;\n border: none;\n font-weight: 600;\n }\n\n .print-btn-primary { background: #2563eb; color: #fff; }\n .print-btn-secondary { background: #f3f4f6; color: #374151; border: 1px solid #d1d5db; }\n\n h1 { font-size: 22pt; font-weight: 700; margin-bottom: 0.5em; }\n h2 { font-size: 16pt; font-weight: 700; margin: 1.2em 0 0.4em; border-bottom: 1px solid #e5e7eb; padding-bottom: 0.2em; }\n h3 { font-size: 13pt; font-weight: 600; margin: 1em 0 0.3em; }\n p { margin-bottom: 0.7em; }\n\n table {\n width: 100%;\n border-collapse: collapse;\n margin: 1em 0;\n font-size: 10pt;\n }\n th {\n background: #1e293b;\n color: #f8fafc;\n font-weight: 600;\n text-align: left;\n padding: 7px 12px;\n border: 1px solid #334155;\n }\n td {\n padding: 6px 12px;\n border: 1px solid #e2e8f0;\n vertical-align: top;\n }\n tr:nth-child(even) td { background: #f8fafc; }\n\n @media print {\n body { max-width: 100%; padding: 0; }\n .print-actions { display: none !important; }\n th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }\n }\n`;\n\n/**\n * Wrap body HTML in a complete, styled print document.\n */\nexport function buildPrintDocument(\n bodyHtml: string,\n title = \"AI Response\",\n extraStyles = \"\",\n): string {\n return `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>${escapeHtml(title)}</title>\n <style>\n${PRINT_STYLES}\n${extraStyles}\n </style>\n</head>\n<body>\n <div class=\"print-actions\">\n <button class=\"print-btn print-btn-primary\" onclick=\"window.print()\">Print / Save as PDF</button>\n <button class=\"print-btn print-btn-secondary\" onclick=\"window.close()\">Close</button>\n </div>\n <div class=\"content\">\n${bodyHtml}\n </div>\n</body>\n</html>`;\n}\n\n/**\n * How a print request actually reached the user.\n *\n * \"opened\" — a print window/tab was opened and the document written into it.\n * \"downloaded\" — the popup was blocked, so the document was downloaded as an\n * .html file instead (the contract's fallback). Hosts SHOULD\n * surface this to the user (e.g. a toast saying the print file\n * was downloaded) — a blocked popup plus a silent download is\n * indistinguishable from \"nothing happened\", which is exactly\n * how QA filed it (2026-08-30, F5/F6/F8).\n */\nexport type PrintOutcome = \"opened\" | \"downloaded\";\n\n/**\n * Open a new browser window and write a complete HTML document into it.\n * Falls back to downloading an .html file if the popup is blocked.\n *\n * Returns which path was taken so callers can tell the user when the\n * fallback fired. `windowFeatures` customizes the popup geometry (the\n * flashcards fixed-geometry variants pass a wider window).\n */\nexport function openPrintWindow(\n htmlDocument: string,\n filename = \"print\",\n windowFeatures = \"width=920,height=720,scrollbars=yes\",\n): PrintOutcome {\n const win = window.open(\"\", \"_blank\", windowFeatures);\n if (!win) {\n // Popup blocked — fall back to file download\n const blob = new Blob([htmlDocument], { type: \"text/html;charset=utf-8\" });\n const url = URL.createObjectURL(blob);\n const a = document.createElement(\"a\");\n a.href = url;\n a.download = `${filename.replace(/\\s+/g, \"-\").toLowerCase()}.html`;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n // Revoke on a macrotask so the browser has started the blob fetch —\n // a synchronous revoke races the download in some engines.\n setTimeout(() => URL.revokeObjectURL(url), 0);\n return \"downloaded\";\n }\n win.document.open();\n win.document.write(htmlDocument);\n win.document.close();\n return \"opened\";\n}\n\n/**\n * Shorthand: build the document and open it in one call.\n * Returns the same PrintOutcome as openPrintWindow.\n */\nexport function printHtmlContent(\n bodyHtml: string,\n title = \"AI Response\",\n extraStyles = \"\",\n): PrintOutcome {\n const doc = buildPrintDocument(bodyHtml, title, extraStyles);\n return openPrintWindow(doc, title);\n}\n\n/**\n * Build the auto-shrink script that runs INSIDE a printed window: for every\n * element matching each selector, its font-size is reduced (0.5pt steps, 6pt\n * floor) until it fits its parent element's box. This is the flashcards\n * FIT_TEXT behavior verbatim, parameterized by selector so every lane\n * (flashcards card text, Avery text, label captions) shares the ONE loop.\n *\n * Pass the same selectors the original used to get byte-identical behavior:\n * flashcards passes `[\".card-text .card-text-inner\", \".avery-text-wrap .avery-text\"]`.\n */\nexport function buildFitTextScript(selectors: readonly string[]): string {\n const selectorsJson = JSON.stringify([...selectors]);\n return `\n<script>\n(function() {\n function fitText(el, container) {\n // container is the bounding box we must fit inside\n var maxW = container.clientWidth;\n var maxH = container.clientHeight;\n var size = parseFloat(window.getComputedStyle(el).fontSize);\n var minSize = 6;\n // Give the element a chance to reflow at current size before measuring\n el.style.fontSize = size + \"pt\";\n while (size > minSize && (el.scrollWidth > maxW + 1 || el.scrollHeight > maxH + 1)) {\n size -= 0.5;\n el.style.fontSize = size + \"pt\";\n }\n }\n function runAll() {\n var selectors = ${selectorsJson};\n for (var s = 0; s < selectors.length; s++) {\n var els = document.querySelectorAll(selectors[s]);\n for (var i = 0; i < els.length; i++) {\n fitText(els[i], els[i].parentElement);\n }\n }\n }\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", runAll);\n } else {\n // document.write pages may already be loaded\n setTimeout(runAll, 0);\n }\n})();\n</script>`;\n}\n\n","/**\n * @ai-matrx/print/safe-html — THE allow-list every Markdown→HTML string this\n * package hands out goes through.\n *\n * Why an allow-list: the regex converter (`markdownToHtml` /\n * `markdownToArticleHtml`) lets author raw HTML through so a document can feed\n * WordPress. Its old guard was a block-list (script, style, on… handlers,\n * javascript: URLs) and everything nobody listed — `<iframe>`, `<form>`,\n * `<meta http-equiv=refresh>`, `<object>`/`<embed>`, `<base>`, `<link>`,\n * inline `style` — reached the clipboard, the downloaded page and the preview.\n * Now a tag or attribute survives only when it is listed here.\n *\n * Sync and DOM-free (parse5 via hast), so it runs in Node, workers, the\n * extension service worker and Tauri alike.\n *\n * Two schemas:\n * • `SAFE_HTML_SCHEMA` — GitHub's rendering rules (hast-util-sanitize's\n * default schema) with no id clobber-prefixing and the \"drop the element\n * AND its text\" list for elements whose text is not prose. For any host\n * that renders plain semantic HTML (email bodies, CMS drafts).\n * • `PRINT_HTML_SCHEMA` — the same, plus exactly the vocabulary print's own\n * converters emit: `matrx-*` / `print-*` / `code-*` / `doc-*` classes,\n * table-cell alignment, the flashcard checkbox + label, figures, and the\n * page-break separator's data/aria attributes.\n */\n\nimport { fromHtml } from \"hast-util-from-html\";\nimport { defaultSchema, sanitize, type Schema } from \"hast-util-sanitize\";\nimport { toHtml } from \"hast-util-to-html\";\nimport type { Root } from \"hast\";\n\ntype Attributes = NonNullable<Schema[\"attributes\"]>;\ntype AttributeList = Attributes[string];\n\n/** Elements removed together with their content (their text is not prose). */\nconst STRIP_WITH_CONTENT = [\n \"script\",\n \"style\",\n \"noscript\",\n \"template\",\n \"iframe\",\n \"object\",\n \"embed\",\n \"textarea\",\n \"select\",\n \"head\",\n \"title\",\n];\n\n/** Never allowed, whatever a schema extension adds. */\nexport const FORBIDDEN_TAGS: readonly string[] = [\n ...STRIP_WITH_CONTENT,\n \"form\",\n \"meta\",\n \"base\",\n \"link\",\n \"frame\",\n \"frameset\",\n \"applet\",\n \"button\",\n \"svg\",\n \"math\",\n];\n\nconst baseAttributes = defaultSchema.attributes ?? {};\n\nexport const SAFE_HTML_SCHEMA: Schema = {\n ...defaultSchema,\n tagNames: (defaultSchema.tagNames ?? []).filter((t) => !FORBIDDEN_TAGS.includes(t)),\n strip: STRIP_WITH_CONTENT,\n // Authored anchors keep their names; the GitHub `user-content-` rewrite\n // would also break `<label for>` → `<input id>` pairs.\n clobberPrefix: \"\",\n clobber: [],\n};\n\n/** Class tokens print's converters emit. Author classes outside these are dropped. */\nconst PRINT_CLASS = /^(?:(?:matrx|print|code|doc|language)-[\\w-]*|inline-code|is-checked)$/;\n\n/**\n * A tag's own `className` definition wins over `'*'` (and returns an empty\n * list rather than falling through), so the print class pattern is merged into\n * every definition that names `className`, and added where none does.\n */\nfunction withPrintClasses(defs: AttributeList = []): AttributeList {\n let found = false;\n const out = defs.map((d) => {\n if (Array.isArray(d) && d[0] === \"className\") {\n found = true;\n return [...d, PRINT_CLASS] as unknown as typeof d;\n }\n return d;\n });\n return found ? out : [...out, [\"className\", PRINT_CLASS]];\n}\n\nconst printAttributes: Attributes = Object.fromEntries(\n Object.entries(baseAttributes).map(([tag, defs]) => [tag, withPrintClasses(defs)]),\n);\n\nconst cellAlign = [\"style\", /^text-align:\\s*(?:left|center|right);?$/] as const;\n\nexport const PRINT_HTML_SCHEMA: Schema = {\n ...SAFE_HTML_SCHEMA,\n tagNames: [\n ...new Set([...(SAFE_HTML_SCHEMA.tagNames ?? []), \"section\", \"figure\", \"figcaption\", \"label\"]),\n ],\n attributes: {\n ...printAttributes,\n \"*\": [\n ...(baseAttributes[\"*\"] ?? []),\n [\"className\", PRINT_CLASS],\n \"role\",\n \"ariaLabel\",\n \"ariaHidden\",\n \"dataLabel\",\n \"dataLanguage\",\n \"dataArtifactType\",\n ],\n // Table-cell alignment is the one inline style the converter writes.\n td: withPrintClasses([...(baseAttributes[\"td\"] ?? []), [...cellAlign]]),\n th: withPrintClasses([...(baseAttributes[\"th\"] ?? []), [...cellAlign]]),\n // The flashcard flip is a checkbox + label pair (GitHub forces `disabled`).\n input: withPrintClasses([[\"type\", \"checkbox\"], \"checked\"]),\n label: withPrintClasses([\"htmlFor\"]),\n },\n required: { input: { type: \"checkbox\" } },\n protocols: {\n ...defaultSchema.protocols,\n href: [...(defaultSchema.protocols?.href ?? []), \"tel\"],\n // Embedded images (`data:image/png;base64,…`) — an <img> never runs script.\n src: [...(defaultSchema.protocols?.src ?? []), \"data\"],\n },\n};\n\n/** Sanitize an HTML fragment against an allow-list (default: `SAFE_HTML_SCHEMA`). */\nexport function sanitizeHtmlFragment(html: string, schema: Schema = SAFE_HTML_SCHEMA): string {\n if (!html) return \"\";\n const tree = sanitize(fromHtml(html, { fragment: true }), schema) as Root;\n return toHtml(tree, { characterReferences: { useNamedReferences: true } });\n}\n\n/** Sanitize the output of print's own converters (keeps the `.matrx-*` vocabulary). */\nexport function sanitizePrintHtml(html: string): string {\n return sanitizeHtmlFragment(html, PRINT_HTML_SCHEMA);\n}\n\nexport type { Schema as SafeHtmlSchema };\n\n/**\n * MathML from the TeX typesetter. TeX is author input, and MathJax's `html`,\n * `bbox` and `\\mmlToken` commands turn it into attributes (`\\href{javascript:…}`\n * → `href`, `\\style{position:fixed…}` / `\\bbox[position:fixed]` → `style`).\n * Only presentation MathML elements and their layout attributes survive.\n */\nconst MATHML_TAGS = [\n \"math\", \"maction\", \"annotation\", \"menclose\", \"merror\", \"mfrac\", \"mglyph\", \"mi\",\n \"mlabeledtr\", \"mmultiscripts\", \"mn\", \"mo\", \"mover\", \"mpadded\", \"mphantom\", \"mprescripts\", \"none\",\n \"mroot\", \"mrow\", \"ms\", \"mspace\", \"msqrt\", \"mstyle\", \"msub\", \"msubsup\", \"msup\", \"mtable\", \"mtd\",\n \"mtext\", \"mtr\", \"munder\", \"munderover\", \"semantics\",\n];\n\nconst MATHML_ATTRIBUTES = [\n \"xmlns\", \"display\", \"displaystyle\", \"mathvariant\", \"mathsize\", \"mathcolor\", \"mathbackground\",\n \"scriptlevel\", \"dir\", \"fence\", \"form\", \"largeop\", \"lspace\", \"rspace\", \"movablelimits\",\n \"separator\", \"stretchy\", \"symmetric\", \"maxsize\", \"minsize\", \"accent\", \"accentunder\", \"align\",\n \"columnalign\", \"rowalign\", \"columnspacing\", \"rowspacing\", \"columnlines\", \"rowlines\", \"frame\",\n \"framespacing\", \"equalrows\", \"equalcolumns\", \"linethickness\", \"numalign\", \"denomalign\",\n \"bevelled\", \"notation\", \"width\", \"height\", \"depth\", \"voffset\", \"lquote\", \"rquote\", \"columnspan\",\n \"rowspan\", \"encoding\", \"open\", \"close\", \"separators\", \"actiontype\", \"selection\", \"mslinebreak\",\n \"linebreak\", \"indentalign\", \"data*\",\n];\n\nexport const MATHML_SCHEMA: Schema = {\n tagNames: MATHML_TAGS,\n attributes: { \"*\": MATHML_ATTRIBUTES },\n strip: [\"script\", \"style\"],\n clobberPrefix: \"\",\n clobber: [],\n protocols: {},\n};\n\n/** Sanitize a typeset MathML string (keeps layout, drops links and styles). */\nexport function sanitizeMathml(mathml: string): string {\n return sanitizeHtmlFragment(mathml, MATHML_SCHEMA);\n}\n\n/**\n * SVG from the TeX typesetter (PDF display math, LIST T26). MathJax's `\\href`,\n * `\\style`, `\\class`, `\\cssId`, `\\bbox[…]` and `\\mmlToken[…]` reach the SVG as\n * `<a href=\"javascript:…\">`, `style=\"position:fixed…\"`, `class`, `id`. The PDF\n * writer draws this SVG, and any host that shows it would too, so only the\n * drawing vocabulary survives: shapes, paths, text, transforms and paint. A\n * link wrapper is unwrapped (its glyphs stay), everything else is dropped.\n */\nconst MATH_SVG_TAGS = [\"svg\", \"g\", \"path\", \"rect\", \"line\", \"polyline\", \"polygon\", \"circle\", \"ellipse\", \"text\", \"title\", \"desc\"];\n\nconst MATH_SVG_ATTRIBUTES = [\n \"xmlns\", \"width\", \"height\", \"viewBox\", \"role\", \"focusable\", \"ariaHidden\", \"ariaLabel\",\n \"stroke\", \"fill\", \"strokeWidth\", \"strokeLinecap\", \"strokeLinejoin\", \"transform\", \"d\",\n \"x\", \"y\", \"x1\", \"y1\", \"x2\", \"y2\", \"points\", \"cx\", \"cy\", \"r\", \"rx\", \"ry\",\n \"dataMmlNode\", \"dataC\",\n];\n\nexport const MATH_SVG_SCHEMA: Schema = {\n tagNames: MATH_SVG_TAGS,\n attributes: { \"*\": MATH_SVG_ATTRIBUTES },\n strip: [\"script\", \"style\", \"foreignObject\"],\n clobberPrefix: \"\",\n clobber: [],\n protocols: {},\n};\n\n/** Sanitize a typeset math SVG (keeps the drawing, drops links, styles, classes and ids). */\nexport function sanitizeMathSvg(svg: string): string {\n return sanitizeHtmlFragment(svg, MATH_SVG_SCHEMA);\n}\n\n/**\n * THE final allow-list of the one Markdown→HTML engine (`@ai-matrx/print/\n * markdown-html`, CONTRACT §1.9): print's own vocabulary plus typeset MathML\n * (MathML elements carry only the MathML layout attributes), and — for the\n * inline clipboard skin only — `style` attributes whose value is EXACTLY one\n * the engine itself wrote (`inlineStyles`). An author can never reach a style.\n */\nexport function engineHtmlSchema(inlineStyles: readonly string[] = []): Schema {\n const exact = inlineStyles.length\n ? [new RegExp(`^(?:${[...new Set(inlineStyles)].map((s) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")).join(\"|\")})$`)]\n : [];\n const mathAttributes = Object.fromEntries(MATHML_TAGS.map((tag) => [tag, MATHML_ATTRIBUTES]));\n const printAttrs = PRINT_HTML_SCHEMA.attributes ?? {};\n const styled = (defs: AttributeList = []): AttributeList =>\n exact.length ? [...defs.filter((d) => !(Array.isArray(d) && d[0] === \"style\")), [\"style\", ...exact]] : defs;\n const attributes: Attributes = { ...printAttrs, ...mathAttributes };\n if (exact.length) {\n for (const tag of new Set([...(PRINT_HTML_SCHEMA.tagNames ?? []), \"div\", \"span\"])) {\n if (MATHML_TAGS.includes(tag)) continue;\n attributes[tag] = styled(printAttrs[tag] ?? []);\n }\n // Table cells keep their alignment AND the skin's cell style (the skin writes both into one value).\n }\n return {\n ...PRINT_HTML_SCHEMA,\n tagNames: [...new Set([...(PRINT_HTML_SCHEMA.tagNames ?? []), ...MATHML_TAGS])],\n attributes,\n };\n}\n\n/** Sanitize the engine's output (see `engineHtmlSchema`). */\nexport function sanitizeEngineHtml(html: string, inlineStyles: readonly string[] = []): string {\n return sanitizeHtmlFragment(html, engineHtmlSchema(inlineStyles));\n}\n","/**\n * Default print stylesheets for `@ai-matrx/print/markdown`.\n *\n * Two skins, ONE semantic-token vocabulary (C26 — structural CSS ships in the\n * package, the token CONTRACT is enforced, token VALUES are host-overridable):\n *\n * \"document\" — the `.matrx-*` content sheet. What `markdownToHtml` emits,\n * what the markdown→PDF lane renders, and what pastes straight\n * into a WordPress theme.\n * \"article\" — the serif AI-response sheet used by the print-window lane.\n *\n * Every colour is `var(--matrx-print-<role>, <default>)`. The inline fallback\n * is what makes the drop-in test pass in a fresh, unthemed app; the `:root`\n * block is the shipped default token-values sheet a host overrides by\n * appending its own `:root` rule (`getMarkdownStylesheet({ tokens })`).\n *\n * Both sheets carry the print hard parts — `@media print`, page-break\n * avoidance, orphans/widows, `print-color-adjust` — so no host re-derives them.\n *\n * THIS FILE IS THE SOURCE OF TRUTH. It was seeded once from the two host\n * stylesheets it replaced (matrx-frontend's WordPress sheet and its serif\n * print sheet, both deleted in the same session); there is no generator to\n * re-run and no upstream to diff against. Edit it here.\n *\n * DO NOT hand-edit colour literals back in: a hardcoded colour in package CSS\n * is a C26 violation. Add a role to the vocabulary instead.\n */\n\n/** Default token VALUES for the document skin. */\nexport const MARKDOWN_DOCUMENT_TOKENS_CSS = `:root {\n --matrx-print-accent: #667eea;\n --matrx-print-accent-2: #764ba2;\n --matrx-print-bg: #ffffff;\n --matrx-print-border: #e1e1e1;\n --matrx-print-border-muted: #d1d5db;\n --matrx-print-border-strong: #e5e5e5;\n --matrx-print-code-bg: #f5f5f5;\n --matrx-print-code-block-bg: #f8f8f8;\n --matrx-print-code-block-fg: #333;\n --matrx-print-code-fg: #d73a49;\n --matrx-print-fg: #1a1a1a;\n --matrx-print-fg-muted: #4a4a4a;\n --matrx-print-fg-subtle: #6b7280;\n --matrx-print-heading: #2a2a2a;\n --matrx-print-heading-sub: #3a3a3a;\n --matrx-print-link-fg: #374151;\n --matrx-print-link-hover-fg: #1f2937;\n --matrx-print-link-underline: #9ca3af;\n --matrx-print-quote-fg: #666;\n --matrx-print-shadow: rgba(0, 0, 0, 0.1);\n --matrx-print-shadow-strong: rgba(0, 0, 0, 0.2);\n --matrx-print-success: #2d5016;\n --matrx-print-success-2: #1e3a0f;\n --matrx-print-surface: #f8f9fa;\n --matrx-print-table-fg: #333333;\n}`;\n\n/** Default token VALUES for the article skin. */\nexport const MARKDOWN_ARTICLE_TOKENS_CSS = `:root {\n --matrx-print-accent: #2563eb;\n --matrx-print-bg: #fff;\n --matrx-print-border: #e5e7eb;\n --matrx-print-border-muted: #d1d5db;\n --matrx-print-code-bg: #f1f5f9;\n --matrx-print-fg: #1a1a1a;\n --matrx-print-fg-muted: #374151;\n --matrx-print-fg-subtle: #64748b;\n --matrx-print-heading: #111827;\n --matrx-print-ink: #0f172a;\n --matrx-print-line: #e2e8f0;\n --matrx-print-quote-bg: #f5f3ff;\n --matrx-print-quote-border: #6366f1;\n --matrx-print-surface: #f8fafc;\n --matrx-print-surface-sunken: #f3f4f6;\n --matrx-print-table-head-bg: #1e293b;\n --matrx-print-table-head-border: #334155;\n}`;\n\n/** Structural CSS for the document skin (`.matrx-*` classes). */\nexport const MARKDOWN_DOCUMENT_CSS = `/* \n * MATRX WordPress CSS - Production Ready\n * Use this CSS in your WordPress theme to style MATRX content\n * All styles are scoped to .matrx-content-container to avoid conflicts\n */\n\n/* Content Container */\n.matrx-content-container {\n max-width: 800px;\n margin: 0 auto;\n padding: 2rem;\n line-height: 1.6;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;\n}\n\n/* Typography */\n.matrx-h1 {\n font-size: 2.5rem;\n font-weight: 700;\n margin: 0 0 1.5rem 0;\n color: var(--matrx-print-fg, #1a1a1a);\n line-height: 1.2;\n}\n\n.matrx-h2 {\n font-size: 1.8rem;\n font-weight: 600;\n margin: 3rem 0 1rem 0 !important;\n color: var(--matrx-print-heading, #2a2a2a);\n line-height: 1.3 !important;\n border-bottom: 2px solid var(--matrx-print-border-strong, #e5e5e5);\n padding-bottom: 0.75rem !important;\n padding-top: 0 !important;\n}\n\n.matrx-h3 {\n font-size: 1.3rem;\n font-weight: 600;\n margin: 2rem 0 1rem 0;\n color: var(--matrx-print-heading-sub, #3a3a3a);\n line-height: 1.4;\n}\n\n.matrx-h4 {\n font-size: 1.1rem;\n font-weight: 600;\n margin: 1.5rem 0 0.75rem 0;\n color: var(--matrx-print-heading-sub, #3a3a3a);\n line-height: 1.4;\n}\n\n.matrx-h5 {\n font-size: 1rem;\n font-weight: 600;\n margin: 1.25rem 0 0.5rem 0;\n color: var(--matrx-print-heading-sub, #3a3a3a);\n line-height: 1.4;\n}\n\n.matrx-h6 {\n font-size: 0.9rem;\n font-weight: 600;\n margin: 1rem 0 0.5rem 0;\n color: var(--matrx-print-heading-sub, #3a3a3a);\n line-height: 1.4;\n}\n\n/* Paragraphs */\n.matrx-intro {\n font-size: 1.1rem;\n color: var(--matrx-print-fg-muted, #4a4a4a);\n margin-bottom: 2rem;\n padding: 1.5rem;\n background: var(--matrx-print-surface, #f8f9fa);\n border-left: 4px solid var(--matrx-print-border-muted, #d1d5db);\n border-radius: 0 8px 8px 0;\n}\n\n.matrx-paragraph {\n font-size: 1rem;\n color: var(--matrx-print-fg-muted, #4a4a4a);\n margin-bottom: 1.5rem;\n text-align: justify;\n}\n\n/* Text Formatting */\n.matrx-em {\n font-style: italic;\n color: var(--matrx-print-heading, #2a2a2a);\n}\n\n.matrx-strong {\n font-weight: 600;\n color: var(--matrx-print-heading, #2a2a2a);\n}\n\n/* Links */\n.matrx-link {\n color: var(--matrx-print-link-fg, #374151);\n text-decoration: underline;\n text-decoration-color: var(--matrx-print-border-muted, #d1d5db);\n text-underline-offset: 3px;\n transition: all 0.2s ease;\n}\n\n.matrx-link:hover {\n color: var(--matrx-print-link-hover-fg, #1f2937);\n text-decoration-color: var(--matrx-print-link-underline, #9ca3af);\n}\n\n/* Images */\n.matrx-image {\n max-width: 100%;\n height: auto;\n display: block;\n margin: 1.5rem auto;\n border-radius: 8px;\n box-shadow: 0 2px 8px var(--matrx-print-shadow, rgba(0, 0, 0, 0.1));\n}\n\n/* Lists */\n.matrx-list {\n margin: 1.5rem 0;\n padding-left: 0;\n}\n\n.matrx-bullet-list {\n list-style: none;\n}\n\n.matrx-list-item {\n margin-bottom: 1rem;\n padding-left: 1.5rem;\n position: relative;\n color: var(--matrx-print-fg-muted, #4a4a4a);\n}\n\n.matrx-list-item::before {\n content: \"•\";\n color: var(--matrx-print-fg-subtle, #6b7280);\n font-weight: bold;\n position: absolute;\n left: 0;\n top: 0;\n font-size: 1.2rem;\n}\n\n/* Numbered Lists */\n.matrx-numbered-list {\n list-style: decimal;\n padding-left: 2rem;\n}\n\n.matrx-numbered-list > .matrx-list-item {\n padding-left: 0.5rem;\n}\n\n.matrx-numbered-list > .matrx-list-item::before {\n content: none;\n /* Remove the bullet */\n}\n\n/* Nested list indentation */\n.matrx-nested-list {\n margin-top: 0.5rem;\n margin-bottom: 0.5rem;\n padding-left: 1.5rem !important;\n}\n\n/* Ensure nested lists within list items are properly indented */\n.matrx-list-item > .matrx-list {\n margin-top: 0.5rem;\n margin-bottom: 0.5rem;\n padding-left: 1.5rem;\n}\n\n/* For multiple levels of nesting, increase indentation */\n.matrx-nested-list .matrx-nested-list {\n padding-left: 1.5rem !important;\n}\n\n/* Code */\n.matrx-content-container .matrx-inline-code {\n background-color: var(--matrx-print-code-bg, #f5f5f5);\n padding: 0.125rem 0.25rem;\n border-radius: 0.25rem;\n font-family: \"Monaco\", \"Menlo\", \"Ubuntu Mono\", monospace;\n font-size: 0.875rem;\n color: var(--matrx-print-code-fg, #d73a49);\n}\n\n.matrx-content-container .matrx-code-block {\n background-color: var(--matrx-print-code-block-bg, #f8f8f8);\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n border-radius: 0.375rem;\n padding: 1rem;\n margin: 1.5rem 0;\n overflow-x: auto;\n}\n\n.matrx-content-container .matrx-code {\n font-family: \"Monaco\", \"Menlo\", \"Ubuntu Mono\", monospace;\n font-size: 0.875rem;\n line-height: 1.5;\n color: var(--matrx-print-code-block-fg, #333);\n}\n\n/* Blockquotes */\n.matrx-content-container .matrx-blockquote {\n border-left: 4px solid var(--matrx-print-border, #e1e1e1);\n padding-left: 1rem;\n margin: 1.5rem 0;\n font-style: italic;\n color: var(--matrx-print-quote-fg, #666);\n}\n\n/* Tables */\n.matrx-content-container .matrx-table {\n width: 100%;\n border-collapse: collapse;\n margin: 1.5rem 0;\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n}\n\n.matrx-content-container .matrx-table-header {\n background-color: var(--matrx-print-surface, #f8f9fa);\n font-weight: 600;\n padding: 0.75rem;\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n text-align: left;\n}\n\n.matrx-content-container .matrx-table-cell {\n padding: 0.75rem;\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n}\n\n.matrx-content-container .matrx-table-row:nth-child(even) {\n background-color: var(--matrx-print-surface, #f8f9fa);\n}\n\n/* Images */\n.matrx-content-container .matrx-image {\n max-width: 100%;\n height: auto;\n border-radius: 0.375rem;\n margin: 1rem 0;\n}\n\n/* Horizontal Rules */\n.matrx-content-container .matrx-hr {\n border: none;\n border-top: 1px solid var(--matrx-print-border, #e1e1e1);\n margin: 2rem 0;\n}\n\n/* FAQ Styles - Clean Design */\n.matrx-faq-item {\n margin-bottom: 2rem;\n padding: 1.5rem;\n background: var(--matrx-print-surface, #f8f9fa);\n border-radius: 8px;\n border-left: 4px solid var(--matrx-print-border-muted, #d1d5db);\n}\n\n.matrx-faq-question {\n font-size: 1.2rem;\n font-weight: 600;\n margin: 0 0 0.75rem 0;\n color: var(--matrx-print-heading, #2a2a2a);\n}\n\n.matrx-faq-answer {\n margin: 0;\n color: var(--matrx-print-fg-muted, #4a4a4a);\n line-height: 1.6;\n}\n\n/* Code Blocks */\n.matrx-inline-code {\n background-color: var(--matrx-print-code-bg, #f5f5f5);\n padding: 0.125rem 0.25rem;\n border-radius: 0.25rem;\n font-family: \"Monaco\", \"Menlo\", \"Ubuntu Mono\", monospace;\n font-size: 0.875rem;\n color: var(--matrx-print-code-fg, #d73a49);\n}\n\n.matrx-code-block {\n background-color: var(--matrx-print-code-block-bg, #f8f8f8);\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n border-radius: 0.375rem;\n padding: 1rem;\n margin: 1.5rem 0;\n overflow-x: auto;\n}\n\n.matrx-code {\n font-family: \"Monaco\", \"Menlo\", \"Ubuntu Mono\", monospace;\n font-size: 0.875rem;\n line-height: 1.5;\n color: var(--matrx-print-code-block-fg, #333);\n}\n\n/* Blockquotes */\n.matrx-blockquote {\n border-left: 4px solid var(--matrx-print-border, #e1e1e1);\n padding-left: 1rem;\n margin: 1.5rem 0;\n font-style: italic;\n color: var(--matrx-print-quote-fg, #666);\n}\n\n/* Tables */\n.matrx-table {\n width: 100%;\n border-collapse: collapse;\n margin: 1.5rem 0;\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n color: var(--matrx-print-table-fg, #333333);\n}\n\n.matrx-table-head {\n background-color: var(--matrx-print-surface, #f8f9fa);\n}\n\n.matrx-table-body {\n background-color: var(--matrx-print-bg, #ffffff);\n}\n\n.matrx-table-header {\n background-color: var(--matrx-print-surface, #f8f9fa);\n font-weight: 600;\n padding: 0.75rem;\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n text-align: left;\n color: var(--matrx-print-table-fg, #333333);\n}\n\n.matrx-table-cell {\n padding: 0.75rem;\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n color: var(--matrx-print-table-fg, #333333);\n}\n\n.matrx-table-row {\n color: var(--matrx-print-table-fg, #333333);\n}\n\n.matrx-table-row:nth-child(even) {\n background-color: var(--matrx-print-surface, #f8f9fa);\n}\n\n/* Ensure table content doesn't inherit external colors */\n.matrx-table * {\n color: inherit;\n}\n\n/* Images */\n.matrx-image {\n max-width: 100%;\n height: auto;\n border-radius: 0.375rem;\n margin: 1rem 0;\n}\n\n/* Horizontal Rules */\n.matrx-hr {\n border: none;\n border-top: 1px solid var(--matrx-print-border, #e1e1e1);\n margin: 2rem 0;\n}\n\n/* Utility Classes */\n.matrx-div {\n margin: 0.5rem 0;\n}\n\n.matrx-span {\n /* Inherit parent styling by default */\n}\n\n/* Flashcard Styles */\n.matrx-flashcards-container {\n margin: 2rem 0;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n}\n\n.matrx-flashcard {\n perspective: 1000px;\n perspective-origin: center center;\n height: 200px;\n cursor: pointer;\n position: relative;\n margin-bottom: 0.5rem;\n}\n\n.matrx-flashcard-input {\n display: none;\n}\n\n.matrx-flashcard-inner {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n transition: transform 0.6s;\n transform-style: preserve-3d;\n transform-origin: center center;\n}\n\n.matrx-flashcard-input:checked ~ .matrx-flashcard-inner {\n transform: rotateY(180deg);\n}\n\n.matrx-flashcard-front,\n.matrx-flashcard-back {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n backface-visibility: hidden;\n border-radius: 12px;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 1.5rem;\n box-shadow: 0 4px 6px var(--matrx-print-shadow, rgba(0, 0, 0, 0.1));\n transition: box-shadow 0.3s ease;\n box-sizing: border-box;\n}\n\n.matrx-flashcard-front {\n background: linear-gradient(135deg, var(--matrx-print-accent, #667eea) 0%, var(--matrx-print-accent-2, #764ba2) 100%);\n color: white;\n}\n\n.matrx-flashcard-back {\n background: linear-gradient(135deg, var(--matrx-print-success, #2d5016) 0%, var(--matrx-print-success-2, #1e3a0f) 100%);\n color: white;\n transform: rotateY(180deg);\n}\n\n.matrx-flashcard:hover .matrx-flashcard-front,\n.matrx-flashcard:hover .matrx-flashcard-back {\n box-shadow: 0 8px 16px var(--matrx-print-shadow-strong, rgba(0, 0, 0, 0.2));\n}\n\n.matrx-flashcard-content {\n text-align: center;\n font-size: 1.3rem;\n line-height: 1.8;\n max-height: 100%;\n width: 100%;\n overflow: hidden;\n}\n\n.matrx-flashcard-label {\n cursor: pointer;\n user-select: none;\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: 10;\n}\n\n.matrx-flashcard-indicator {\n position: absolute;\n bottom: 12px;\n right: 16px;\n font-size: 0.75rem;\n opacity: 0.8;\n font-weight: 500;\n letter-spacing: 0.5px;\n}\n\n/* Responsive adjustments */\n@media (max-width: 768px) {\n .matrx-flashcard {\n height: 180px;\n }\n\n .matrx-flashcard-content {\n font-size: 1rem;\n }\n\n .matrx-flashcard-front,\n .matrx-flashcard-back {\n padding: 1.25rem;\n }\n}\n\n@media (max-width: 480px) {\n .matrx-flashcard {\n height: 160px;\n }\n\n .matrx-flashcard-content {\n font-size: 0.95rem;\n }\n\n .matrx-flashcard-front,\n .matrx-flashcard-back {\n padding: 1rem;\n }\n}\n\n/* Responsive Design */\n@media (max-width: 768px) {\n .matrx-content-container {\n padding: 1rem;\n }\n\n .matrx-h1 {\n font-size: 2rem;\n }\n\n .matrx-h2 {\n font-size: 1.5rem;\n margin: 2rem 0 1rem 0 !important;\n }\n\n .matrx-h3 {\n font-size: 1.2rem;\n }\n\n .matrx-h4 {\n font-size: 1.05rem;\n }\n\n .matrx-h5 {\n font-size: 0.95rem;\n }\n\n .matrx-h6 {\n font-size: 0.9rem;\n }\n\n .matrx-intro {\n padding: 1rem;\n font-size: 1rem;\n }\n\n .matrx-faq-question {\n font-size: 1.1rem;\n margin: 1.5rem 0 0.75rem 0;\n }\n\n .matrx-paragraph {\n text-align: left;\n }\n\n .matrx-table {\n font-size: 0.875rem;\n }\n\n .matrx-table-header,\n .matrx-table-cell {\n padding: 0.5rem;\n }\n\n .matrx-code-block {\n padding: 0.75rem;\n margin: 1rem 0;\n }\n}\n\n@media (max-width: 480px) {\n .matrx-content-container {\n padding: 0.75rem;\n }\n\n .matrx-h1 {\n font-size: 1.75rem;\n margin-bottom: 1rem;\n }\n\n .matrx-h2 {\n font-size: 1.3rem;\n margin: 1.5rem 0 0.75rem 0 !important;\n }\n\n .matrx-h3 {\n font-size: 1.1rem;\n margin: 1.5rem 0 0.75rem 0;\n }\n\n .matrx-h4 {\n font-size: 1rem;\n margin: 1.25rem 0 0.5rem 0;\n }\n\n .matrx-h5 {\n font-size: 0.9rem;\n margin: 1rem 0 0.5rem 0;\n }\n\n .matrx-h6 {\n font-size: 0.85rem;\n margin: 1rem 0 0.5rem 0;\n }\n\n .matrx-intro {\n padding: 0.75rem;\n margin-bottom: 1.5rem;\n }\n\n .matrx-paragraph {\n margin-bottom: 1.25rem;\n }\n\n .matrx-list-item {\n margin-bottom: 0.75rem;\n }\n\n .matrx-table-header,\n .matrx-table-cell {\n padding: 0.375rem;\n }\n\n .matrx-code-block {\n padding: 0.5rem;\n font-size: 0.8rem;\n }\n\n .matrx-inline-code {\n font-size: 0.8rem;\n }\n}\n/* Print / PDF hard parts — added by @ai-matrx/print 0.3.0. */\n@media print {\n .matrx-content-container {\n max-width: 100%;\n padding: 0;\n }\n\n .matrx-h1,\n .matrx-h2,\n .matrx-h3,\n .matrx-h4,\n .matrx-h5,\n .matrx-h6 {\n page-break-after: avoid;\n break-after: avoid;\n }\n\n .matrx-paragraph,\n .matrx-intro {\n orphans: 3;\n widows: 3;\n }\n\n .matrx-table,\n .matrx-code-block,\n .matrx-blockquote,\n .matrx-list-item,\n .matrx-image,\n .matrx-faq-item,\n .matrx-flashcard {\n page-break-inside: avoid;\n break-inside: avoid;\n }\n\n .matrx-table-header,\n .matrx-code-block,\n .matrx-blockquote,\n .matrx-flashcard {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n\n .matrx-link {\n text-decoration: underline;\n }\n}\n`;\n\n/** Structural CSS for the article skin (bare tags + `.print-*` classes). */\nexport const MARKDOWN_ARTICLE_CSS = `*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}body{font-family:Georgia,'Times New Roman',serif;font-size:11pt;line-height:1.7;color:var(--matrx-print-fg, #1a1a1a);background:var(--matrx-print-bg, #fff);max-width:780px;margin:0 auto;padding:32px 40px}.print-actions{display:flex;gap:10px;margin-bottom:28px;padding-bottom:20px;border-bottom:2px solid var(--matrx-print-border, #e5e7eb)}.print-btn{display:inline-flex;align-items:center;gap:6px;padding:8px 20px;border-radius:8px;font-size:13px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;cursor:pointer;border:none;font-weight:600;transition:opacity .15s}.print-btn:hover{opacity:.85}.print-btn-primary{background:var(--matrx-print-accent, #2563eb);color:var(--matrx-print-bg, #fff)}.print-btn-secondary{background:var(--matrx-print-surface-sunken, #f3f4f6);color:var(--matrx-print-fg-muted, #374151);border:1px solid var(--matrx-print-border-muted, #d1d5db)}h1,h2,h3,h4,h5,h6{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Helvetica Neue',sans-serif;font-weight:700;line-height:1.3;color:var(--matrx-print-heading, #111827);margin-top:1.6em;margin-bottom:.5em;page-break-after:avoid}h1{font-size:24pt;border-bottom:2px solid var(--matrx-print-border, #e5e7eb);padding-bottom:.3em;margin-top:0}h2{font-size:18pt;border-bottom:1px solid var(--matrx-print-border, #e5e7eb);padding-bottom:.2em}h3{font-size:14pt}p{margin-bottom:.9em;orphans:3;widows:3}a{color:var(--matrx-print-accent, #2563eb);text-decoration:underline;word-break:break-word}ul,ol{margin:.6em 0 .9em 0;padding-left:1.8em}li{margin-bottom:.3em;page-break-inside:avoid}blockquote{margin:1em 0;padding:.7em 1em .7em 1.2em;border-left:4px solid var(--matrx-print-quote-border, #6366f1);background:var(--matrx-print-quote-bg, #f5f3ff);border-radius:0 6px 6px 0;color:var(--matrx-print-fg-muted, #374151);font-style:italic;page-break-inside:avoid}.inline-code{font-family:'JetBrains Mono','Fira Code',monospace;font-size:9.5pt;background:var(--matrx-print-code-bg, #f1f5f9);color:var(--matrx-print-ink, #0f172a);padding:1px 5px;border-radius:4px;border:1px solid var(--matrx-print-line, #e2e8f0)}.code-block-wrapper{position:relative;margin:1em 0 1.2em;border-radius:8px;overflow:hidden;border:1px solid var(--matrx-print-line, #e2e8f0);page-break-inside:avoid}.code-lang{display:block;font-family:-apple-system,sans-serif;font-size:9pt;font-weight:600;color:var(--matrx-print-fg-subtle, #64748b);background:var(--matrx-print-surface, #f8fafc);padding:4px 12px;border-bottom:1px solid var(--matrx-print-line, #e2e8f0);text-transform:uppercase;letter-spacing:.05em}.code-block{margin:0;padding:14px 16px;background:var(--matrx-print-ink, #0f172a);color:var(--matrx-print-line, #e2e8f0);font-family:'JetBrains Mono',monospace;font-size:9pt;line-height:1.6;overflow-x:auto;white-space:pre;tab-size:2}.print-table{width:100%;border-collapse:collapse;margin:1em 0 1.2em;font-size:10pt;page-break-inside:avoid}.print-table th{background:var(--matrx-print-table-head-bg, #1e293b);color:var(--matrx-print-surface, #f8fafc);font-family:-apple-system,sans-serif;font-weight:600;font-size:9.5pt;text-align:left;padding:8px 12px;border:1px solid var(--matrx-print-table-head-border, #334155)}.print-table td{padding:7px 12px;border:1px solid var(--matrx-print-line, #e2e8f0);vertical-align:top}.print-table tr:nth-child(even) td{background:var(--matrx-print-surface, #f8fafc)}hr{border:none;border-top:2px solid var(--matrx-print-border, #e5e7eb);margin:1.5em 0}.print-figure{margin:1em 0 1.2em;page-break-inside:avoid}.print-image{display:block;max-width:100%;height:auto;margin:0 auto;border-radius:6px}.print-figure figcaption{margin-top:.4em;text-align:center;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;font-size:9.5pt;color:var(--matrx-print-fg-subtle, #64748b)}@media print{body{max-width:100%;padding:0;font-size:10.5pt}.print-actions{display:none!important}.code-block,.print-table th,blockquote{color-adjust:exact;-webkit-print-color-adjust:exact;print-color-adjust:exact}a[href]::after{content:\" (\"attr(href)\")\";font-size:9pt;color:var(--matrx-print-fg-subtle, #64748b)}a[href^=\"#\"]::after,a[href^=\"javascript:\"]::after{content:\"\"}h1,h2,h3{page-break-after:avoid}pre,blockquote,table{page-break-inside:avoid}}`;\n\n/**\n * Rules BOTH skins share — appended after the skin sheet by\n * `getMarkdownStylesheet`. Everything the two converters emit identically\n * (page breaks, artifact panels, task boxes, accent/heavy rules, strikethrough,\n * printed flashcard pairs) is styled once here so the skins cannot drift, plus\n * the print hard parts every printed page needs regardless of skin.\n *\n * Page break: on screen a dashed rule labelled \"Page break\" with generous\n * padding — the same idea the chat preview draws; on paper a zero-height\n * element that forces the next content onto a new page.\n */\nexport const MARKDOWN_SHARED_CSS = `\n.matrx-page-break {\n position: relative;\n clear: both;\n height: 0;\n margin: 2.75rem 0;\n border: 0;\n border-top: 2px dashed var(--matrx-print-border-muted, #d1d5db);\n}\n.matrx-page-break::after {\n content: attr(data-label);\n position: absolute;\n left: 50%;\n top: 0;\n transform: translate(-50%, -50%);\n padding: 0 0.75rem;\n background: var(--matrx-print-bg, #ffffff);\n color: var(--matrx-print-fg-subtle, #6b7280);\n font: 600 10px/1.6 -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;\n letter-spacing: 0.08em;\n text-transform: uppercase;\n white-space: nowrap;\n}\n\n.matrx-artifact {\n margin: 1.25em 0;\n border: 1px solid var(--matrx-print-border, #e5e7eb);\n border-radius: 8px;\n overflow: hidden;\n}\n.matrx-artifact-header {\n display: flex;\n align-items: baseline;\n gap: 0.6em;\n padding: 0.45em 0.9em;\n background: var(--matrx-print-surface, #f8fafc);\n border-bottom: 1px solid var(--matrx-print-border, #e5e7eb);\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;\n}\n.matrx-artifact-kind {\n font-size: 0.72em;\n font-weight: 700;\n letter-spacing: 0.06em;\n text-transform: uppercase;\n color: var(--matrx-print-accent, #2563eb);\n}\n.matrx-artifact-title {\n font-weight: 600;\n color: var(--matrx-print-fg, #1a1a1a);\n}\n.matrx-artifact-body {\n padding: 0.8em 0.9em;\n}\n.matrx-artifact-body > :first-child {\n margin-top: 0;\n}\n.matrx-artifact-body > :last-child {\n margin-bottom: 0;\n}\n/* The panel's kind chip already names these languages. */\n.matrx-artifact:is([data-artifact-type=\"html\"], [data-artifact-type=\"react\"], [data-artifact-type=\"svg\"], [data-artifact-type=\"mermaid\"], [data-artifact-type=\"diff\"], [data-artifact-type=\"iframe\"]) .code-lang {\n display: none;\n}\n.matrx-artifact-empty {\n margin: 0;\n font-style: italic;\n color: var(--matrx-print-fg-subtle, #6b7280);\n}\n\nli.matrx-task-item {\n list-style: none;\n}\n/* The box IS the marker — the document skin's custom bullet must not sit on it. */\n:is(.matrx-content-container, .content) li.matrx-task-item::before {\n content: none;\n}\n.matrx-task-box {\n position: relative;\n display: inline-block;\n width: 0.9em;\n height: 0.9em;\n margin: 0 0.5em 0 -1.35em;\n border: 1.5px solid var(--matrx-print-fg-muted, #4a4a4a);\n border-radius: 3px;\n vertical-align: -0.1em;\n}\n.matrx-task-box.is-checked::after {\n content: \"\\\\2713\";\n position: absolute;\n inset: 0;\n font-size: 0.8em;\n font-weight: 700;\n line-height: 1.1em;\n text-align: center;\n color: var(--matrx-print-fg, #1a1a1a);\n}\n\n:is(.matrx-content-container, .content) del {\n color: var(--matrx-print-fg-muted, #4a4a4a);\n text-decoration: line-through;\n}\n:is(.matrx-content-container, .content) hr.matrx-hr-accent {\n height: 2px;\n margin: 1.75em 0;\n border: 0;\n border-radius: 2px;\n background: var(--matrx-print-accent, #2563eb);\n opacity: 0.6;\n}\n:is(.matrx-content-container, .content) hr.matrx-hr-heavy {\n height: 4px;\n margin: 2.25em 0;\n border: 0;\n border-radius: 4px;\n background: var(--matrx-print-accent, #2563eb);\n}\n\n.matrx-flashcards-print {\n margin: 1em 0 1.2em;\n}\n.matrx-fc {\n display: grid;\n grid-template-columns: 1fr 1fr;\n margin-bottom: 0.5em;\n border: 1px solid var(--matrx-print-border, #e5e7eb);\n border-radius: 6px;\n}\n.matrx-fc-front,\n.matrx-fc-back {\n padding: 0.6em 0.8em;\n}\n.matrx-fc-front {\n font-weight: 600;\n border-right: 1px dashed var(--matrx-print-border-muted, #d1d5db);\n}\n.matrx-fc-num {\n display: inline-block;\n min-width: 1.6em;\n font-size: 0.85em;\n color: var(--matrx-print-fg-subtle, #6b7280);\n}\n\n@media print {\n .matrx-page-break {\n margin: 0;\n border: 0;\n break-after: page;\n page-break-after: always;\n }\n .matrx-page-break::after {\n content: none;\n }\n .matrx-page-break + * {\n margin-top: 0;\n }\n\n /* Scoped to the rendered markdown (.matrx-content-container = document\n skin, .content = print window) so a host page that carries this sheet\n — a WordPress theme — keeps its own print rules everywhere else. */\n\n /* Long tables flow across pages: the header row repeats, rows never split. */\n :is(.matrx-content-container, .content) thead {\n display: table-header-group;\n }\n :is(.matrx-content-container, .content) :is(tr, img, figure),\n .matrx-fc,\n .matrx-task-item {\n break-inside: avoid;\n page-break-inside: avoid;\n }\n :is(.matrx-content-container, .content) :is(h1, h2, h3, h4, h5, h6),\n .matrx-artifact-header {\n break-after: avoid;\n page-break-after: avoid;\n break-inside: avoid;\n }\n\n /* Paper cannot scroll: long code lines wrap instead of being cut off. */\n :is(.matrx-content-container, .content) :is(pre, pre code) {\n white-space: pre-wrap !important;\n overflow-wrap: anywhere;\n overflow: visible !important;\n }\n .code-block-wrapper,\n .matrx-artifact {\n overflow: visible;\n }\n :is(.matrx-content-container, .content) img {\n max-width: 100% !important;\n }\n\n .matrx-artifact-header,\n .matrx-task-box {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n\n a.matrx-link[href^=\"http\"]::after {\n content: \" (\" attr(href) \")\";\n font-size: 0.85em;\n color: var(--matrx-print-fg-subtle, #6b7280);\n overflow-wrap: anywhere;\n }\n}\n`;\n\n/**\n * Page geometry + page numbers (\"3 / 12\", bottom centre). Part of the default\n * sheet; `getMarkdownStylesheet({ pageNumbers: false })` leaves it out.\n * Browsers without `@page` margin boxes ignore the numbering and keep the\n * margins.\n */\nexport const MARKDOWN_PAGE_CSS = `\n@page {\n margin: 0.6in 0.65in 0.7in;\n @bottom-center {\n content: counter(page) \" / \" counter(pages);\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;\n font-size: 8pt;\n color: var(--matrx-print-fg-subtle, #6b7280);\n }\n}\n`;\n\n/** `@page` geometry without numbering. */\nexport const MARKDOWN_PAGE_PLAIN_CSS = `\n@page {\n margin: 0.6in 0.65in 0.7in;\n}\n`;\n","/**\n * @ai-matrx/print/directives — the ONE definition of the print directives\n * markdown can carry, shared by every surface that reads markdown.\n *\n * Why a separate, zero-dependency entry: the directive syntax has three\n * readers — this package's two converters (print window / PDF / HTML page),\n * the chat renderer's remark plugin (the on-screen preview), and any editor\n * that inserts one. If each re-derived the regex they would drift the first\n * time someone added an alias. `/markdown` carries ~20KB of stylesheet, so the\n * chat bundle imports the syntax from here instead and pays nothing.\n *\n * ── Page break ────────────────────────────────────────────────────────────\n * A line that is exactly one of these (case-insensitive, surrounding\n * whitespace ignored) forces the next content onto a new printed page:\n *\n * <!-- pagebreak --> ← canonical; invisible in any other renderer\n * <!-- page-break --> <!-- page break --> <!-- newpage -->\n * \\pagebreak \\newpage ← LaTeX / pandoc habit\n * <div style=\"page-break-after: always\"></div> ← Typora / VS Code habit\n * (also `page-break-before`, `break-after: page`, `break-before: page`,\n * and `<div class=\"page-break\"></div>` / `class=\"pagebreak\"`)\n *\n * On screen every surface draws the same idea: a dashed rule labelled\n * \"Page break\" with generous padding. In print it is a zero-height element\n * with `break-after: page`.\n */\n\n/** The form editors insert and docs recommend. */\nexport const PAGE_BREAK_MARKDOWN = \"<!-- pagebreak -->\";\n\n/** The class every surface puts on a rendered page break. */\nexport const PAGE_BREAK_CLASS = \"matrx-page-break\";\n\n/** Screen label for a rendered page break. */\nexport const PAGE_BREAK_LABEL = \"Page break\";\n\nconst COMMENT_FORM = /^<!--\\s*(?:page[\\s_-]?break|new[\\s_-]?page)\\s*-->$/i;\nconst LATEX_FORM = /^\\\\(?:pagebreak|newpage|clearpage)\\s*(?:\\{\\s*\\})?$/i;\nconst DIV_FORM = /^<div\\b([^>]*)>\\s*<\\/div>$|^<div\\b([^>]*)\\/>$/i;\nconst DIV_BREAK_ATTR =\n /(?:page-break-(?:after|before)\\s*:\\s*always|break-(?:after|before)\\s*:\\s*page|class\\s*=\\s*[\"'](?:[^\"']*\\s)?page-?break(?:\\s[^\"']*)?[\"'])/i;\n\n/** Columns of leading indentation (tab = 4, NBSP counts as a space). */\nfunction indentColumns(line: string): number {\n let cols = 0;\n for (const ch of line) {\n if (ch === \" \" || ch === \"\\u00A0\") cols += 1;\n else if (ch === \"\\t\") cols += 4;\n else break;\n }\n return cols;\n}\n\n/**\n * Is this single line a page-break directive? Indented four or more columns\n * it is not — in markdown that is a code block, and every surface must agree.\n */\nexport function isPageBreakLine(line: string): boolean {\n if (indentColumns(line) >= 4) return false;\n const t = line.trim();\n if (t.length < 8 || t.length > 200) return false;\n if (COMMENT_FORM.test(t) || LATEX_FORM.test(t)) return true;\n const div = DIV_FORM.exec(t);\n if (!div) return false;\n return DIV_BREAK_ATTR.test(div[1] ?? div[2] ?? \"\");\n}\n\n// ── Section break ─────────────────────────────────────────────────────────\n//\n// A section break is a page break that can also change the page layout for\n// everything after it (Word's \"Section break (next page)\"):\n//\n// <!-- section --> ← new page, same layout\n// <!-- section: landscape --> ← new page, landscape from here on\n// <!-- section landscape columns=2 --> ← landscape AND two columns\n// <!-- section portrait columns=1 --> ← back to the default layout\n//\n// Recognised words: `landscape` / `portrait`, `columns=N` (or `cols=N`,\n// `N columns`, 1–3). Unknown words are ignored, never an error — the break\n// still happens. Every page-break reader treats a section break as a break.\n\n/** The form editors insert for a plain section break. */\nexport const SECTION_BREAK_MARKDOWN = \"<!-- section -->\";\n\nexport interface SectionBreakDirective {\n /** Absent = inherit the document's orientation. */\n orientation?: \"portrait\" | \"landscape\";\n /** Absent = inherit the document's column count. 1–3. */\n columns?: 1 | 2 | 3;\n}\n\nconst SECTION_FORM = /^<!--\\s*section(?:[\\s_-]?break)?\\b\\s*:?\\s*([^>]*?)\\s*-->$/i;\n\n/** Parse a section-break line; `null` when the line is not one. */\nexport function parseSectionBreakLine(line: string): SectionBreakDirective | null {\n if (indentColumns(line) >= 4) return null;\n const m = SECTION_FORM.exec(line.trim());\n if (!m) return null;\n const words = (m[1] ?? \"\").toLowerCase();\n const out: SectionBreakDirective = {};\n if (/\\blandscape\\b/.test(words)) out.orientation = \"landscape\";\n else if (/\\bportrait\\b/.test(words)) out.orientation = \"portrait\";\n const cols = /\\b(?:columns?|cols?)\\s*[=:]\\s*(\\d)\\b/.exec(words) ?? /\\b(\\d)\\s*[-\\s]?columns?\\b/.exec(words);\n if (cols) {\n const n = Math.min(3, Math.max(1, Number(cols[1])));\n out.columns = n as 1 | 2 | 3;\n }\n return out;\n}\n\n// ── Table of contents / bibliography placement ───────────────────────────\n//\n// `[[toc]]`, `[toc]`, `[TOC]`, `${toc}`, `<!-- toc -->`, `\\tableofcontents`\n// put the table of contents at that spot (otherwise frontmatter `toc: true`\n// puts it at the start). `<!-- bibliography -->`, `[[bibliography]]`,\n// `\\printbibliography` put the reference list there (otherwise it closes the\n// document whenever something is cited).\n\nexport const TOC_MARKDOWN = \"[[toc]]\";\nexport const BIBLIOGRAPHY_MARKDOWN = \"<!-- bibliography -->\";\n\nconst TOC_FORM = /^(?:\\[\\[\\s*toc\\s*\\]\\]|\\[toc\\]|\\$\\{toc\\}|<!--\\s*toc\\s*-->|\\\\tableofcontents)$/i;\nconst BIBLIOGRAPHY_FORM =\n /^(?:\\[\\[\\s*(?:bibliography|references)\\s*\\]\\]|<!--\\s*(?:bibliography|references)\\s*-->|\\\\printbibliography|\\\\bibliography\\{[^}]*\\})$/i;\n\nexport function isTocLine(line: string): boolean {\n return indentColumns(line) < 4 && TOC_FORM.test(line.trim());\n}\n\nexport function isBibliographyLine(line: string): boolean {\n return indentColumns(line) < 4 && BIBLIOGRAPHY_FORM.test(line.trim());\n}\n\n/** Any directive that ends the current printed page (page or section break). */\nexport function isBreakLine(line: string): boolean {\n return isPageBreakLine(line) || parseSectionBreakLine(line) !== null;\n}\n\n/**\n * Split markdown into the pieces that belong on separate pages. Fence-aware:\n * a directive inside a ``` / ~~~ code block is code, not a break. Always\n * returns at least one piece; empty pieces (two breaks in a row, a break at\n * the very start or end) are kept out so no blank page is produced.\n */\nexport function splitAtPageBreaks(markdown: string): string[] {\n const lines = markdown.split(/\\r?\\n/);\n const pieces: string[] = [];\n let current: string[] = [];\n let fence: string | null = null;\n\n for (const line of lines) {\n // Any indent — the converters accept list-nested fences, so must this.\n const fenceMatch = /^\\s*(`{3,}|~{3,})/.exec(line);\n if (fenceMatch) {\n const marker = fenceMatch[1] as string;\n if (fence === null) fence = marker;\n else if (marker[0] === fence[0] && marker.length >= fence.length) fence = null;\n } else if (fence === null && isBreakLine(line)) {\n if (current.join(\"\\n\").trim()) pieces.push(current.join(\"\\n\"));\n current = [];\n continue;\n }\n current.push(line);\n }\n if (current.join(\"\\n\").trim() || pieces.length === 0) pieces.push(current.join(\"\\n\"));\n return pie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;AACd;AAGO,SAAS,sBACd,UACA,MACA,UAAiC,CAAC,GAC1B;AACR,SAAO,SAAS,YACZ,sBAAsB,UAAU,OAAO,IACvC,eAAe,UAAU,OAAO;AACtC;AAoBO,SAAS,uBACd,UACA,UAAyC,CAAC,GAClC;AACR,QAAM,OAAqB,QAAQ,QAAQ;AAC3C,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,UACJ,QAAQ,kBACP,CAAC,OACA;AAAA,IACE;AAAA,IACA;AAAA,IACA,QAAQ,WAAW,EAAE,UAAU,QAAQ,SAAS,IAAI,CAAC;AAAA,EACvD;AACJ,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,MACJ,QAAQ,OACR,sBAAsB;AAAA,IACpB;AAAA,IACA,GAAI,QAAQ,WAAW,SAAY,CAAC,IAAI,EAAE,QAAQ,QAAQ,OAAO;AAAA,IACjE,GAAI,QAAQ,aAAa,SAAY,CAAC,IAAI,EAAE,UAAU,QAAQ,SAAS;AAAA,EACzE,CAAC;AAIH,QAAM,SACJ,QAAQ,oBAAoB,SAAS,YAAY,oBAAoB;AAEvE,QAAM,UAAU,QAAQ,mBACpB,4NACA;AAEJ,SAAO,8IAA0I;AAAA,IAC/I;AAAA,EACF,CAAC;AAAA,SACM,GAAG,GAAG,MAAM;AAAA,QACb,OAAO,wBAAwB,QAAQ;AAC/C;AAcO,SAAS,cACd,UACA,UAAgC,CAAC,GACnB;AACd,QAAM,QAAQ,QAAQ,SAAS;AAC/B,QAAM,MAAM,uBAAuB,UAAU;AAAA,IAC3C,GAAG;AAAA,IACH;AAAA,IACA,kBAAkB,QAAQ,oBAAoB;AAAA,EAChD,CAAC;AACD,SAAO,QAAQ,mBAAmB,SAC9B,gBAAgB,KAAK,KAAK,IAC1B,gBAAgB,KAAK,OAAO,QAAQ,cAAc;AACxD;","names":["import_html_escape","cellAlign"]}
1
+ {"version":3,"sources":["../src/markdown.ts","../src/core.ts","../src/safe-html.ts","../src/markdown-css.ts","../src/directives.ts"],"sourcesContent":["/**\n * @ai-matrx/print/markdown — the SHIPPED DEFAULT markdown→HTML converter and\n * print stylesheet.\n *\n * Why this entry exists: `markdownToPdfBlob` used to declare its converter and\n * its stylesheet as REQUIRED injected ports (\"bring your own converter +\n * stylesheet\"). That is the exact failure THE ALL-INCLUSIVE LAW names — every\n * host had to build the hard half itself, and both hosts that tried ended up\n * with a different converter, a different stylesheet, and a different set of\n * bugs. The package now ships a complete, working default for both ports; the\n * injection seam survives as the OVERRIDE path, never as a prerequisite.\n *\n * Two skins, one vocabulary:\n * • \"document\" — `markdownToHtml` emits `.matrx-*`-classed HTML (tables,\n * nested lists, images, links, code, FAQ blocks, flashcards) and\n * `MARKDOWN_DOCUMENT_CSS` styles it. This is the PDF/publish/WordPress\n * lane.\n * • \"article\" — `markdownToArticleHtml` emits bare semantic tags and\n * `MARKDOWN_ARTICLE_CSS` gives them the serif AI-response look. This is\n * the print-window lane.\n *\n * Nothing here touches `window`/`document` at import time, and nothing here is\n * heavy — but it IS ~20KB of CSS, so `markdownToPdfBlob` reaches it through a\n * lazy `import(\"./markdown\")` and a consumer that never prints markdown pays\n * nothing.\n *\n * NOTHING FAILS SILENTLY: every case where the converter drops input it cannot\n * represent (a malformed flashcard, an empty document) is reported through the\n * optional `onNotice` sink with a concrete remedy, instead of vanishing.\n */\n\nimport { openPrintWindow, type PrintOutcome } from \"./core\";\nimport { escapeHtml } from \"@ai-matrx/kit/html-escape\";\nimport { codeSpanText, findTableEnd, mapCodeRanges, rowCells, tableStartsAt, unescapeCellPipes } from \"@ai-matrx/content-ir/source\";\nimport { PRINT_HTML_SCHEMA, sanitizePrintHtml } from \"./safe-html\";\nimport {\n MARKDOWN_ARTICLE_CSS,\n MARKDOWN_ARTICLE_TOKENS_CSS,\n MARKDOWN_DOCUMENT_CSS,\n MARKDOWN_DOCUMENT_TOKENS_CSS,\n MARKDOWN_PAGE_CSS,\n MARKDOWN_PAGE_PLAIN_CSS,\n MARKDOWN_SHARED_CSS,\n} from \"./markdown-css\";\nimport {\n PAGE_BREAK_CLASS,\n PAGE_BREAK_LABEL,\n PAGE_BREAK_MARKDOWN,\n isBibliographyLine,\n isBreakLine,\n isPageBreakLine,\n isTocLine,\n splitAtPageBreaks,\n} from \"./directives\";\n\nexport {\n MARKDOWN_ARTICLE_CSS,\n MARKDOWN_ARTICLE_TOKENS_CSS,\n MARKDOWN_DOCUMENT_CSS,\n MARKDOWN_DOCUMENT_TOKENS_CSS,\n MARKDOWN_PAGE_CSS,\n MARKDOWN_SHARED_CSS,\n PAGE_BREAK_CLASS,\n PAGE_BREAK_MARKDOWN,\n isPageBreakLine,\n splitAtPageBreaks,\n};\n\n/** Which shipped look to render markdown in. */\nexport type MarkdownSkin = \"document\" | \"article\";\n\n/**\n * A thing the converter could not represent, with the remedy. Announced, never\n * swallowed — a dropped card that says nothing is indistinguishable from a card\n * the author never wrote.\n */\nexport interface MarkdownNotice {\n code: \"flashcard-malformed\" | \"empty-output\" | \"html-stripped\";\n message: string;\n /** What the caller (or the author of the markdown) should do about it. */\n remedy: string;\n}\n\nexport interface MarkdownToHtmlOptions {\n /** Keep `<thinking>` / `<think>` / `<reasoning>` blocks. Default: false. */\n includeThinking?: boolean;\n /** Where dropped/degraded content is announced. */\n onNotice?: (notice: MarkdownNotice) => void;\n}\n\n// ─── thinking-block stripping ────────────────────────────────────────────────\n\n/**\n * Strip `<thinking>` / `<think>` / `<reasoning>` blocks from model output.\n *\n * All three tags are treated as equivalent — a host that handled only\n * `<thinking>` leaked raw reasoning into printed documents the moment a model\n * switched tag names, which is exactly the bug this package exists to stop\n * being re-solved per app.\n */\nexport function removeThinkingContent(content: string): string {\n if (!content) return \"\";\n\n // A hidden section leaves the paragraph structure around it intact: when it\n // sat between blank lines (its own paragraph), the text on either side stays\n // two paragraphs; only a section inside a paragraph collapses to a line\n // break. Replacing every section with one \"\\n\" merged two stored paragraphs\n // into one on screen (verify-RC-B5 round 3 F6).\n const hide = (_match: string, before: string, after: string) =>\n before.length >= 2 || after.length >= 2 ? \"\\n\\n\" : \"\\n\";\n let result = content\n .replace(/(\\n*)<thinking>[\\s\\S]*?<\\/thinking>(\\n*)/gi, hide)\n .replace(/(\\n*)<think>[\\s\\S]*?<\\/think>(\\n*)/gi, hide)\n .replace(/(\\n*)<reasoning>[\\s\\S]*?<\\/reasoning>(\\n*)/gi, hide);\n\n // 3+ newlines collapse to 2 — intentional paragraph breaks survive.\n result = result.replace(/\\n{3,}/g, \"\\n\\n\");\n return result.trim();\n}\n\n/** Does this content carry any reasoning block? */\nexport function hasThinkingContent(content: string): boolean {\n if (!content) return false;\n return /<thinking>|<think>|<reasoning>/i.test(content);\n}\n\n// ─── shared machinery: ONE pre-pass, ONE table/list/rule grammar ────────────\n//\n// Both skins used to carry their own table parser, their own list builder,\n// their own rule regex, and their own (or no) code-fence handling — and they\n// had drifted: the article skin had no nested lists, the document skin ran the\n// emphasis pass over code, neither understood a page break, and both pasted an\n// `<artifact>`'s raw HTML (its <html>, <body> and <script>) straight into the\n// host page. Everything below is shared; a skin supplies only class names and\n// the HTML for a code block / flashcard deck.\n\n// Private-use delimiters: they cannot collide with author text (the input is\n// scrubbed of them first) and no markdown pass treats them as syntax.\nconst TOKEN_OPEN = \"\\uE000\";\nconst TOKEN_CLOSE = \"\\uE001\";\nconst BLOCK_TOKEN = (i: number): string => `${TOKEN_OPEN}B${i}${TOKEN_CLOSE}`;\nconst INLINE_TOKEN = (i: number): string => `${TOKEN_OPEN}I${i}${TOKEN_CLOSE}`;\nconst TOKEN_RE = /\\uE000([BI])(\\d+)\\uE001/g;\nconst PARAGRAPH_WRAPPED_BLOCK_RE = /<p[^>]*>\\s*(\\uE000B\\d+\\uE001)\\s*<\\/p>/g;\n\n/** Converted HTML parked behind a placeholder so later passes cannot touch it. */\nclass Stash {\n private readonly items: string[] = [];\n\n block(html: string): string {\n return BLOCK_TOKEN(this.items.push(html) - 1);\n }\n\n inline(html: string): string {\n return INLINE_TOKEN(this.items.push(html) - 1);\n }\n\n restore(html: string): string {\n // Items can hold tokens of their own (inline code inside a link), so\n // restore until nothing is left — bounded, since items never self-nest.\n let out = html;\n for (let pass = 0; pass < 8 && out.includes(TOKEN_OPEN); pass++) {\n out = out\n .replace(PARAGRAPH_WRAPPED_BLOCK_RE, \"$1\")\n .replace(TOKEN_RE, (_m: string, _k: string, i: string) => this.items[Number(i)] ?? \"\");\n }\n return out;\n }\n}\n\ninterface SkinGrammar {\n skin: MarkdownSkin;\n table: string;\n thead: string;\n tbody: string;\n tr: string;\n th: string;\n td: string;\n ul: string;\n ol: string;\n ulNested: string;\n olNested: string;\n li: string;\n hr: string;\n del: string;\n strong: string;\n em: string;\n inlineCode: string;\n}\n\nconst DOCUMENT_GRAMMAR: SkinGrammar = {\n skin: \"document\",\n table: \"matrx-table\",\n thead: \"matrx-table-head\",\n tbody: \"matrx-table-body\",\n tr: \"matrx-table-row\",\n th: \"matrx-table-header\",\n td: \"matrx-table-cell\",\n ul: \"matrx-list matrx-bullet-list\",\n ol: \"matrx-list matrx-numbered-list\",\n ulNested: \"matrx-list matrx-bullet-list matrx-nested-list\",\n olNested: \"matrx-list matrx-numbered-list matrx-nested-list\",\n li: \"matrx-list-item\",\n hr: \"matrx-hr\",\n del: \"matrx-del\",\n strong: \"matrx-strong\",\n em: \"matrx-em\",\n inlineCode: \"matrx-inline-code\",\n};\n\nconst ARTICLE_GRAMMAR: SkinGrammar = {\n skin: \"article\",\n table: \"print-table\",\n thead: \"\",\n tbody: \"\",\n tr: \"\",\n th: \"\",\n td: \"\",\n ul: \"\",\n ol: \"\",\n ulNested: \"\",\n olNested: \"\",\n li: \"\",\n hr: \"\",\n del: \"\",\n strong: \"\",\n em: \"\",\n inlineCode: \"inline-code\",\n};\n\nconst cls = (...names: string[]): string => {\n const joined = names.filter(Boolean).join(\" \");\n return joined ? ` class=\"${joined}\"` : \"\";\n};\n\n/** The rendered page break — identical markup in both skins. */\nconst PAGE_BREAK_HTML = `<div class=\"${PAGE_BREAK_CLASS}\" role=\"separator\" aria-label=\"${PAGE_BREAK_LABEL}\" data-label=\"${PAGE_BREAK_LABEL}\"></div>`;\n\nfunction codeBlockHtml(g: SkinGrammar, code: string, language: string): string {\n const body = escapeHtml(code.replace(/\\n$/, \"\"));\n const lang = language.trim();\n if (g.skin === \"article\") {\n const label = lang ? `<span class=\"code-lang\">${escapeHtml(lang)}</span>` : \"\";\n return `<div class=\"code-block-wrapper\">${label}<pre class=\"code-block\"><code>${body}</code></pre></div>`;\n }\n const dataLang = lang ? ` data-language=\"${escapeHtml(lang)}\"` : \"\";\n return `<pre class=\"matrx-code-block\"${dataLang}><code class=\"matrx-code\">${body}</code></pre>`;\n}\n\n// ── artifacts ───────────────────────────────────────────────────────────────\n\n/** Artifact types whose body is source code, printed as its source. */\nconst CODE_ARTIFACT_LANGUAGE: Readonly<Record<string, string>> = {\n html: \"html\",\n react: \"tsx\",\n svg: \"svg\",\n mermaid: \"mermaid\",\n diff: \"diff\",\n iframe: \"html\",\n code: \"\",\n};\n\nconst ARTIFACT_TYPE_LABEL: Readonly<Record<string, string>> = {\n html: \"HTML\",\n svg: \"SVG\",\n react: \"React\",\n iframe: \"Embed\",\n};\n\nfunction parseTagAttributes(tag: string): Record<string, string> {\n const attrs: Record<string, string> = {};\n for (const m of tag.matchAll(/([a-zA-Z_][\\w-]*)\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)')/g)) {\n attrs[(m[1] as string).toLowerCase()] = m[2] ?? m[3] ?? \"\";\n }\n return attrs;\n}\n\nfunction artifactLabel(type: string): string {\n if (!type) return \"Artifact\";\n return (\n ARTIFACT_TYPE_LABEL[type] ??\n type.replace(/[-_]+/g, \" \").replace(/\\b\\w/g, (c) => c.toUpperCase())\n );\n}\n\n/**\n * `<artifact …>body</artifact>` envelopes as plain markdown — the SAME rules the\n * skins use for their titled panels, for pipelines that parse markdown (the\n * document writer): source-code types and JSON bodies become fenced code;\n * every other body (tables, checklists, notes) is markdown and is kept as is.\n * Fenced code is never touched.\n */\nexport function unwrapArtifactsToMarkdown(markdown: string): string {\n if (!/<artifact\\b/i.test(markdown)) return markdown;\n return markdown\n .split(/(^[ \\t]*(?:`{3,}|~{3,})[\\s\\S]*?^[ \\t]*(?:`{3,}|~{3,})[ \\t]*$)/m)\n .map((part, i) =>\n i % 2 === 1\n ? part\n : part.replace(/<artifact\\b((?:[^>\"']|\"[^\"]*\"|'[^']*')*?)>([\\s\\S]*?)<\\/artifact>/gi, (_m, tag: string, body: string) => {\n const attrs = parseTagAttributes(tag);\n const type = (attrs.type ?? \"\").toLowerCase();\n const trimmed = body.replace(/^\\n+|\\n+$/g, \"\");\n if (!trimmed.trim()) return \"\";\n if (/^\\s*(`{3,}|~{3,})/.test(trimmed)) return `\\n\\n${trimmed}\\n\\n`;\n if (type in CODE_ARTIFACT_LANGUAGE) {\n const lang = CODE_ARTIFACT_LANGUAGE[type] || attrs.language || attrs.lang || \"\";\n return `\\n\\n\\`\\`\\`\\`${lang}\\n${trimmed}\\n\\`\\`\\`\\`\\n\\n`;\n }\n if (looksLikeJson(trimmed)) return `\\n\\n\\`\\`\\`\\`json\\n${JSON.stringify(JSON.parse(trimmed), null, 2)}\\n\\`\\`\\`\\`\\n\\n`;\n return `\\n\\n${trimmed}\\n\\n`;\n }),\n )\n .join(\"\");\n}\n\nfunction looksLikeJson(body: string): boolean {\n const t = body.trim();\n if (!/^[[{]/.test(t)) return false;\n try {\n JSON.parse(t);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * An `<artifact type id version title>body</artifact>` block, rendered as a\n * titled panel. Source-code artifacts (html, react, svg, mermaid, diff, code)\n * and JSON bodies print as escaped source — never as live markup, which is\n * what used to inject a whole `<html>…<script>` document into the host page.\n * Everything else (checklists, flashcards, research, notes) is markdown and is\n * converted in the same skin.\n */\nfunction artifactHtml(\n g: SkinGrammar,\n attrs: Record<string, string>,\n body: string | null,\n ctx: ConvertContext,\n): string {\n const type = (attrs.type ?? \"\").toLowerCase();\n const title = attrs.title?.trim() ?? \"\";\n const header = `<div class=\"matrx-artifact-header\"><span class=\"matrx-artifact-kind\">${escapeHtml(\n artifactLabel(type),\n )}</span>${title ? `<span class=\"matrx-artifact-title\">${escapeHtml(title)}</span>` : \"\"}</div>`;\n\n let inner: string;\n const trimmed = (body ?? \"\").replace(/^\\n+|\\n+$/g, \"\");\n if (body === null || !trimmed.trim()) {\n inner = `<p class=\"matrx-artifact-empty\">Saved artifact — open it in AI Matrx to view its content.</p>`;\n } else if (/^\\s*(`{3,}|~{3,})/.test(trimmed)) {\n inner = convertBody(g.skin, trimmed, ctx);\n } else if (type in CODE_ARTIFACT_LANGUAGE) {\n inner = codeBlockHtml(g, trimmed, CODE_ARTIFACT_LANGUAGE[type] || attrs.language || attrs.lang || \"\");\n } else if (looksLikeJson(trimmed)) {\n inner = codeBlockHtml(g, JSON.stringify(JSON.parse(trimmed), null, 2), \"json\");\n } else {\n inner = convertBody(g.skin, trimmed, ctx);\n }\n\n return `<section class=\"matrx-artifact\" data-artifact-type=\"${escapeHtml(type || \"artifact\")}\">${header}<div class=\"matrx-artifact-body\">${inner}</div></section>`;\n}\n\n// ── flashcards ──────────────────────────────────────────────────────────────\n\ninterface ParsedCard {\n front: string;\n back: string;\n}\n\nfunction parseFlashcards(content: string, notice: MarkdownToHtmlOptions[\"onNotice\"]): ParsedCard[] {\n const cards: ParsedCard[] = [];\n for (const card of content.split(/\\n*---\\n*/g).map((c) => c.trim()).filter(Boolean)) {\n const front = card.match(/Front:\\s*(.+?)(?=\\n|$)/i)?.[1]?.trim();\n const back = card.match(/Back:\\s*([\\s\\S]+?)$/i)?.[1]?.trim();\n if (!front || !back) {\n // A card that silently disappears from a printed deck is a defect the\n // printer can see and the author cannot.\n notice?.({\n code: \"flashcard-malformed\",\n message: `A flashcard was skipped: it is missing a ${front ? \"Back:\" : \"Front:\"} line.`,\n remedy:\n 'Every card inside <flashcards> needs both \"Front: …\" and \"Back: …\", separated from the next card by ---.',\n });\n continue;\n }\n cards.push({ front, back });\n }\n return cards;\n}\n\nfunction flashcardsHtml(g: SkinGrammar, cards: ParsedCard[], ctx: ConvertContext): string {\n if (g.skin === \"article\") {\n // Paper cannot flip: print the deck as question / answer pairs.\n return `<div class=\"matrx-flashcards-print\">${cards\n .map(\n (c, i) =>\n `<div class=\"matrx-fc\"><div class=\"matrx-fc-front\"><span class=\"matrx-fc-num\">${\n i + 1\n }</span>${c.front}</div><div class=\"matrx-fc-back\">${c.back}</div></div>`,\n )\n .join(\"\")}</div>`;\n }\n let out = '<div class=\"matrx-flashcards-container\">\\n';\n for (const { front, back } of cards) {\n ctx.cardIndex++;\n const cardId = `card${ctx.cardIndex}`;\n out += ` <div class=\"matrx-flashcard\">\n <input type=\"checkbox\" class=\"matrx-flashcard-input\" id=\"${cardId}\">\n <label for=\"${cardId}\" class=\"matrx-flashcard-label\"></label>\n <div class=\"matrx-flashcard-inner\">\n <div class=\"matrx-flashcard-front\">\n <div class=\"matrx-flashcard-content\">\n <strong>${front}</strong>\n </div>\n <span class=\"matrx-flashcard-indicator\">CLICK TO FLIP</span>\n </div>\n <div class=\"matrx-flashcard-back\">\n <div class=\"matrx-flashcard-content\">\n ${back}\n </div>\n <span class=\"matrx-flashcard-indicator\">CLICK TO FLIP</span>\n </div>\n </div>\n </div>\n\n`;\n }\n return `${out}</div>\\n`;\n}\n\n// ── the pre-pass ────────────────────────────────────────────────────────────\n\ninterface ConvertContext {\n options: MarkdownToHtmlOptions;\n depth: number;\n cardIndex: number;\n strippedAnnounced: boolean;\n}\n\nconst FENCE_OPEN = /^(\\s*)(`{3,}|~{3,})\\s*([^\\s`]*)[^`]*$/;\n\n/**\n * Pull every region the markdown passes must not touch out of the text:\n * fenced code, `<artifact>` blocks, page-break directives, `<flashcards>`,\n * inline code — and remove what must never reach a printed page (scripts,\n * styles, a document shell, HTML comments). Returns the text with\n * placeholders; `stash.restore` puts the finished HTML back.\n */\nfunction protectRegions(markdown: string, g: SkinGrammar, stash: Stash, ctx: ConvertContext): string {\n const lines = markdown.split(/\\r?\\n/);\n const out: string[] = [];\n\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i] as string;\n\n // Fenced code (``` or ~~~, any indent, unclosed = to the end).\n const fence = FENCE_OPEN.exec(line);\n if (fence) {\n const marker = fence[2] as string;\n const code: string[] = [];\n let j = i + 1;\n for (; j < lines.length; j++) {\n const close = /^\\s*(`{3,}|~{3,})\\s*$/.exec(lines[j] as string);\n if (close && (close[1] as string)[0] === marker[0] && (close[1] as string).length >= marker.length) break;\n code.push(lines[j] as string);\n }\n const indent = (fence[1] as string).length;\n const dedented = code.map((l) => l.slice(Math.min(indent, l.length - l.trimStart().length)));\n out.push(stash.block(codeBlockHtml(g, dedented.join(\"\\n\"), fence[3] ?? \"\")));\n i = j;\n continue;\n }\n\n if (isBreakLine(line)) {\n out.push(stash.block(PAGE_BREAK_HTML));\n continue;\n }\n // Placement directives only mean something to the document pipeline\n // (@ai-matrx/print/document); a skin never prints them as literal text.\n if (isTocLine(line) || isBibliographyLine(line)) continue;\n\n // <artifact …>body</artifact> — the canonical materialized wire form.\n const open = /^\\s*<artifact\\b((?:[^>\"']|\"[^\"]*\"|'[^']*')*?)(\\/?)>(.*)$/i.exec(line);\n if (open) {\n const attrs = parseTagAttributes(open[1] ?? \"\");\n if (open[2] === \"/\") {\n out.push(stash.block(artifactHtml(g, attrs, null, ctx)));\n if (open[3]?.trim()) out.push(open[3]);\n continue;\n }\n const bodyLines: string[] = [];\n let rest = open[3] ?? \"\";\n let after = \"\";\n let j = i;\n let inFence: string | null = null;\n for (;;) {\n const closeAt = inFence ? -1 : rest.search(/<\\/artifact\\s*>/i);\n if (closeAt >= 0) {\n bodyLines.push(rest.slice(0, closeAt));\n after = rest.slice(closeAt).replace(/^<\\/artifact\\s*>/i, \"\");\n break;\n }\n bodyLines.push(rest);\n const f = /^\\s*(`{3,}|~{3,})/.exec(rest);\n if (f) {\n const m = f[1] as string;\n if (inFence === null) inFence = m;\n else if (m[0] === inFence[0] && m.length >= inFence.length) inFence = null;\n }\n j++;\n if (j >= lines.length) break;\n rest = lines[j] as string;\n }\n const html =\n ctx.depth >= 3\n ? codeBlockHtml(g, bodyLines.join(\"\\n\"), \"\")\n : artifactHtml(g, attrs, bodyLines.join(\"\\n\"), { ...ctx, depth: ctx.depth + 1 });\n out.push(stash.block(html));\n if (after.trim()) out.push(after);\n i = j;\n continue;\n }\n\n // A GFM table — found and split BEFORE any inline pass (THE rule,\n // @ai-matrx/content-ir/source), so code spans, escapes and emphasis are read\n // per cell exactly as GFM reads a cell, and a line that starts another block\n // (`> 8C | …`, `- x`) ends the table and is left for its own pass.\n if (tableStartsAt(lines, i)) {\n const end = findTableEnd(lines, i);\n out.push(stash.block(tableHtml(lines.slice(i, end), g, stash)));\n i = end - 1;\n continue;\n }\n\n out.push(line);\n }\n\n let text = out.join(\"\\n\");\n\n // Inline code FIRST: prose about HTML (\"put it in a `<script>` tag\") must\n // reach the page as code, not be read as markup by the passes below.\n text = text.replace(/`([^`\\n]+)`/g, (_m: string, code: string) =>\n stash.inline(`<code${cls(g.inlineCode)}>${escapeHtml(code)}</code>`),\n );\n // Backslash escapes (CommonMark): `\\*` is a literal `*`, `\\\\` a literal `\\` —\n // never syntax for the passes below, never a printed backslash.\n text = resolveEscapes(text, stash);\n\n // Comments are invisible by definition — page-break comments were already\n // taken above, so what remains is safe to drop without a notice.\n text = text.replace(/<!--[\\s\\S]*?-->/g, \"\");\n\n // A printed page and a published HTML page are not a place to run someone\n // else's script or restyle the host. Paired regions go whole; a stray\n // opening/closing tag goes alone (never \"everything to the end\"). Repeat\n // until stable so a split `<scr<script></script>ipt>` cannot reassemble.\n const before = text;\n for (let pass = 0; pass < 8; pass++) {\n const next = text\n .replace(/<(script|style|head)\\b[^>]*>[\\s\\S]*?<\\/\\1\\s*>/gi, \"\")\n .replace(/<\\/?(?:script|style|head|html|body)\\b[^>]*>/gi, \"\")\n .replace(/<!DOCTYPE[^>]*>/gi, \"\");\n if (next === text) break;\n text = next;\n }\n text = sanitizeRawTags(text);\n // The allow-list (`./safe-html`) is what actually guards the output; this\n // only decides whether the author is told something of theirs was dropped.\n if ((text !== before || hasDisallowedTag(text)) && !ctx.strippedAnnounced) {\n ctx.strippedAnnounced = true;\n ctx.options.onNotice?.({\n code: \"html-stripped\",\n message:\n \"Markup that is not on the safe list (a <script>, <style>, <iframe>, <form>, <object>/<embed>, <meta>, <link>, an on… event handler, inline style, or a javascript: URL) was removed from the rendered copy.\",\n remedy:\n 'To show a full HTML page, put it in an ```html fence or an <artifact type=\"html\"> block — it is printed as its source.',\n });\n }\n\n // Flashcard decks — behind placeholders so no markdown pass re-processes them.\n text = text.replace(/<flashcards>([\\s\\S]*?)<\\/flashcards>/gi, (_m: string, content: string) => {\n const cards = parseFlashcards(content, ctx.options.onNotice);\n return cards.length ? `\\n${stash.block(flashcardsHtml(g, cards, ctx))}\\n` : \"\";\n });\n\n return text;\n}\n\nconst ALLOWED_TAGS = new Set(PRINT_HTML_SCHEMA.tagNames ?? []);\n\n/** A raw tag the allow-list will drop (our own `<flashcards>` island excepted). */\nfunction hasDisallowedTag(text: string): boolean {\n for (const m of text.matchAll(/<\\/?([a-zA-Z][\\w:-]*)/g)) {\n const tag = (m[1] as string).toLowerCase();\n if (tag !== \"flashcards\" && !ALLOWED_TAGS.has(tag)) return true;\n }\n return false;\n}\n\nconst URL_ATTRS = new Set([\"href\", \"src\", \"action\", \"formaction\", \"xlink:href\", \"poster\", \"background\"]);\n\nfunction decodeForSchemeCheck(value: string): string {\n return value\n .replace(/&#x([0-9a-f]+);?/gi, (_m: string, h: string) => String.fromCharCode(parseInt(h, 16)))\n .replace(/&#(\\d+);?/g, (_m: string, d: string) => String.fromCharCode(Number(d)))\n .replace(/&colon;/gi, \":\")\n .replace(/[\\u0000-\\u0020]+/g, \"\")\n .toLowerCase();\n}\n\n/**\n * Author raw HTML survives (the document skin feeds WordPress), but never with\n * an `on…` handler, a `srcdoc`, or a script-scheme URL — entity- and\n * whitespace-obfuscated forms included.\n */\nfunction sanitizeRawTags(text: string): string {\n return text.replace(\n /<([a-zA-Z][\\w:-]*)((?:[^>\"']|\"[^\"]*\"|'[^']*')*)>/g,\n (whole: string, tag: string, rawAttrs: string) => {\n if (!/[=\\s]/.test(rawAttrs)) return whole;\n let changed = false;\n const attrs = rawAttrs.replace(\n /(\\s+)([^\\s\"'=<>/]+)(\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'>]+)))?/g,\n (m: string, _sp: string, name: string, _eq: string, dq?: string, sq?: string, bare?: string) => {\n const lower = name.toLowerCase();\n if (lower.startsWith(\"on\") || lower === \"srcdoc\") {\n changed = true;\n return \"\";\n }\n if (URL_ATTRS.has(lower)) {\n const value = decodeForSchemeCheck(dq ?? sq ?? bare ?? \"\");\n if (/^(?:javascript|vbscript):|^data:text\\/html/.test(value)) {\n changed = true;\n return ` ${name}=\"#\"`;\n }\n }\n return m;\n },\n );\n return changed ? `<${tag}${attrs}>` : whole;\n },\n );\n}\n\n/** A URL that can go in an attribute: no script schemes, no attribute breakout. */\nfunction safeUrl(url: string): string {\n const u = url.trim();\n if (/^(?:javascript|vbscript):|^data:text\\/html/.test(decodeForSchemeCheck(u))) return \"#\";\n return u.replace(/\"/g, \"%22\");\n}\n\n/**\n * Bold / italic / strikethrough, shared by both skins. Underscores follow the\n * CommonMark intraword rule — `snake_case_name` stays literal.\n */\nfunction convertEmphasis(html: string, g: SkinGrammar): string {\n const strong = `<strong${cls(g.strong)}>`;\n const em = `<em${cls(g.em)}>`;\n return html\n .replace(/\\*\\*\\*(?!\\s)(.+?)(?<!\\s)\\*\\*\\*/g, `${strong}${em}$1</em></strong>`)\n .replace(/\\*\\*(?!\\s)(.+?)(?<!\\s)\\*\\*/g, `${strong}$1</strong>`)\n .replace(/(?<![\\w*])\\*(?![\\s*])(.+?)(?<![\\s*])\\*(?![\\w*])/g, `${em}$1</em>`)\n .replace(/(?<![\\w_])___(?!\\s)(.+?)(?<!\\s)___(?![\\w_])/g, `${strong}${em}$1</em></strong>`)\n .replace(/(?<![\\w_])__(?!\\s)(.+?)(?<!\\s)__(?![\\w_])/g, `${strong}$1</strong>`)\n .replace(/(?<![\\w_])_(?![\\s_])(.+?)(?<![\\s_])_(?![\\w_])/g, `${em}$1</em>`)\n .replace(/~~(?!\\s)(.+?)(?<!\\s)~~/g, `<del${cls(g.del)}>$1</del>`);\n}\n\n/** `[text](url)` / `![alt](url \"title\")` with one level of parentheses in the URL. */\nconst LINK_URL = String.raw`((?:[^()\\s]|\\([^()\\s]*\\))+)(?:\\s+\"[^\"]*\")?`;\nconst IMAGE_RE = new RegExp(String.raw`!\\[([^\\]]*)\\]\\(` + LINK_URL + String.raw`\\)`, \"g\");\nconst LINK_RE = new RegExp(String.raw`\\[([^\\]]+)\\]\\(` + LINK_URL + String.raw`\\)`, \"g\");\n\n/** `***` accent rule, `#===` heavy rule, `---` / `___` plain rule. */\nfunction convertRules(html: string, g: SkinGrammar): string {\n return html\n .replace(/^\\s{0,3}#\\s*={3,}\\s*$/gm, `<hr${cls(g.hr, \"matrx-hr-heavy\")}>`)\n .replace(/^\\s{0,3}\\*(?:\\s*\\*){2,}\\s*$/gm, `<hr${cls(g.hr, \"matrx-hr-accent\")}>`)\n .replace(/^\\s{0,3}(?:-\\s*){3,}$/gm, `<hr${cls(g.hr)}>`)\n .replace(/^\\s{0,3}(?:_\\s*){3,}$/gm, `<hr${cls(g.hr)}>`);\n}\n\nfunction cellAlign(separator: string): string {\n const s = separator.trim();\n const left = s.startsWith(\":\");\n const right = s.endsWith(\":\");\n if (left && right) return ' style=\"text-align:center\"';\n if (right) return ' style=\"text-align:right\"';\n return \"\";\n}\n\n/** A CommonMark backslash escape: `\\` before ASCII punctuation. */\nconst ESCAPE_RE = /\\\\([!-\\/:-@[-`{-~])/g;\n\nfunction resolveEscapes(text: string, stash: Stash): string {\n return text.replace(ESCAPE_RE, (_m: string, ch: string) => stash.inline(escapeHtml(ch)));\n}\n\n/**\n * One cell's inline content, read the way GFM reads a cell: the table-level\n * `\\|` → `|` first (inside code spans too, spec example 200), then code spans,\n * backslash escapes, images, links and emphasis — never block syntax.\n */\nfunction cellInlineHtml(cell: string, g: SkinGrammar, stash: Stash): string {\n // Code spans by THE one code-range rule (@ai-matrx/content-ir/source).\n let t = mapCodeRanges(unescapeCellPipes(cell), (range, raw) =>\n range.kind === \"span\" ? stash.inline(`<code${cls(g.inlineCode)}>${escapeHtml(codeSpanText(raw))}</code>`) : raw,\n );\n t = resolveEscapes(t, stash);\n t = t.replace(IMAGE_RE, (_m: string, alt: string, url: string) =>\n stash.inline(`<img class=\"${g.skin === \"document\" ? \"matrx-image\" : \"print-image\"}\" src=\"${safeUrl(url)}\" alt=\"${escapeHtml(alt)}\" />`),\n );\n t = t.replace(LINK_RE, (_m: string, text: string, url: string) =>\n stash.inline(`<a${g.skin === \"document\" ? ' class=\"matrx-link\"' : \"\"} href=\"${safeUrl(url)}\">${convertEmphasis(text, g)}</a>`),\n );\n return convertEmphasis(t, g);\n}\n\n/**\n * A GFM table by THE rule (@ai-matrx/content-ir/source — the rule chat, the\n * editor and the server read tables by): edge pipes optional, `\\|` stays in its\n * cell, every row printed at the header's width (empty cells kept — columns\n * never shift), `:---:` alignment honoured, each cell read as inline content.\n */\nfunction tableHtml(lines: readonly string[], g: SkinGrammar, stash: Stash): string {\n const cellsOf = (line: string) => rowCells(line).map((cell) => cellInlineHtml(cell, g, stash));\n const headers = cellsOf(lines[0] ?? \"\");\n const aligns = rowCells(lines[1] ?? \"\").map(cellAlign);\n const rows = lines.slice(2).map((line) => {\n const cells = cellsOf(line);\n return headers.map((_h, k) => cells[k] ?? \"\");\n });\n let t = `<table${cls(g.table)}>\\n<thead${cls(g.thead)}>\\n<tr${cls(g.tr)}>\\n`;\n headers.forEach((h, k) => {\n t += `<th${cls(g.th)}${aligns[k] ?? \"\"}>${h}</th>\\n`;\n });\n t += \"</tr>\\n</thead>\\n\";\n if (rows.length > 0) {\n t += `<tbody${cls(g.tbody)}>\\n`;\n for (const row of rows) {\n t += `<tr${cls(g.tr)}>\\n`;\n row.forEach((c, k) => {\n t += `<td${cls(g.td)}${aligns[k] ?? \"\"}>${c}</td>\\n`;\n });\n t += \"</tr>\\n\";\n }\n t += \"</tbody>\\n\";\n }\n return `${t}</table>`;\n}\n\ninterface OpenList {\n type: \"ul\" | \"ol\";\n indent: number;\n}\n\n/** Nested ordered/bullet lists — indentation-driven open/close bookkeeping. */\nfunction convertLists(html: string, g: SkinGrammar): string {\n const lines = html.split(\"\\n\");\n let processed = \"\";\n const listStack: OpenList[] = [];\n let lastListItem: \"\" | \"ul\" | \"ol\" = \"\";\n const li = `<li${cls(g.li)}>`;\n\n const top = (): OpenList | undefined => listStack[listStack.length - 1];\n const openTag = (type: \"ul\" | \"ol\", nested: boolean): string =>\n type === \"ol\"\n ? `<ol${cls(nested ? g.olNested : g.ol)}>\\n`\n : `<ul${cls(nested ? g.ulNested : g.ul)}>\\n`;\n\n const popOne = (): void => {\n if (lastListItem) {\n processed += \"</li>\\n\";\n lastListItem = \"\";\n }\n const closing = listStack.pop();\n if (!closing) return;\n processed += closing.type === \"ol\" ? \"</ol>\\n\" : \"</ul>\\n\";\n if (listStack.length > 0) processed += \"</li>\\n\";\n };\n\n const closeDeeperThan = (indent: number): void => {\n while (listStack.length > 0 && (top() as OpenList).indent > indent) popOne();\n };\n\n for (const line of lines) {\n const numbered = line.match(/^(\\s*)(\\d+)[.)]\\s+(.+)$/);\n const bullet = numbered ? null : line.match(/^(\\s*)[*\\-+]\\s+(.+)$/);\n if (numbered || bullet) {\n const type: \"ul\" | \"ol\" = numbered ? \"ol\" : \"ul\";\n const indent = ((numbered ?? bullet) as RegExpMatchArray)[1]?.length ?? 0;\n const content = (numbered ? numbered[3] : (bullet as RegExpMatchArray)[2]) ?? \"\";\n const current = top();\n\n if (current && indent > current.indent) {\n processed += `\\n${openTag(type, true)}`;\n listStack.push({ type, indent });\n } else {\n closeDeeperThan(indent);\n if (lastListItem && top()?.indent === indent) processed += \"</li>\\n\";\n const now = top();\n if (now && now.indent === indent && now.type !== type) {\n // Same depth, other list type: close the old list, open the new one.\n const closing = listStack.pop() as OpenList;\n processed += closing.type === \"ol\" ? \"</ol>\\n\" : \"</ul>\\n\";\n }\n const after = top();\n if (!after || after.indent !== indent || after.type !== type) {\n processed += openTag(type, listStack.length > 0);\n listStack.push({ type, indent });\n }\n }\n processed += `${li}${content}`;\n lastListItem = type;\n continue;\n }\n\n if (line.trim() !== \"\") {\n while (listStack.length > 0) popOne();\n }\n processed += `${line}\\n`;\n }\n while (listStack.length > 0) popOne();\n\n // GFM task items: `- [ ] todo` / `- [x] done` print as real boxes.\n return processed.replace(\n /<li( class=\"([^\"]*)\")?>\\s*\\[([ xX])\\]\\s+/g,\n (_m: string, _c: string | undefined, classes: string | undefined, mark: string) =>\n `<li${cls(classes ?? \"\", \"matrx-task-item\")}><span class=\"matrx-task-box${\n mark === \" \" ? \"\" : \" is-checked\"\n }\" aria-hidden=\"true\"></span>`,\n );\n}\n\nfunction convertBody(skin: MarkdownSkin, markdown: string, ctx: ConvertContext): string {\n return skin === \"article\" ? articleBody(markdown, ctx) : documentBody(markdown, ctx);\n}\n\n/** Author text can never forge a placeholder. */\nfunction scrubTokens(markdown: string): string {\n return markdown.replace(/[\\uE000\\uE001]/g, \"\");\n}\n\nfunction newContext(options: MarkdownToHtmlOptions): ConvertContext {\n return { options, depth: 0, cardIndex: 0, strippedAnnounced: false };\n}\n\n// ─── document skin: markdown → `.matrx-*` HTML ───────────────────────────────\n\n/**\n * markdown → `.matrx-*`-classed HTML wrapped in `.matrx-content-container`.\n *\n * The class vocabulary is deliberate and non-configurable: it is what\n * `MARKDOWN_DOCUMENT_CSS` styles, what the PDF lane renders, and what a\n * WordPress theme targets. Handles (in this order, because the order is the\n * whole trick): the shared pre-pass (code, artifacts, page breaks, flashcards,\n * inline code, unsafe page markup) → rules → images → links → headings →\n * emphasis → nested/task lists → blockquotes → tables → block elements →\n * paragraphs → FAQ promotion → placeholder restoration.\n */\nexport function markdownToHtml(\n markdown: string,\n options: MarkdownToHtmlOptions = {},\n): string {\n if (!markdown) {\n options.onNotice?.({\n code: \"empty-output\",\n message: \"markdownToHtml received an empty string.\",\n remedy: \"Check the content is loaded before converting; nothing was rendered.\",\n });\n return \"\";\n }\n const source = scrubTokens(options.includeThinking ? markdown : removeThinkingContent(markdown));\n return sanitizePrintHtml(\n `<div class=\"matrx-content-container\">${documentBody(source, newContext(options))}</div>`,\n );\n}\n\nfunction documentBody(markdown: string, ctx: ConvertContext): string {\n const g = DOCUMENT_GRAMMAR;\n const stash = new Stash();\n let html = protectRegions(markdown, g, stash, ctx);\n\n // Rules before headings/lists so `---` / `#===` / `***` are never eaten.\n html = convertRules(html, g);\n\n // Images BEFORE links — `![a](u)` is a superset of `[a](u)`.\n html = html.replace(IMAGE_RE, (_m: string, alt: string, url: string) =>\n stash.block(`<img class=\"matrx-image\" src=\"${safeUrl(url)}\" alt=\"${escapeHtml(alt)}\" />`),\n );\n html = html.replace(LINK_RE, (_m: string, text: string, url: string) =>\n stash.inline(`<a class=\"matrx-link\" href=\"${safeUrl(url)}\">${convertEmphasis(text, g)}</a>`),\n );\n\n html = html\n .replace(/^# (.+)$/gm, '<h1 class=\"matrx-h1\">$1</h1>')\n .replace(/^## (.+)$/gm, '<h2 class=\"matrx-h2\">$1</h2>')\n .replace(/^### (.+)$/gm, '<h3 class=\"matrx-h3\">$1</h3>')\n .replace(/^#### (.+)$/gm, '<h4 class=\"matrx-h4\">$1</h4>')\n .replace(/^##### (.+)$/gm, '<h5 class=\"matrx-h5\">$1</h5>')\n .replace(/^###### (.+)$/gm, '<h6 class=\"matrx-h6\">$1</h6>');\n\n // Lists BEFORE emphasis, so a bullet opening with bold (`* **A** and *b*`)\n // is still a bullet.\n html = convertLists(html, g);\n html = convertEmphasis(html, g);\n\n html = html.replace(/^> ?(.+)$/gm, '<blockquote class=\"matrx-blockquote\">$1</blockquote>');\n\n\n html = html\n .replace(/<table>/g, '<table class=\"matrx-table\">')\n .replace(/<thead>/g, '<thead class=\"matrx-table-head\">')\n .replace(/<tbody>/g, '<tbody class=\"matrx-table-body\">')\n .replace(/<tr>/g, '<tr class=\"matrx-table-row\">')\n .replace(/<th>/g, '<th class=\"matrx-table-header\">')\n .replace(/<td>/g, '<td class=\"matrx-table-cell\">');\n\n html = html.replace(/<img(?![^>]*class=)([^>]*)>/g, '<img class=\"matrx-image\"$1>');\n // Author divs join the vocabulary without losing their own class\n // (the old rewrite emitted two class attributes and the browser kept one).\n html = html.replace(/<div\\b([^>]*)>/g, (m: string, attrs: string) => {\n if (/\\bclass=\"matrx-/.test(attrs)) return m;\n if (/\\bclass=\"/.test(attrs)) return `<div${attrs.replace(/\\bclass=\"/, 'class=\"matrx-div ')}>`;\n return `<div class=\"matrx-div\"${attrs}>`;\n });\n html = html.replace(/<span(?![^>]*class=)([^>]*)>/g, '<span class=\"matrx-span\"$1>');\n\n html = html.replace(/^([^<\\n].+)$/gm, '<p class=\"matrx-paragraph\">$1</p>');\n html = html.replace(/<\\/p>\\s*<p class=\"matrx-paragraph\">/g, '</p><p class=\"matrx-paragraph\">');\n\n // Intro paragraph (first <p> after the h1) — before FAQ promotion.\n html = html.replace(\n /(<h1 class=\"matrx-h1\">[\\s\\S]*?<\\/h1>\\s*)<p class=\"matrx-paragraph\">((?:(?!\\uE000B)[\\s\\S])*?)<\\/p>/g,\n '$1<p class=\"matrx-intro\">$2</p>',\n );\n\n // FAQ promotion: bold questions and question headings become FAQ items.\n html = html.replace(\n /^<strong class=\"matrx-strong\">([^<]*\\?[^<]*)<\\/strong>$/gm,\n '<h3 class=\"matrx-h3\">$1</h3>',\n );\n html = html.replace(\n /<p class=\"matrx-paragraph\"><strong class=\"matrx-strong\">([^<]*\\?[^<]*)<\\/strong><\\/p>/g,\n '<h3 class=\"matrx-h3\">$1</h3>',\n );\n html = html.replace(\n /<h3 class=\"matrx-h3\">([^<]*\\?[^<]*)<\\/h3>/g,\n '<div class=\"matrx-faq-question\">$1</div>',\n );\n html = html.replace(\n /(<div class=\"matrx-faq-question\">[^<]*<\\/div>)\\s*(<p class=\"matrx-paragraph\">[\\s\\S]*?<\\/p>)/g,\n '<div class=\"matrx-faq-item\">$1<div class=\"matrx-faq-answer\">$2</div></div>',\n );\n html = html.replace(\n /(<div class=\"matrx-faq-question\">[^<]*<\\/div>)(?!\\s*<div class=\"matrx-faq-answer\">)/g,\n '<div class=\"matrx-faq-item\">$1<div class=\"matrx-faq-answer\"></div></div>',\n );\n html = html.replace(\n /(<div class=\"matrx-faq-answer\">)<p class=\"matrx-paragraph\">([\\s\\S]*?)<\\/p>(<\\/div>)/g,\n \"$1$2$3\",\n );\n\n return stash.restore(html);\n}\n\n// ─── article skin: markdown → bare semantic HTML ─────────────────────────────\n\n/**\n * markdown → bare semantic HTML (`h1`…`h6`, `p`, `ul`/`ol`, `blockquote`,\n * `.code-block-wrapper`, `.print-table`) for the article skin.\n *\n * Code is HTML-escaped in both skins (the shared pre-pass); a print window\n * never re-escapes, so unescaped code would render as markup.\n */\nexport function markdownToArticleHtml(\n markdown: string,\n options: MarkdownToHtmlOptions = {},\n): string {\n if (!markdown) {\n options.onNotice?.({\n code: \"empty-output\",\n message: \"markdownToArticleHtml received an empty string.\",\n remedy: \"Check the content is loaded before printing; nothing was rendered.\",\n });\n return \"\";\n }\n const source = scrubTokens(options.includeThinking ? markdown : removeThinkingContent(markdown));\n return sanitizePrintHtml(articleBody(source, newContext(options)));\n}\n\nfunction articleBody(markdown: string, ctx: ConvertContext): string {\n const g = ARTICLE_GRAMMAR;\n const stash = new Stash();\n let html = protectRegions(markdown, g, stash, ctx);\n html = convertRules(html, g);\n\n // Images BEFORE links — `![a](u)` is a superset of `[a](u)`. Without this\n // pass an image fell through to the link pass and printed as a literal\n // \"!\" followed by a link (chat \"Print\", 2026-09-21).\n html = html.replace(IMAGE_RE, (_m: string, alt: string, url: string) =>\n stash.block(\n `<figure class=\"print-figure\"><img class=\"print-image\" src=\"${safeUrl(url)}\" alt=\"${escapeHtml(alt)}\" />${\n alt ? `<figcaption>${escapeHtml(alt)}</figcaption>` : \"\"\n }</figure>`,\n ),\n );\n html = html.replace(LINK_RE, (_m: string, text: string, url: string) =>\n stash.inline(`<a href=\"${safeUrl(url)}\">${convertEmphasis(text, g)}</a>`),\n );\n\n html = html\n .replace(/^#{6}\\s+(.+)$/gm, \"<h6>$1</h6>\")\n .replace(/^#{5}\\s+(.+)$/gm, \"<h5>$1</h5>\")\n .replace(/^#{4}\\s+(.+)$/gm, \"<h4>$1</h4>\")\n .replace(/^#{3}\\s+(.+)$/gm, \"<h3>$1</h3>\")\n .replace(/^#{2}\\s+(.+)$/gm, \"<h2>$1</h2>\")\n .replace(/^#{1}\\s+(.+)$/gm, \"<h1>$1</h1>\");\n\n html = html.replace(/^> ?(.+)$/gm, \"<blockquote>$1</blockquote>\");\n html = convertLists(html, g);\n html = convertEmphasis(html, g);\n\n html = html\n .split(\"\\n\")\n .map((line) => {\n const t = line.trim();\n if (!t) return \"\";\n if (\n /^<\\/?(h[1-6]|ul|ol|li|blockquote|pre|hr|table|thead|tbody|tr|th|td|div|figure|section)/.test(t) ||\n /^\\uE000B\\d+\\uE001$/.test(t)\n ) {\n return line;\n }\n return `<p>${t}</p>`;\n })\n .join(\"\\n\");\n\n return stash.restore(html).replace(/\\n{3,}/g, \"\\n\\n\").trim();\n}\n\n// ─── stylesheet + document composition ───────────────────────────────────────\n\n/**\n * The Print / Close action bar. The article sheet styles it already; the\n * document sheet is a content stylesheet with no chrome, so this ships beside\n * it — otherwise every host printing document-skin markdown gets two unstyled\n * browser buttons at the top of the page.\n */\nexport const PRINT_ACTIONS_CSS = `\n.print-actions { display: flex; gap: 10px; margin: 0 auto 28px; max-width: 800px; padding: 0 2rem 20px; border-bottom: 2px solid var(--matrx-print-border, #e1e1e1); }\n.print-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 20px; border-radius: 8px; font-size: 13px; font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif; cursor: pointer; border: none; font-weight: 600; }\n.print-btn-primary { background: var(--matrx-print-accent, #667eea); color: var(--matrx-print-bg, #ffffff); }\n.print-btn-secondary { background: var(--matrx-print-surface, #f8f9fa); color: var(--matrx-print-fg-strong, #374151); border: 1px solid var(--matrx-print-border-muted, #d1d5db); }\n@media print { .print-actions { display: none !important; } }\n`;\n\nexport interface MarkdownStylesheetOptions {\n /** Which shipped look. Default: `\"document\"`. */\n skin?: MarkdownSkin;\n /**\n * Host brand overrides — a CSS string appended AFTER the package's default\n * token values, so `:root { --matrx-print-accent: #0f766e; }` wins. Token\n * VALUES are host-owned; the token CONTRACT and the structural CSS are not.\n */\n tokens?: string;\n /** Extra rules appended after everything else. */\n extraCss?: string;\n /**\n * Number printed pages (\"3 / 12\", bottom centre) via `@page` margin boxes.\n * Default: true. Page margins are set either way.\n */\n pageNumbers?: boolean;\n}\n\n/**\n * The complete default stylesheet for a skin: default token values, the\n * structural sheet, the rules both skins share (page breaks, artifacts, task\n * boxes, print hard parts), page geometry, then the host's overrides. Never returns an empty string.\n */\nexport function getMarkdownStylesheet(\n options: MarkdownStylesheetOptions = {},\n): string {\n const skin: MarkdownSkin = options.skin ?? \"document\";\n const base =\n skin === \"article\"\n ? `${MARKDOWN_ARTICLE_TOKENS_CSS}\\n${MARKDOWN_ARTICLE_CSS}`\n : `${MARKDOWN_DOCUMENT_TOKENS_CSS}\\n${MARKDOWN_DOCUMENT_CSS}`;\n const page = options.pageNumbers === false ? MARKDOWN_PAGE_PLAIN_CSS : MARKDOWN_PAGE_CSS;\n return [base, MARKDOWN_SHARED_CSS, page, options.tokens ?? \"\", options.extraCss ?? \"\"]\n .filter((part) => part.trim().length > 0)\n .join(\"\\n\");\n}\n\n/** Convert markdown with the converter that matches a skin. */\nexport function markdownToHtmlForSkin(\n markdown: string,\n skin: MarkdownSkin,\n options: MarkdownToHtmlOptions = {},\n): string {\n return skin === \"article\"\n ? markdownToArticleHtml(markdown, options)\n : markdownToHtml(markdown, options);\n}\n\nexport interface RenderMarkdownDocumentOptions extends MarkdownStylesheetOptions {\n title?: string;\n /** Override the shipped converter. The seam survives; it is no longer required. */\n convertToHtml?: (markdown: string) => string;\n /** Replace the whole stylesheet (not merely the tokens). */\n css?: string;\n onNotice?: (notice: MarkdownNotice) => void;\n /** Include the Print / Close action bar (hidden by `@media print`). */\n withPrintActions?: boolean;\n}\n\n/**\n * markdown → a complete, standalone, styled HTML document string.\n *\n * This is the one composition every lane uses — the print window, the PDF\n * capture host, and \"copy a full HTML page\". A host that builds its own\n * `<!DOCTYPE html>` wrapper around package CSS is re-implementing this.\n */\nexport function renderMarkdownDocument(\n markdown: string,\n options: RenderMarkdownDocumentOptions = {},\n): string {\n const skin: MarkdownSkin = options.skin ?? \"document\";\n const title = options.title ?? \"AI Response\";\n const convert =\n options.convertToHtml ??\n ((md: string) =>\n markdownToHtmlForSkin(\n md,\n skin,\n options.onNotice ? { onNotice: options.onNotice } : {},\n ));\n const bodyHtml = convert(markdown);\n const css =\n options.css ??\n getMarkdownStylesheet({\n skin,\n ...(options.tokens === undefined ? {} : { tokens: options.tokens }),\n ...(options.extraCss === undefined ? {} : { extraCss: options.extraCss }),\n });\n\n // The article sheet already styles the action bar; the document sheet is a\n // pure content stylesheet, so it gets the shared chrome appended.\n const chrome =\n options.withPrintActions && skin !== \"article\" ? PRINT_ACTIONS_CSS : \"\";\n\n const actions = options.withPrintActions\n ? '<div class=\"print-actions\"><button class=\"print-btn print-btn-primary\" onclick=\"window.print()\">Print / Save as PDF</button><button class=\"print-btn print-btn-secondary\" onclick=\"window.close()\">Close</button></div>'\n : \"\";\n\n return `<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1.0\"><title>${escapeHtml(\n title,\n )}</title>\n<style>${css}${chrome}</style></head>\n<body>${actions}<div class=\"content\">${bodyHtml}</div></body></html>`;\n}\n\nexport interface PrintMarkdownOptions extends RenderMarkdownDocumentOptions {\n /** Window features for the print window. */\n windowFeatures?: string;\n}\n\n/**\n * Open a print window for a markdown string, in one call.\n *\n * Returns the `PrintOutcome` so the host can tell the user when the popup was\n * blocked and the `.html` download fallback fired instead — a silent fallback\n * is indistinguishable from \"print did nothing\".\n */\nexport function printMarkdown(\n markdown: string,\n options: PrintMarkdownOptions = {},\n): PrintOutcome {\n const title = options.title ?? \"AI Response\";\n const doc = renderMarkdownDocument(markdown, {\n ...options,\n title,\n withPrintActions: options.withPrintActions ?? true,\n });\n return options.windowFeatures === undefined\n ? openPrintWindow(doc, title)\n : openPrintWindow(doc, title, options.windowFeatures);\n}\n","/**\n * @ai-matrx/print/core — the Block Print contract & print-window composition.\n *\n * Ported VERBATIM from matrx-frontend `lib/block-print/block-print-utils.ts`\n * (2026-08-29 state, including the `number` and `select` PrintSetting types the\n * commerce label lane added). Zero dependencies; touches `window` only at call\n * time, so the module stays import-inert and RSC-safe.\n *\n * BlockPrinter is the only interface a host system needs to know about.\n * Each printable unit exports its own BlockPrinter alongside its render\n * component; host code only ever calls print(data, variantId, settings).\n *\n * `buildFitTextScript` is the ONE auto-shrink script (the flashcards\n * FIT_TEXT pattern, parameterized by selector so the label lane shares it).\n */\n\n// THE ONE HTML escaper (duplication census row 14). Nine copies of\n// `escapeHtml` were live across the fleet and THEY DID NOT ESCAPE THE SAME\n// CHARACTERS — a string safe through one was an attribute break-out through\n// another. It moved to `@ai-matrx/kit/html-escape` with a decided character\n// set: an HTML escaper must not require this package's jspdf + html2canvas\n// graph. Not re-exported from here; import `@ai-matrx/kit/html-escape`.\nimport { escapeHtml } from \"@ai-matrx/kit/html-escape\";\n\n// ─── Contract ────────────────────────────────────────────────────────────────\n\nexport interface PrintVariant {\n id: string;\n label: string;\n description?: string;\n}\n\n/**\n * A single user-configurable setting shown in the print dialog.\n * Extend the discriminated union for new control types\n * without breaking existing printers.\n */\nexport type PrintSetting =\n | {\n type: \"boolean\";\n id: string;\n label: string;\n description?: string;\n /** Default value shown when the dialog first opens */\n defaultValue: boolean;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n }\n | {\n /**\n * A numeric \"from → to\" range control, rendered as two small number inputs.\n * Writes two entries into the resolved PrintSettings map — one under fromId,\n * one under toId. Printers interpret 0 (or missing) as \"no bound\" by convention.\n */\n type: \"range\";\n /** Stable id used as React key — not written to the settings map */\n id: string;\n label: string;\n description?: string;\n /** Settings map key for the lower bound value */\n fromId: string;\n /** Settings map key for the upper bound value */\n toId: string;\n defaultFrom: number;\n defaultTo: number;\n /** Minimum accepted value for each input (inclusive). Default 0. */\n min?: number;\n /** Placeholder shown when the input is empty (0). Default \"start\" / \"end\". */\n fromPlaceholder?: string;\n toPlaceholder?: string;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n }\n | {\n /** A single numeric input (e.g. \"start at label #\", \"copies\"). */\n type: \"number\";\n id: string;\n label: string;\n description?: string;\n defaultValue: number;\n /** Minimum accepted value (inclusive). Default 0. */\n min?: number;\n /** Maximum accepted value (inclusive). Omit = unbounded. */\n max?: number;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n }\n | {\n /** A one-of-N choice rendered as a compact segmented row. */\n type: \"select\";\n id: string;\n label: string;\n description?: string;\n options: { value: string; label: string }[];\n defaultValue: string;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n };\n\n/** A resolved map of setting id → current value, passed to print(). */\nexport type PrintSettings = Record<string, boolean | string | number>;\n\n/**\n * The self-contained print capability that each block can export.\n * Host code only ever calls print(data, variantId, settings) — it never inspects internals.\n */\nexport interface BlockPrinter {\n /** Tooltip / aria-label for the print button in the block header */\n label: string;\n\n /**\n * Variants offered to the user before printing.\n * Empty array = no options dialog shown; prints immediately with defaults.\n */\n variants: PrintVariant[];\n\n /**\n * Optional user-configurable settings shown below the variant picker.\n * Omit entirely if the block has no configurable settings.\n */\n settings?: PrintSetting[];\n\n /**\n * Execute the print.\n * data — the block's structured data (serverData or parsed content)\n * variantId — which variant was chosen (undefined = default / no variants)\n * settings — resolved setting values chosen by the user\n *\n * MAY resolve to a PrintOutcome (\"opened\" | \"downloaded\") so the host can\n * tell the user when the popup-blocked download fallback fired; `void`\n * stays legal for printers that don't go through a print window.\n */\n print: (\n data: unknown,\n variantId?: string,\n settings?: PrintSettings,\n ) => void | PrintOutcome | Promise<void | PrintOutcome>;\n}\n\n// ─── Shared Utilities ─────────────────────────────────────────────────────────\n\nconst PRINT_STYLES = `\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;\n font-size: 11pt;\n line-height: 1.6;\n color: #1a1a1a;\n background: #fff;\n max-width: 860px;\n margin: 0 auto;\n padding: 28px 36px;\n }\n\n .print-actions {\n display: flex;\n gap: 10px;\n margin-bottom: 24px;\n padding-bottom: 18px;\n border-bottom: 2px solid #e5e7eb;\n }\n\n .print-btn {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n padding: 8px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-family: inherit;\n cursor: pointer;\n border: none;\n font-weight: 600;\n }\n\n .print-btn-primary { background: #2563eb; color: #fff; }\n .print-btn-secondary { background: #f3f4f6; color: #374151; border: 1px solid #d1d5db; }\n\n h1 { font-size: 22pt; font-weight: 700; margin-bottom: 0.5em; }\n h2 { font-size: 16pt; font-weight: 700; margin: 1.2em 0 0.4em; border-bottom: 1px solid #e5e7eb; padding-bottom: 0.2em; }\n h3 { font-size: 13pt; font-weight: 600; margin: 1em 0 0.3em; }\n p { margin-bottom: 0.7em; }\n\n table {\n width: 100%;\n border-collapse: collapse;\n margin: 1em 0;\n font-size: 10pt;\n }\n th {\n background: #1e293b;\n color: #f8fafc;\n font-weight: 600;\n text-align: left;\n padding: 7px 12px;\n border: 1px solid #334155;\n }\n td {\n padding: 6px 12px;\n border: 1px solid #e2e8f0;\n vertical-align: top;\n }\n tr:nth-child(even) td { background: #f8fafc; }\n\n @media print {\n body { max-width: 100%; padding: 0; }\n .print-actions { display: none !important; }\n th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }\n }\n`;\n\n/**\n * Wrap body HTML in a complete, styled print document.\n */\nexport function buildPrintDocument(\n bodyHtml: string,\n title = \"AI Response\",\n extraStyles = \"\",\n): string {\n return `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>${escapeHtml(title)}</title>\n <style>\n${PRINT_STYLES}\n${extraStyles}\n </style>\n</head>\n<body>\n <div class=\"print-actions\">\n <button class=\"print-btn print-btn-primary\" onclick=\"window.print()\">Print / Save as PDF</button>\n <button class=\"print-btn print-btn-secondary\" onclick=\"window.close()\">Close</button>\n </div>\n <div class=\"content\">\n${bodyHtml}\n </div>\n</body>\n</html>`;\n}\n\n/**\n * How a print request actually reached the user.\n *\n * \"opened\" — a print window/tab was opened and the document written into it.\n * \"downloaded\" — the popup was blocked, so the document was downloaded as an\n * .html file instead (the contract's fallback). Hosts SHOULD\n * surface this to the user (e.g. a toast saying the print file\n * was downloaded) — a blocked popup plus a silent download is\n * indistinguishable from \"nothing happened\", which is exactly\n * how QA filed it (2026-08-30, F5/F6/F8).\n */\nexport type PrintOutcome = \"opened\" | \"downloaded\";\n\n/**\n * Open a new browser window and write a complete HTML document into it.\n * Falls back to downloading an .html file if the popup is blocked.\n *\n * Returns which path was taken so callers can tell the user when the\n * fallback fired. `windowFeatures` customizes the popup geometry (the\n * flashcards fixed-geometry variants pass a wider window).\n */\nexport function openPrintWindow(\n htmlDocument: string,\n filename = \"print\",\n windowFeatures = \"width=920,height=720,scrollbars=yes\",\n): PrintOutcome {\n const win = window.open(\"\", \"_blank\", windowFeatures);\n if (!win) {\n // Popup blocked — fall back to file download\n const blob = new Blob([htmlDocument], { type: \"text/html;charset=utf-8\" });\n const url = URL.createObjectURL(blob);\n const a = document.createElement(\"a\");\n a.href = url;\n a.download = `${filename.replace(/\\s+/g, \"-\").toLowerCase()}.html`;\n document.body.appendChild(a);\n a.click();\n document.body.removeChild(a);\n // Revoke on a macrotask so the browser has started the blob fetch —\n // a synchronous revoke races the download in some engines.\n setTimeout(() => URL.revokeObjectURL(url), 0);\n return \"downloaded\";\n }\n win.document.open();\n win.document.write(htmlDocument);\n win.document.close();\n return \"opened\";\n}\n\n/**\n * Shorthand: build the document and open it in one call.\n * Returns the same PrintOutcome as openPrintWindow.\n */\nexport function printHtmlContent(\n bodyHtml: string,\n title = \"AI Response\",\n extraStyles = \"\",\n): PrintOutcome {\n const doc = buildPrintDocument(bodyHtml, title, extraStyles);\n return openPrintWindow(doc, title);\n}\n\n/**\n * Build the auto-shrink script that runs INSIDE a printed window: for every\n * element matching each selector, its font-size is reduced (0.5pt steps, 6pt\n * floor) until it fits its parent element's box. This is the flashcards\n * FIT_TEXT behavior verbatim, parameterized by selector so every lane\n * (flashcards card text, Avery text, label captions) shares the ONE loop.\n *\n * Pass the same selectors the original used to get byte-identical behavior:\n * flashcards passes `[\".card-text .card-text-inner\", \".avery-text-wrap .avery-text\"]`.\n */\nexport function buildFitTextScript(selectors: readonly string[]): string {\n const selectorsJson = JSON.stringify([...selectors]);\n return `\n<script>\n(function() {\n function fitText(el, container) {\n // container is the bounding box we must fit inside\n var maxW = container.clientWidth;\n var maxH = container.clientHeight;\n var size = parseFloat(window.getComputedStyle(el).fontSize);\n var minSize = 6;\n // Give the element a chance to reflow at current size before measuring\n el.style.fontSize = size + \"pt\";\n while (size > minSize && (el.scrollWidth > maxW + 1 || el.scrollHeight > maxH + 1)) {\n size -= 0.5;\n el.style.fontSize = size + \"pt\";\n }\n }\n function runAll() {\n var selectors = ${selectorsJson};\n for (var s = 0; s < selectors.length; s++) {\n var els = document.querySelectorAll(selectors[s]);\n for (var i = 0; i < els.length; i++) {\n fitText(els[i], els[i].parentElement);\n }\n }\n }\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", runAll);\n } else {\n // document.write pages may already be loaded\n setTimeout(runAll, 0);\n }\n})();\n</script>`;\n}\n\n","/**\n * @ai-matrx/print/safe-html — THE allow-list every Markdown→HTML string this\n * package hands out goes through.\n *\n * Why an allow-list: the regex converter (`markdownToHtml` /\n * `markdownToArticleHtml`) lets author raw HTML through so a document can feed\n * WordPress. Its old guard was a block-list (script, style, on… handlers,\n * javascript: URLs) and everything nobody listed — `<iframe>`, `<form>`,\n * `<meta http-equiv=refresh>`, `<object>`/`<embed>`, `<base>`, `<link>`,\n * inline `style` — reached the clipboard, the downloaded page and the preview.\n * Now a tag or attribute survives only when it is listed here.\n *\n * Sync and DOM-free (parse5 via hast), so it runs in Node, workers, the\n * extension service worker and Tauri alike.\n *\n * Two schemas:\n * • `SAFE_HTML_SCHEMA` — GitHub's rendering rules (hast-util-sanitize's\n * default schema) with no id clobber-prefixing and the \"drop the element\n * AND its text\" list for elements whose text is not prose. For any host\n * that renders plain semantic HTML (email bodies, CMS drafts).\n * • `PRINT_HTML_SCHEMA` — the same, plus exactly the vocabulary print's own\n * converters emit: `matrx-*` / `print-*` / `code-*` / `doc-*` classes,\n * table-cell alignment, the flashcard checkbox + label, figures, and the\n * page-break separator's data/aria attributes.\n */\n\nimport { fromHtml } from \"hast-util-from-html\";\nimport { defaultSchema, sanitize, type Schema } from \"hast-util-sanitize\";\nimport { toHtml } from \"hast-util-to-html\";\nimport type { Root } from \"hast\";\n\ntype Attributes = NonNullable<Schema[\"attributes\"]>;\ntype AttributeList = Attributes[string];\n\n/** Elements removed together with their content (their text is not prose). */\nconst STRIP_WITH_CONTENT = [\n \"script\",\n \"style\",\n \"noscript\",\n \"template\",\n \"iframe\",\n \"object\",\n \"embed\",\n \"textarea\",\n \"select\",\n \"head\",\n \"title\",\n];\n\n/** Never allowed, whatever a schema extension adds. */\nexport const FORBIDDEN_TAGS: readonly string[] = [\n ...STRIP_WITH_CONTENT,\n \"form\",\n \"meta\",\n \"base\",\n \"link\",\n \"frame\",\n \"frameset\",\n \"applet\",\n \"button\",\n \"svg\",\n \"math\",\n];\n\nconst baseAttributes = defaultSchema.attributes ?? {};\n\nexport const SAFE_HTML_SCHEMA: Schema = {\n ...defaultSchema,\n tagNames: (defaultSchema.tagNames ?? []).filter((t) => !FORBIDDEN_TAGS.includes(t)),\n strip: STRIP_WITH_CONTENT,\n // Authored anchors keep their names; the GitHub `user-content-` rewrite\n // would also break `<label for>` → `<input id>` pairs.\n clobberPrefix: \"\",\n clobber: [],\n};\n\n/** Class tokens print's converters emit. Author classes outside these are dropped. */\nconst PRINT_CLASS = /^(?:(?:matrx|print|code|doc|language)-[\\w-]*|inline-code|is-checked)$/;\n\n/**\n * A tag's own `className` definition wins over `'*'` (and returns an empty\n * list rather than falling through), so the print class pattern is merged into\n * every definition that names `className`, and added where none does.\n */\nfunction withPrintClasses(defs: AttributeList = []): AttributeList {\n let found = false;\n const out = defs.map((d) => {\n if (Array.isArray(d) && d[0] === \"className\") {\n found = true;\n return [...d, PRINT_CLASS] as unknown as typeof d;\n }\n return d;\n });\n return found ? out : [...out, [\"className\", PRINT_CLASS]];\n}\n\nconst printAttributes: Attributes = Object.fromEntries(\n Object.entries(baseAttributes).map(([tag, defs]) => [tag, withPrintClasses(defs)]),\n);\n\nconst cellAlign = [\"style\", /^text-align:\\s*(?:left|center|right);?$/] as const;\n\nexport const PRINT_HTML_SCHEMA: Schema = {\n ...SAFE_HTML_SCHEMA,\n tagNames: [\n ...new Set([...(SAFE_HTML_SCHEMA.tagNames ?? []), \"section\", \"figure\", \"figcaption\", \"label\"]),\n ],\n attributes: {\n ...printAttributes,\n \"*\": [\n ...(baseAttributes[\"*\"] ?? []),\n [\"className\", PRINT_CLASS],\n \"role\",\n \"ariaLabel\",\n \"ariaHidden\",\n \"dataLabel\",\n \"dataLanguage\",\n \"dataArtifactType\",\n ],\n // Table-cell alignment is the one inline style the converter writes.\n td: withPrintClasses([...(baseAttributes[\"td\"] ?? []), [...cellAlign]]),\n th: withPrintClasses([...(baseAttributes[\"th\"] ?? []), [...cellAlign]]),\n // The flashcard flip is a checkbox + label pair (GitHub forces `disabled`).\n input: withPrintClasses([[\"type\", \"checkbox\"], \"checked\"]),\n label: withPrintClasses([\"htmlFor\"]),\n },\n required: { input: { type: \"checkbox\" } },\n protocols: {\n ...defaultSchema.protocols,\n href: [...(defaultSchema.protocols?.href ?? []), \"tel\"],\n // Embedded images (`data:image/png;base64,…`) — an <img> never runs script.\n src: [...(defaultSchema.protocols?.src ?? []), \"data\"],\n },\n};\n\n/** Sanitize an HTML fragment against an allow-list (default: `SAFE_HTML_SCHEMA`). */\nexport function sanitizeHtmlFragment(html: string, schema: Schema = SAFE_HTML_SCHEMA): string {\n if (!html) return \"\";\n const tree = sanitize(fromHtml(html, { fragment: true }), schema) as Root;\n return toHtml(tree, { characterReferences: { useNamedReferences: true } });\n}\n\n/** Sanitize the output of print's own converters (keeps the `.matrx-*` vocabulary). */\nexport function sanitizePrintHtml(html: string): string {\n return sanitizeHtmlFragment(html, PRINT_HTML_SCHEMA);\n}\n\nexport type { Schema as SafeHtmlSchema };\n\n/**\n * MathML from the TeX typesetter. TeX is author input, and MathJax's `html`,\n * `bbox` and `\\mmlToken` commands turn it into attributes (`\\href{javascript:…}`\n * → `href`, `\\style{position:fixed…}` / `\\bbox[position:fixed]` → `style`).\n * Only presentation MathML elements and their layout attributes survive.\n */\nconst MATHML_TAGS = [\n \"math\", \"maction\", \"annotation\", \"menclose\", \"merror\", \"mfrac\", \"mglyph\", \"mi\",\n \"mlabeledtr\", \"mmultiscripts\", \"mn\", \"mo\", \"mover\", \"mpadded\", \"mphantom\", \"mprescripts\", \"none\",\n \"mroot\", \"mrow\", \"ms\", \"mspace\", \"msqrt\", \"mstyle\", \"msub\", \"msubsup\", \"msup\", \"mtable\", \"mtd\",\n \"mtext\", \"mtr\", \"munder\", \"munderover\", \"semantics\",\n];\n\nconst MATHML_ATTRIBUTES = [\n \"xmlns\", \"display\", \"displaystyle\", \"mathvariant\", \"mathsize\", \"mathcolor\", \"mathbackground\",\n \"scriptlevel\", \"dir\", \"fence\", \"form\", \"largeop\", \"lspace\", \"rspace\", \"movablelimits\",\n \"separator\", \"stretchy\", \"symmetric\", \"maxsize\", \"minsize\", \"accent\", \"accentunder\", \"align\",\n \"columnalign\", \"rowalign\", \"columnspacing\", \"rowspacing\", \"columnlines\", \"rowlines\", \"frame\",\n \"framespacing\", \"equalrows\", \"equalcolumns\", \"linethickness\", \"numalign\", \"denomalign\",\n \"bevelled\", \"notation\", \"width\", \"height\", \"depth\", \"voffset\", \"lquote\", \"rquote\", \"columnspan\",\n \"rowspan\", \"encoding\", \"open\", \"close\", \"separators\", \"actiontype\", \"selection\", \"mslinebreak\",\n \"linebreak\", \"indentalign\", \"data*\",\n];\n\nexport const MATHML_SCHEMA: Schema = {\n tagNames: MATHML_TAGS,\n attributes: { \"*\": MATHML_ATTRIBUTES },\n strip: [\"script\", \"style\"],\n clobberPrefix: \"\",\n clobber: [],\n protocols: {},\n};\n\n/** Sanitize a typeset MathML string (keeps layout, drops links and styles). */\nexport function sanitizeMathml(mathml: string): string {\n return sanitizeHtmlFragment(mathml, MATHML_SCHEMA);\n}\n\n/**\n * SVG from the TeX typesetter (PDF display math, LIST T26). MathJax's `\\href`,\n * `\\style`, `\\class`, `\\cssId`, `\\bbox[…]` and `\\mmlToken[…]` reach the SVG as\n * `<a href=\"javascript:…\">`, `style=\"position:fixed…\"`, `class`, `id`. The PDF\n * writer draws this SVG, and any host that shows it would too, so only the\n * drawing vocabulary survives: shapes, paths, text, transforms and paint. A\n * link wrapper is unwrapped (its glyphs stay), everything else is dropped.\n */\nconst MATH_SVG_TAGS = [\"svg\", \"g\", \"path\", \"rect\", \"line\", \"polyline\", \"polygon\", \"circle\", \"ellipse\", \"text\", \"title\", \"desc\"];\n\nconst MATH_SVG_ATTRIBUTES = [\n \"xmlns\", \"width\", \"height\", \"viewBox\", \"role\", \"focusable\", \"ariaHidden\", \"ariaLabel\",\n \"stroke\", \"fill\", \"strokeWidth\", \"strokeLinecap\", \"strokeLinejoin\", \"transform\", \"d\",\n \"x\", \"y\", \"x1\", \"y1\", \"x2\", \"y2\", \"points\", \"cx\", \"cy\", \"r\", \"rx\", \"ry\",\n \"dataMmlNode\", \"dataC\",\n];\n\nexport const MATH_SVG_SCHEMA: Schema = {\n tagNames: MATH_SVG_TAGS,\n attributes: { \"*\": MATH_SVG_ATTRIBUTES },\n strip: [\"script\", \"style\", \"foreignObject\"],\n clobberPrefix: \"\",\n clobber: [],\n protocols: {},\n};\n\n/** Sanitize a typeset math SVG (keeps the drawing, drops links, styles, classes and ids). */\nexport function sanitizeMathSvg(svg: string): string {\n return sanitizeHtmlFragment(svg, MATH_SVG_SCHEMA);\n}\n\n/**\n * THE final allow-list of the one Markdown→HTML engine (`@ai-matrx/print/\n * markdown-html`, CONTRACT §1.9): print's own vocabulary plus typeset MathML\n * (MathML elements carry only the MathML layout attributes), and — for the\n * inline clipboard skin only — `style` attributes whose value is EXACTLY one\n * the engine itself wrote (`inlineStyles`). An author can never reach a style.\n */\nexport function engineHtmlSchema(inlineStyles: readonly string[] = []): Schema {\n const exact = inlineStyles.length\n ? [new RegExp(`^(?:${[...new Set(inlineStyles)].map((s) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")).join(\"|\")})$`)]\n : [];\n const mathAttributes = Object.fromEntries(MATHML_TAGS.map((tag) => [tag, MATHML_ATTRIBUTES]));\n const printAttrs = PRINT_HTML_SCHEMA.attributes ?? {};\n const styled = (defs: AttributeList = []): AttributeList =>\n exact.length ? [...defs.filter((d) => !(Array.isArray(d) && d[0] === \"style\")), [\"style\", ...exact]] : defs;\n const attributes: Attributes = { ...printAttrs, ...mathAttributes };\n if (exact.length) {\n for (const tag of new Set([...(PRINT_HTML_SCHEMA.tagNames ?? []), \"div\", \"span\"])) {\n if (MATHML_TAGS.includes(tag)) continue;\n attributes[tag] = styled(printAttrs[tag] ?? []);\n }\n // Table cells keep their alignment AND the skin's cell style (the skin writes both into one value).\n }\n return {\n ...PRINT_HTML_SCHEMA,\n tagNames: [...new Set([...(PRINT_HTML_SCHEMA.tagNames ?? []), ...MATHML_TAGS])],\n attributes,\n };\n}\n\n/** Sanitize the engine's output (see `engineHtmlSchema`). */\nexport function sanitizeEngineHtml(html: string, inlineStyles: readonly string[] = []): string {\n return sanitizeHtmlFragment(html, engineHtmlSchema(inlineStyles));\n}\n","/**\n * Default print stylesheets for `@ai-matrx/print/markdown`.\n *\n * Two skins, ONE semantic-token vocabulary (C26 — structural CSS ships in the\n * package, the token CONTRACT is enforced, token VALUES are host-overridable):\n *\n * \"document\" — the `.matrx-*` content sheet. What `markdownToHtml` emits,\n * what the markdown→PDF lane renders, and what pastes straight\n * into a WordPress theme.\n * \"article\" — the serif AI-response sheet used by the print-window lane.\n *\n * Every colour is `var(--matrx-print-<role>, <default>)`. The inline fallback\n * is what makes the drop-in test pass in a fresh, unthemed app; the `:root`\n * block is the shipped default token-values sheet a host overrides by\n * appending its own `:root` rule (`getMarkdownStylesheet({ tokens })`).\n *\n * Both sheets carry the print hard parts — `@media print`, page-break\n * avoidance, orphans/widows, `print-color-adjust` — so no host re-derives them.\n *\n * THIS FILE IS THE SOURCE OF TRUTH. It was seeded once from the two host\n * stylesheets it replaced (matrx-frontend's WordPress sheet and its serif\n * print sheet, both deleted in the same session); there is no generator to\n * re-run and no upstream to diff against. Edit it here.\n *\n * DO NOT hand-edit colour literals back in: a hardcoded colour in package CSS\n * is a C26 violation. Add a role to the vocabulary instead.\n */\n\n/** Default token VALUES for the document skin. */\nexport const MARKDOWN_DOCUMENT_TOKENS_CSS = `:root {\n --matrx-print-accent: #667eea;\n --matrx-print-accent-2: #764ba2;\n --matrx-print-bg: #ffffff;\n --matrx-print-border: #e1e1e1;\n --matrx-print-border-muted: #d1d5db;\n --matrx-print-border-strong: #e5e5e5;\n --matrx-print-code-bg: #f5f5f5;\n --matrx-print-code-block-bg: #f8f8f8;\n --matrx-print-code-block-fg: #333;\n --matrx-print-code-fg: #d73a49;\n --matrx-print-fg: #1a1a1a;\n --matrx-print-fg-muted: #4a4a4a;\n --matrx-print-fg-subtle: #6b7280;\n --matrx-print-heading: #2a2a2a;\n --matrx-print-heading-sub: #3a3a3a;\n --matrx-print-link-fg: #374151;\n --matrx-print-link-hover-fg: #1f2937;\n --matrx-print-link-underline: #9ca3af;\n --matrx-print-quote-fg: #666;\n --matrx-print-shadow: rgba(0, 0, 0, 0.1);\n --matrx-print-shadow-strong: rgba(0, 0, 0, 0.2);\n --matrx-print-success: #2d5016;\n --matrx-print-success-2: #1e3a0f;\n --matrx-print-surface: #f8f9fa;\n --matrx-print-table-fg: #333333;\n}`;\n\n/** Default token VALUES for the article skin. */\nexport const MARKDOWN_ARTICLE_TOKENS_CSS = `:root {\n --matrx-print-accent: #2563eb;\n --matrx-print-bg: #fff;\n --matrx-print-border: #e5e7eb;\n --matrx-print-border-muted: #d1d5db;\n --matrx-print-code-bg: #f1f5f9;\n --matrx-print-fg: #1a1a1a;\n --matrx-print-fg-muted: #374151;\n --matrx-print-fg-subtle: #64748b;\n --matrx-print-heading: #111827;\n --matrx-print-ink: #0f172a;\n --matrx-print-line: #e2e8f0;\n --matrx-print-quote-bg: #f5f3ff;\n --matrx-print-quote-border: #6366f1;\n --matrx-print-surface: #f8fafc;\n --matrx-print-surface-sunken: #f3f4f6;\n --matrx-print-table-head-bg: #1e293b;\n --matrx-print-table-head-border: #334155;\n}`;\n\n/** Structural CSS for the document skin (`.matrx-*` classes). */\nexport const MARKDOWN_DOCUMENT_CSS = `/* \n * MATRX WordPress CSS - Production Ready\n * Use this CSS in your WordPress theme to style MATRX content\n * All styles are scoped to .matrx-content-container to avoid conflicts\n */\n\n/* Content Container */\n.matrx-content-container {\n max-width: 800px;\n margin: 0 auto;\n padding: 2rem;\n line-height: 1.6;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;\n}\n\n/* Typography */\n.matrx-h1 {\n font-size: 2.5rem;\n font-weight: 700;\n margin: 0 0 1.5rem 0;\n color: var(--matrx-print-fg, #1a1a1a);\n line-height: 1.2;\n}\n\n.matrx-h2 {\n font-size: 1.8rem;\n font-weight: 600;\n margin: 3rem 0 1rem 0 !important;\n color: var(--matrx-print-heading, #2a2a2a);\n line-height: 1.3 !important;\n border-bottom: 2px solid var(--matrx-print-border-strong, #e5e5e5);\n padding-bottom: 0.75rem !important;\n padding-top: 0 !important;\n}\n\n.matrx-h3 {\n font-size: 1.3rem;\n font-weight: 600;\n margin: 2rem 0 1rem 0;\n color: var(--matrx-print-heading-sub, #3a3a3a);\n line-height: 1.4;\n}\n\n.matrx-h4 {\n font-size: 1.1rem;\n font-weight: 600;\n margin: 1.5rem 0 0.75rem 0;\n color: var(--matrx-print-heading-sub, #3a3a3a);\n line-height: 1.4;\n}\n\n.matrx-h5 {\n font-size: 1rem;\n font-weight: 600;\n margin: 1.25rem 0 0.5rem 0;\n color: var(--matrx-print-heading-sub, #3a3a3a);\n line-height: 1.4;\n}\n\n.matrx-h6 {\n font-size: 0.9rem;\n font-weight: 600;\n margin: 1rem 0 0.5rem 0;\n color: var(--matrx-print-heading-sub, #3a3a3a);\n line-height: 1.4;\n}\n\n/* Paragraphs */\n.matrx-intro {\n font-size: 1.1rem;\n color: var(--matrx-print-fg-muted, #4a4a4a);\n margin-bottom: 2rem;\n padding: 1.5rem;\n background: var(--matrx-print-surface, #f8f9fa);\n border-left: 4px solid var(--matrx-print-border-muted, #d1d5db);\n border-radius: 0 8px 8px 0;\n}\n\n.matrx-paragraph {\n font-size: 1rem;\n color: var(--matrx-print-fg-muted, #4a4a4a);\n margin-bottom: 1.5rem;\n text-align: justify;\n}\n\n/* Text Formatting */\n.matrx-em {\n font-style: italic;\n color: var(--matrx-print-heading, #2a2a2a);\n}\n\n.matrx-strong {\n font-weight: 600;\n color: var(--matrx-print-heading, #2a2a2a);\n}\n\n/* Links */\n.matrx-link {\n color: var(--matrx-print-link-fg, #374151);\n text-decoration: underline;\n text-decoration-color: var(--matrx-print-border-muted, #d1d5db);\n text-underline-offset: 3px;\n transition: all 0.2s ease;\n}\n\n.matrx-link:hover {\n color: var(--matrx-print-link-hover-fg, #1f2937);\n text-decoration-color: var(--matrx-print-link-underline, #9ca3af);\n}\n\n/* Images */\n.matrx-image {\n max-width: 100%;\n height: auto;\n display: block;\n margin: 1.5rem auto;\n border-radius: 8px;\n box-shadow: 0 2px 8px var(--matrx-print-shadow, rgba(0, 0, 0, 0.1));\n}\n\n/* Lists */\n.matrx-list {\n margin: 1.5rem 0;\n padding-left: 0;\n}\n\n.matrx-bullet-list {\n list-style: none;\n}\n\n.matrx-list-item {\n margin-bottom: 1rem;\n padding-left: 1.5rem;\n position: relative;\n color: var(--matrx-print-fg-muted, #4a4a4a);\n}\n\n.matrx-list-item::before {\n content: \"•\";\n color: var(--matrx-print-fg-subtle, #6b7280);\n font-weight: bold;\n position: absolute;\n left: 0;\n top: 0;\n font-size: 1.2rem;\n}\n\n/* Numbered Lists */\n.matrx-numbered-list {\n list-style: decimal;\n padding-left: 2rem;\n}\n\n.matrx-numbered-list > .matrx-list-item {\n padding-left: 0.5rem;\n}\n\n.matrx-numbered-list > .matrx-list-item::before {\n content: none;\n /* Remove the bullet */\n}\n\n/* Nested list indentation */\n.matrx-nested-list {\n margin-top: 0.5rem;\n margin-bottom: 0.5rem;\n padding-left: 1.5rem !important;\n}\n\n/* Ensure nested lists within list items are properly indented */\n.matrx-list-item > .matrx-list {\n margin-top: 0.5rem;\n margin-bottom: 0.5rem;\n padding-left: 1.5rem;\n}\n\n/* For multiple levels of nesting, increase indentation */\n.matrx-nested-list .matrx-nested-list {\n padding-left: 1.5rem !important;\n}\n\n/* Code */\n.matrx-content-container .matrx-inline-code {\n background-color: var(--matrx-print-code-bg, #f5f5f5);\n padding: 0.125rem 0.25rem;\n border-radius: 0.25rem;\n font-family: \"Monaco\", \"Menlo\", \"Ubuntu Mono\", monospace;\n font-size: 0.875rem;\n color: var(--matrx-print-code-fg, #d73a49);\n}\n\n.matrx-content-container .matrx-code-block {\n background-color: var(--matrx-print-code-block-bg, #f8f8f8);\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n border-radius: 0.375rem;\n padding: 1rem;\n margin: 1.5rem 0;\n overflow-x: auto;\n}\n\n.matrx-content-container .matrx-code {\n font-family: \"Monaco\", \"Menlo\", \"Ubuntu Mono\", monospace;\n font-size: 0.875rem;\n line-height: 1.5;\n color: var(--matrx-print-code-block-fg, #333);\n}\n\n/* Blockquotes */\n.matrx-content-container .matrx-blockquote {\n border-left: 4px solid var(--matrx-print-border, #e1e1e1);\n padding-left: 1rem;\n margin: 1.5rem 0;\n font-style: italic;\n color: var(--matrx-print-quote-fg, #666);\n}\n\n/* Tables */\n.matrx-content-container .matrx-table {\n width: 100%;\n border-collapse: collapse;\n margin: 1.5rem 0;\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n}\n\n.matrx-content-container .matrx-table-header {\n background-color: var(--matrx-print-surface, #f8f9fa);\n font-weight: 600;\n padding: 0.75rem;\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n text-align: left;\n}\n\n.matrx-content-container .matrx-table-cell {\n padding: 0.75rem;\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n}\n\n.matrx-content-container .matrx-table-row:nth-child(even) {\n background-color: var(--matrx-print-surface, #f8f9fa);\n}\n\n/* Images */\n.matrx-content-container .matrx-image {\n max-width: 100%;\n height: auto;\n border-radius: 0.375rem;\n margin: 1rem 0;\n}\n\n/* Horizontal Rules */\n.matrx-content-container .matrx-hr {\n border: none;\n border-top: 1px solid var(--matrx-print-border, #e1e1e1);\n margin: 2rem 0;\n}\n\n/* FAQ Styles - Clean Design */\n.matrx-faq-item {\n margin-bottom: 2rem;\n padding: 1.5rem;\n background: var(--matrx-print-surface, #f8f9fa);\n border-radius: 8px;\n border-left: 4px solid var(--matrx-print-border-muted, #d1d5db);\n}\n\n.matrx-faq-question {\n font-size: 1.2rem;\n font-weight: 600;\n margin: 0 0 0.75rem 0;\n color: var(--matrx-print-heading, #2a2a2a);\n}\n\n.matrx-faq-answer {\n margin: 0;\n color: var(--matrx-print-fg-muted, #4a4a4a);\n line-height: 1.6;\n}\n\n/* Code Blocks */\n.matrx-inline-code {\n background-color: var(--matrx-print-code-bg, #f5f5f5);\n padding: 0.125rem 0.25rem;\n border-radius: 0.25rem;\n font-family: \"Monaco\", \"Menlo\", \"Ubuntu Mono\", monospace;\n font-size: 0.875rem;\n color: var(--matrx-print-code-fg, #d73a49);\n}\n\n.matrx-code-block {\n background-color: var(--matrx-print-code-block-bg, #f8f8f8);\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n border-radius: 0.375rem;\n padding: 1rem;\n margin: 1.5rem 0;\n overflow-x: auto;\n}\n\n.matrx-code {\n font-family: \"Monaco\", \"Menlo\", \"Ubuntu Mono\", monospace;\n font-size: 0.875rem;\n line-height: 1.5;\n color: var(--matrx-print-code-block-fg, #333);\n}\n\n/* Blockquotes */\n.matrx-blockquote {\n border-left: 4px solid var(--matrx-print-border, #e1e1e1);\n padding-left: 1rem;\n margin: 1.5rem 0;\n font-style: italic;\n color: var(--matrx-print-quote-fg, #666);\n}\n\n/* Tables */\n.matrx-table {\n width: 100%;\n border-collapse: collapse;\n margin: 1.5rem 0;\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n color: var(--matrx-print-table-fg, #333333);\n}\n\n.matrx-table-head {\n background-color: var(--matrx-print-surface, #f8f9fa);\n}\n\n.matrx-table-body {\n background-color: var(--matrx-print-bg, #ffffff);\n}\n\n.matrx-table-header {\n background-color: var(--matrx-print-surface, #f8f9fa);\n font-weight: 600;\n padding: 0.75rem;\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n text-align: left;\n color: var(--matrx-print-table-fg, #333333);\n}\n\n.matrx-table-cell {\n padding: 0.75rem;\n border: 1px solid var(--matrx-print-border, #e1e1e1);\n color: var(--matrx-print-table-fg, #333333);\n}\n\n.matrx-table-row {\n color: var(--matrx-print-table-fg, #333333);\n}\n\n.matrx-table-row:nth-child(even) {\n background-color: var(--matrx-print-surface, #f8f9fa);\n}\n\n/* Ensure table content doesn't inherit external colors */\n.matrx-table * {\n color: inherit;\n}\n\n/* Images */\n.matrx-image {\n max-width: 100%;\n height: auto;\n border-radius: 0.375rem;\n margin: 1rem 0;\n}\n\n/* Horizontal Rules */\n.matrx-hr {\n border: none;\n border-top: 1px solid var(--matrx-print-border, #e1e1e1);\n margin: 2rem 0;\n}\n\n/* Utility Classes */\n.matrx-div {\n margin: 0.5rem 0;\n}\n\n.matrx-span {\n /* Inherit parent styling by default */\n}\n\n/* Flashcard Styles */\n.matrx-flashcards-container {\n margin: 2rem 0;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n}\n\n.matrx-flashcard {\n perspective: 1000px;\n perspective-origin: center center;\n height: 200px;\n cursor: pointer;\n position: relative;\n margin-bottom: 0.5rem;\n}\n\n.matrx-flashcard-input {\n display: none;\n}\n\n.matrx-flashcard-inner {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n transition: transform 0.6s;\n transform-style: preserve-3d;\n transform-origin: center center;\n}\n\n.matrx-flashcard-input:checked ~ .matrx-flashcard-inner {\n transform: rotateY(180deg);\n}\n\n.matrx-flashcard-front,\n.matrx-flashcard-back {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n backface-visibility: hidden;\n border-radius: 12px;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 1.5rem;\n box-shadow: 0 4px 6px var(--matrx-print-shadow, rgba(0, 0, 0, 0.1));\n transition: box-shadow 0.3s ease;\n box-sizing: border-box;\n}\n\n.matrx-flashcard-front {\n background: linear-gradient(135deg, var(--matrx-print-accent, #667eea) 0%, var(--matrx-print-accent-2, #764ba2) 100%);\n color: white;\n}\n\n.matrx-flashcard-back {\n background: linear-gradient(135deg, var(--matrx-print-success, #2d5016) 0%, var(--matrx-print-success-2, #1e3a0f) 100%);\n color: white;\n transform: rotateY(180deg);\n}\n\n.matrx-flashcard:hover .matrx-flashcard-front,\n.matrx-flashcard:hover .matrx-flashcard-back {\n box-shadow: 0 8px 16px var(--matrx-print-shadow-strong, rgba(0, 0, 0, 0.2));\n}\n\n.matrx-flashcard-content {\n text-align: center;\n font-size: 1.3rem;\n line-height: 1.8;\n max-height: 100%;\n width: 100%;\n overflow: hidden;\n}\n\n.matrx-flashcard-label {\n cursor: pointer;\n user-select: none;\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: 10;\n}\n\n.matrx-flashcard-indicator {\n position: absolute;\n bottom: 12px;\n right: 16px;\n font-size: 0.75rem;\n opacity: 0.8;\n font-weight: 500;\n letter-spacing: 0.5px;\n}\n\n/* Responsive adjustments */\n@media (max-width: 768px) {\n .matrx-flashcard {\n height: 180px;\n }\n\n .matrx-flashcard-content {\n font-size: 1rem;\n }\n\n .matrx-flashcard-front,\n .matrx-flashcard-back {\n padding: 1.25rem;\n }\n}\n\n@media (max-width: 480px) {\n .matrx-flashcard {\n height: 160px;\n }\n\n .matrx-flashcard-content {\n font-size: 0.95rem;\n }\n\n .matrx-flashcard-front,\n .matrx-flashcard-back {\n padding: 1rem;\n }\n}\n\n/* Responsive Design */\n@media (max-width: 768px) {\n .matrx-content-container {\n padding: 1rem;\n }\n\n .matrx-h1 {\n font-size: 2rem;\n }\n\n .matrx-h2 {\n font-size: 1.5rem;\n margin: 2rem 0 1rem 0 !important;\n }\n\n .matrx-h3 {\n font-size: 1.2rem;\n }\n\n .matrx-h4 {\n font-size: 1.05rem;\n }\n\n .matrx-h5 {\n font-size: 0.95rem;\n }\n\n .matrx-h6 {\n font-size: 0.9rem;\n }\n\n .matrx-intro {\n padding: 1rem;\n font-size: 1rem;\n }\n\n .matrx-faq-question {\n font-size: 1.1rem;\n margin: 1.5rem 0 0.75rem 0;\n }\n\n .matrx-paragraph {\n text-align: left;\n }\n\n .matrx-table {\n font-size: 0.875rem;\n }\n\n .matrx-table-header,\n .matrx-table-cell {\n padding: 0.5rem;\n }\n\n .matrx-code-block {\n padding: 0.75rem;\n margin: 1rem 0;\n }\n}\n\n@media (max-width: 480px) {\n .matrx-content-container {\n padding: 0.75rem;\n }\n\n .matrx-h1 {\n font-size: 1.75rem;\n margin-bottom: 1rem;\n }\n\n .matrx-h2 {\n font-size: 1.3rem;\n margin: 1.5rem 0 0.75rem 0 !important;\n }\n\n .matrx-h3 {\n font-size: 1.1rem;\n margin: 1.5rem 0 0.75rem 0;\n }\n\n .matrx-h4 {\n font-size: 1rem;\n margin: 1.25rem 0 0.5rem 0;\n }\n\n .matrx-h5 {\n font-size: 0.9rem;\n margin: 1rem 0 0.5rem 0;\n }\n\n .matrx-h6 {\n font-size: 0.85rem;\n margin: 1rem 0 0.5rem 0;\n }\n\n .matrx-intro {\n padding: 0.75rem;\n margin-bottom: 1.5rem;\n }\n\n .matrx-paragraph {\n margin-bottom: 1.25rem;\n }\n\n .matrx-list-item {\n margin-bottom: 0.75rem;\n }\n\n .matrx-table-header,\n .matrx-table-cell {\n padding: 0.375rem;\n }\n\n .matrx-code-block {\n padding: 0.5rem;\n font-size: 0.8rem;\n }\n\n .matrx-inline-code {\n font-size: 0.8rem;\n }\n}\n/* Print / PDF hard parts — added by @ai-matrx/print 0.3.0. */\n@media print {\n .matrx-content-container {\n max-width: 100%;\n padding: 0;\n }\n\n .matrx-h1,\n .matrx-h2,\n .matrx-h3,\n .matrx-h4,\n .matrx-h5,\n .matrx-h6 {\n page-break-after: avoid;\n break-after: avoid;\n }\n\n .matrx-paragraph,\n .matrx-intro {\n orphans: 3;\n widows: 3;\n }\n\n .matrx-table,\n .matrx-code-block,\n .matrx-blockquote,\n .matrx-list-item,\n .matrx-image,\n .matrx-faq-item,\n .matrx-flashcard {\n page-break-inside: avoid;\n break-inside: avoid;\n }\n\n .matrx-table-header,\n .matrx-code-block,\n .matrx-blockquote,\n .matrx-flashcard {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n\n .matrx-link {\n text-decoration: underline;\n }\n}\n`;\n\n/** Structural CSS for the article skin (bare tags + `.print-*` classes). */\nexport const MARKDOWN_ARTICLE_CSS = `*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}body{font-family:Georgia,'Times New Roman',serif;font-size:11pt;line-height:1.7;color:var(--matrx-print-fg, #1a1a1a);background:var(--matrx-print-bg, #fff);max-width:780px;margin:0 auto;padding:32px 40px}.print-actions{display:flex;gap:10px;margin-bottom:28px;padding-bottom:20px;border-bottom:2px solid var(--matrx-print-border, #e5e7eb)}.print-btn{display:inline-flex;align-items:center;gap:6px;padding:8px 20px;border-radius:8px;font-size:13px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;cursor:pointer;border:none;font-weight:600;transition:opacity .15s}.print-btn:hover{opacity:.85}.print-btn-primary{background:var(--matrx-print-accent, #2563eb);color:var(--matrx-print-bg, #fff)}.print-btn-secondary{background:var(--matrx-print-surface-sunken, #f3f4f6);color:var(--matrx-print-fg-muted, #374151);border:1px solid var(--matrx-print-border-muted, #d1d5db)}h1,h2,h3,h4,h5,h6{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Helvetica Neue',sans-serif;font-weight:700;line-height:1.3;color:var(--matrx-print-heading, #111827);margin-top:1.6em;margin-bottom:.5em;page-break-after:avoid}h1{font-size:24pt;border-bottom:2px solid var(--matrx-print-border, #e5e7eb);padding-bottom:.3em;margin-top:0}h2{font-size:18pt;border-bottom:1px solid var(--matrx-print-border, #e5e7eb);padding-bottom:.2em}h3{font-size:14pt}p{margin-bottom:.9em;orphans:3;widows:3}a{color:var(--matrx-print-accent, #2563eb);text-decoration:underline;word-break:break-word}ul,ol{margin:.6em 0 .9em 0;padding-left:1.8em}li{margin-bottom:.3em;page-break-inside:avoid}blockquote{margin:1em 0;padding:.7em 1em .7em 1.2em;border-left:4px solid var(--matrx-print-quote-border, #6366f1);background:var(--matrx-print-quote-bg, #f5f3ff);border-radius:0 6px 6px 0;color:var(--matrx-print-fg-muted, #374151);font-style:italic;page-break-inside:avoid}.inline-code{font-family:'JetBrains Mono','Fira Code',monospace;font-size:9.5pt;background:var(--matrx-print-code-bg, #f1f5f9);color:var(--matrx-print-ink, #0f172a);padding:1px 5px;border-radius:4px;border:1px solid var(--matrx-print-line, #e2e8f0)}.code-block-wrapper{position:relative;margin:1em 0 1.2em;border-radius:8px;overflow:hidden;border:1px solid var(--matrx-print-line, #e2e8f0);page-break-inside:avoid}.code-lang{display:block;font-family:-apple-system,sans-serif;font-size:9pt;font-weight:600;color:var(--matrx-print-fg-subtle, #64748b);background:var(--matrx-print-surface, #f8fafc);padding:4px 12px;border-bottom:1px solid var(--matrx-print-line, #e2e8f0);text-transform:uppercase;letter-spacing:.05em}.code-block{margin:0;padding:14px 16px;background:var(--matrx-print-ink, #0f172a);color:var(--matrx-print-line, #e2e8f0);font-family:'JetBrains Mono',monospace;font-size:9pt;line-height:1.6;overflow-x:auto;white-space:pre;tab-size:2}.print-table{width:100%;border-collapse:collapse;margin:1em 0 1.2em;font-size:10pt;page-break-inside:avoid}.print-table th{background:var(--matrx-print-table-head-bg, #1e293b);color:var(--matrx-print-surface, #f8fafc);font-family:-apple-system,sans-serif;font-weight:600;font-size:9.5pt;text-align:left;padding:8px 12px;border:1px solid var(--matrx-print-table-head-border, #334155)}.print-table td{padding:7px 12px;border:1px solid var(--matrx-print-line, #e2e8f0);vertical-align:top}.print-table tr:nth-child(even) td{background:var(--matrx-print-surface, #f8fafc)}hr{border:none;border-top:2px solid var(--matrx-print-border, #e5e7eb);margin:1.5em 0}.print-figure{margin:1em 0 1.2em;page-break-inside:avoid}.print-image{display:block;max-width:100%;height:auto;margin:0 auto;border-radius:6px}.print-figure figcaption{margin-top:.4em;text-align:center;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;font-size:9.5pt;color:var(--matrx-print-fg-subtle, #64748b)}@media print{body{max-width:100%;padding:0;font-size:10.5pt}.print-actions{display:none!important}.code-block,.print-table th,blockquote{color-adjust:exact;-webkit-print-color-adjust:exact;print-color-adjust:exact}a[href]::after{content:\" (\"attr(href)\")\";font-size:9pt;color:var(--matrx-print-fg-subtle, #64748b)}a[href^=\"#\"]::after,a[href^=\"javascript:\"]::after{content:\"\"}h1,h2,h3{page-break-after:avoid}pre,blockquote,table{page-break-inside:avoid}}`;\n\n/**\n * Rules BOTH skins share — appended after the skin sheet by\n * `getMarkdownStylesheet`. Everything the two converters emit identically\n * (page breaks, artifact panels, task boxes, accent/heavy rules, strikethrough,\n * printed flashcard pairs) is styled once here so the skins cannot drift, plus\n * the print hard parts every printed page needs regardless of skin.\n *\n * Page break: on screen a dashed rule labelled \"Page break\" with generous\n * padding — the same idea the chat preview draws; on paper a zero-height\n * element that forces the next content onto a new page.\n */\nexport const MARKDOWN_SHARED_CSS = `\n.matrx-page-break {\n position: relative;\n clear: both;\n height: 0;\n margin: 2.75rem 0;\n border: 0;\n border-top: 2px dashed var(--matrx-print-border-muted, #d1d5db);\n}\n.matrx-page-break::after {\n content: attr(data-label);\n position: absolute;\n left: 50%;\n top: 0;\n transform: translate(-50%, -50%);\n padding: 0 0.75rem;\n background: var(--matrx-print-bg, #ffffff);\n color: var(--matrx-print-fg-subtle, #6b7280);\n font: 600 10px/1.6 -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;\n letter-spacing: 0.08em;\n text-transform: uppercase;\n white-space: nowrap;\n}\n\n.matrx-artifact {\n margin: 1.25em 0;\n border: 1px solid var(--matrx-print-border, #e5e7eb);\n border-radius: 8px;\n overflow: hidden;\n}\n.matrx-artifact-header {\n display: flex;\n align-items: baseline;\n gap: 0.6em;\n padding: 0.45em 0.9em;\n background: var(--matrx-print-surface, #f8fafc);\n border-bottom: 1px solid var(--matrx-print-border, #e5e7eb);\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;\n}\n.matrx-artifact-kind {\n font-size: 0.72em;\n font-weight: 700;\n letter-spacing: 0.06em;\n text-transform: uppercase;\n color: var(--matrx-print-accent, #2563eb);\n}\n.matrx-artifact-title {\n font-weight: 600;\n color: var(--matrx-print-fg, #1a1a1a);\n}\n.matrx-artifact-body {\n padding: 0.8em 0.9em;\n}\n.matrx-artifact-body > :first-child {\n margin-top: 0;\n}\n.matrx-artifact-body > :last-child {\n margin-bottom: 0;\n}\n/* The panel's kind chip already names these languages. */\n.matrx-artifact:is([data-artifact-type=\"html\"], [data-artifact-type=\"react\"], [data-artifact-type=\"svg\"], [data-artifact-type=\"mermaid\"], [data-artifact-type=\"diff\"], [data-artifact-type=\"iframe\"]) .code-lang {\n display: none;\n}\n.matrx-artifact-empty {\n margin: 0;\n font-style: italic;\n color: var(--matrx-print-fg-subtle, #6b7280);\n}\n\nli.matrx-task-item {\n list-style: none;\n}\n/* The box IS the marker — the document skin's custom bullet must not sit on it. */\n:is(.matrx-content-container, .content) li.matrx-task-item::before {\n content: none;\n}\n.matrx-task-box {\n position: relative;\n display: inline-block;\n width: 0.9em;\n height: 0.9em;\n margin: 0 0.5em 0 -1.35em;\n border: 1.5px solid var(--matrx-print-fg-muted, #4a4a4a);\n border-radius: 3px;\n vertical-align: -0.1em;\n}\n.matrx-task-box.is-checked::after {\n content: \"\\\\2713\";\n position: absolute;\n inset: 0;\n font-size: 0.8em;\n font-weight: 700;\n line-height: 1.1em;\n text-align: center;\n color: var(--matrx-print-fg, #1a1a1a);\n}\n\n:is(.matrx-content-container, .content) del {\n color: var(--matrx-print-fg-muted, #4a4a4a);\n text-decoration: line-through;\n}\n:is(.matrx-content-container, .content) hr.matrx-hr-accent {\n height: 2px;\n margin: 1.75em 0;\n border: 0;\n border-radius: 2px;\n background: var(--matrx-print-accent, #2563eb);\n opacity: 0.6;\n}\n:is(.matrx-content-container, .content) hr.matrx-hr-heavy {\n height: 4px;\n margin: 2.25em 0;\n border: 0;\n border-radius: 4px;\n background: var(--matrx-print-accent, #2563eb);\n}\n\n.matrx-flashcards-print {\n margin: 1em 0 1.2em;\n}\n.matrx-fc {\n display: grid;\n grid-template-columns: 1fr 1fr;\n margin-bottom: 0.5em;\n border: 1px solid var(--matrx-print-border, #e5e7eb);\n border-radius: 6px;\n}\n.matrx-fc-front,\n.matrx-fc-back {\n padding: 0.6em 0.8em;\n}\n.matrx-fc-front {\n font-weight: 600;\n border-right: 1px dashed var(--matrx-print-border-muted, #d1d5db);\n}\n.matrx-fc-num {\n display: inline-block;\n min-width: 1.6em;\n font-size: 0.85em;\n color: var(--matrx-print-fg-subtle, #6b7280);\n}\n\n@media print {\n .matrx-page-break {\n margin: 0;\n border: 0;\n break-after: page;\n page-break-after: always;\n }\n .matrx-page-break::after {\n content: none;\n }\n .matrx-page-break + * {\n margin-top: 0;\n }\n\n /* Scoped to the rendered markdown (.matrx-content-container = document\n skin, .content = print window) so a host page that carries this sheet\n — a WordPress theme — keeps its own print rules everywhere else. */\n\n /* Long tables flow across pages: the header row repeats, rows never split. */\n :is(.matrx-content-container, .content) thead {\n display: table-header-group;\n }\n :is(.matrx-content-container, .content) :is(tr, img, figure),\n .matrx-fc,\n .matrx-task-item {\n break-inside: avoid;\n page-break-inside: avoid;\n }\n :is(.matrx-content-container, .content) :is(h1, h2, h3, h4, h5, h6),\n .matrx-artifact-header {\n break-after: avoid;\n page-break-after: avoid;\n break-inside: avoid;\n }\n\n /* Paper cannot scroll: long code lines wrap instead of being cut off. */\n :is(.matrx-content-container, .content) :is(pre, pre code) {\n white-space: pre-wrap !important;\n overflow-wrap: anywhere;\n overflow: visible !important;\n }\n .code-block-wrapper,\n .matrx-artifact {\n overflow: visible;\n }\n :is(.matrx-content-container, .content) img {\n max-width: 100% !important;\n }\n\n .matrx-artifact-header,\n .matrx-task-box {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n\n a.matrx-link[href^=\"http\"]::after {\n content: \" (\" attr(href) \")\";\n font-size: 0.85em;\n color: var(--matrx-print-fg-subtle, #6b7280);\n overflow-wrap: anywhere;\n }\n}\n`;\n\n/**\n * Page geometry + page numbers (\"3 / 12\", bottom centre). Part of the default\n * sheet; `getMarkdownStylesheet({ pageNumbers: false })` leaves it out.\n * Browsers without `@page` margin boxes ignore the numbering and keep the\n * margins.\n */\nexport const MARKDOWN_PAGE_CSS = `\n@page {\n margin: 0.6in 0.65in 0.7in;\n @bottom-center {\n content: counter(page) \" / \" counter(pages);\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif;\n font-size: 8pt;\n color: var(--matrx-print-fg-subtle, #6b7280);\n }\n}\n`;\n\n/** `@page` geometry without numbering. */\nexport const MARKDOWN_PAGE_PLAIN_CSS = `\n@page {\n margin: 0.6in 0.65in 0.7in;\n}\n`;\n","/**\n * @ai-matrx/print/directives — the ONE definition of the print directives\n * markdown can carry, shared by every surface that reads markdown.\n *\n * Why a separate, zero-dependency entry: the directive syntax has three\n * readers — this package's two converters (print window / PDF / HTML page),\n * the chat renderer's remark plugin (the on-screen preview), and any editor\n * that inserts one. If each re-derived the regex they would drift the first\n * time someone added an alias. `/markdown` carries ~20KB of stylesheet, so the\n * chat bundle imports the syntax from here instead and pays nothing.\n *\n * ── Page break ────────────────────────────────────────────────────────────\n * A line that is exactly one of these (case-insensitive, surrounding\n * whitespace ignored) forces the next content onto a new printed page:\n *\n * <!-- pagebreak --> ← canonical; invisible in any other renderer\n * <!-- page-break --> <!-- page break --> <!-- newpage -->\n * \\pagebreak \\newpage ← LaTeX / pandoc habit\n * <div style=\"page-break-after: always\"></div> ← Typora / VS Code habit\n * (also `page-break-before`, `break-after: page`, `break-before: page`,\n * and `<div class=\"page-break\"></div>` / `class=\"pagebreak\"`)\n *\n * On screen every surface draws the same idea: a dashed rule labelled\n * \"Page break\" with generous padding. In print it is a zero-height element\n * with `break-after: page`.\n */\n\n/** The form editors insert and docs recommend. */\nexport const PAGE_BREAK_MARKDOWN = \"<!-- pagebreak -->\";\n\n/** The class every surface puts on a rendered page break. */\nexport const PAGE_BREAK_CLASS = \"matrx-page-break\";\n\n/** Screen label for a rendered page break. */\nexport const PAGE_BREAK_LABEL = \"Page break\";\n\nconst COMMENT_FORM = /^<!--\\s*(?:page[\\s_-]?break|new[\\s_-]?page)\\s*-->$/i;\nconst LATEX_FORM = /^\\\\(?:pagebreak|newpage|clearpage)\\s*(?:\\{\\s*\\})?$/i;\nconst DIV_FORM = /^<div\\b([^>]*)>\\s*<\\/div>$|^<div\\b([^>]*)\\/>$/i;\nconst DIV_BREAK_ATTR =\n /(?:page-break-(?:after|before)\\s*:\\s*always|break-(?:after|before)\\s*:\\s*page|class\\s*=\\s*[\"'](?:[^\"']*\\s)?page-?break(?:\\s[^\"']*)?[\"'])/i;\n\n/** Columns of leading indentation (tab = 4, NBSP counts as a space). */\nfunction indentColumns(line: string): number {\n let cols = 0;\n for (const ch of line) {\n if (ch === \" \" || ch === \"\\u00A0\") cols += 1;\n else if (ch === \"\\t\") cols += 4;\n else break;\n }\n return cols;\n}\n\n/**\n * Is this single line a page-break directive? Indented four or more columns\n * it is not — in markdown that is a code block, and every surface must agree.\n */\nexport function isPageBreakLine(line: string): boolean {\n if (indentColumns(line) >= 4) return false;\n const t = line.trim();\n if (t.length < 8 || t.length > 200) return false;\n if (COMMENT_FORM.test(t) || LATEX_FORM.test(t)) return true;\n const div = DIV_FORM.exec(t);\n if (!div) return false;\n return DIV_BREAK_ATTR.test(div[1] ?? div[2] ?? \"\");\n}\n\n// ── Section break ─────────────────────────────────────────────────────────\n//\n// A section break is a page break that can also change the page layout for\n// everything after it (Word's \"Section break (next page)\"):\n//\n// <!-- section --> ← new page, same layout\n// <!-- section: landscape --> ← new page, landscape from here on\n// <!-- section landscape columns=2 --> ← landscape AND two columns\n// <!-- section portrait columns=1 --> ← back to the default layout\n//\n// Recognised words: `landscape` / `portrait`, `columns=N` (or `cols=N`,\n// `N columns`, 1–3). Unknown words are ignored, never an error — the break\n// still happens. Every page-break reader treats a section break as a break.\n\n/** The form editors insert for a plain section break. */\nexport const SECTION_BREAK_MARKDOWN = \"<!-- section -->\";\n\nexport interface SectionBreakDirective {\n /** Absent = inherit the document's orientation. */\n orientation?: \"portrait\" | \"landscape\";\n /** Absent = inherit the document's column count. 1–3. */\n columns?: 1 | 2 | 3;\n}\n\nconst SECTION_FORM = /^<!--\\s*section(?:[\\s_-]?break)?\\b\\s*:?\\s*([^>]*?)\\s*-->$/i;\n\n/** Parse a section-break line; `null` when the line is not one. */\nexport function parseSectionBreakLine(line: string): SectionBreakDirective | null {\n if (indentColumns(line) >= 4) return null;\n const m = SECTION_FORM.exec(line.trim());\n if (!m) return null;\n const words = (m[1] ?? \"\").toLowerCase();\n const out: SectionBreakDirective = {};\n if (/\\blandscape\\b/.test(words)) out.orientation = \"landscape\";\n else if (/\\bportrait\\b/.test(words)) out.orientation = \"portrait\";\n const cols = /\\b(?:columns?|cols?)\\s*[=:]\\s*(\\d)\\b/.exec(words) ?? /\\b(\\d)\\s*[-\\s]?columns?\\b/.exec(words);\n if (cols) {\n const n = Math.min(3, Math.max(1, Number(cols[1])));\n out.columns = n as 1 | 2 | 3;\n }\n return out;\n}\n\n// ── Table of contents / bibliography placement ───────────────────────────\n//\n// `[[toc]]`, `[toc]`, `[TOC]`, `${toc}`, `<!-- toc -->`, `\\tableofcontents`\n// put the table of contents at that spot (otherwise frontmatter `toc: true`\n// puts it at the start). `<!-- bibliography -->`, `[[bibliography]]`,\n// `\\printbibliography` put the reference list there (otherwise it closes the\n// document whenever something is cited).\n\nexport const TOC_MARKDOWN = \"[[toc]]\";\nexport const BIBLIOGRAPHY_MARKDOWN = \"<!-- bibliography -->\";\n\nconst TOC_FORM = /^(?:\\[\\[\\s*toc\\s*\\]\\]|\\[toc\\]|\\$\\{toc\\}|<!--\\s*toc\\s*-->|\\\\tableofcontents)$/i;\nconst BIBLIOGRAPHY_FORM =\n /^(?:\\[\\[\\s*(?:bibliography|references)\\s*\\]\\]|<!--\\s*(?:bibliography|references)\\s*-->|\\\\printbibliography|\\\\bibliography\\{[^}]*\\})$/i;\n\nexport function isTocLine(line: string): boolean {\n return indentColumns(line) < 4 && TOC_FORM.test(line.trim());\n}\n\nexport function isBibliographyLine(line: string): boolean {\n return indentColumns(line) < 4 && BIBLIOGRAPHY_FORM.test(line.trim());\n}\n\n/** Any directive that ends the current printed page (page or section break). */\nexport function isBreakLine(line: string): boolean {\n return isPageBreakLine(line) || parseSectionBreakLine(line) !== null;\n}\n\n/**\n * Split markdown into the pieces that belong on separate pages. Fence-aware:\n * a directive inside a ``` / ~~~ code block is code, not a break. Always\n * returns at least one piece; empty pieces (two breaks in a row, a break at\n * the very start or end) are kept out so no blank page is produced.\n */\nexport function splitAtPageBreaks(markdown: string): string[] {\n const lines = markdown.split(/\\r?\\n/);\n const pieces: string[] = [];\n let current: string[] = [];\n let fence: string | null = null;\n\n for (const line of lines) {\n // Any indent — the converters accept list-nested fences, so must this.\n const fenceMatch = /^\\s*(`{3,}|~{3,})/.exec(line);\n if (fenceMatch) {\n const marker = fenceMatch[1] as string;\n if (fence === null) fence = marker;\n else if (marker[0] === fence[0] && marker.length >= fence.length) fence = null;\n } else if (fence === null && isBreakLine(line)) {\n if (current.join(\"\\n\").trim()) pieces.push(current.join(\"\\n\"));\n current = [];\n continue;\n }\n current.push(line);\n }\n if (current.join(\"\\n\").trim() || pieces.length === 0) pieces.push(current.join(\"\\n\"));\n return pieces;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsBA,yBAA2B;AAkPpB,SAAS,gBACd,cACA,WAAW,SACX,iBAAiB,uCACH;AACd,QAAM,MAAM,OAAO,KAAK,IAAI,UAAU,cAAc;AACpD,MAAI,CAAC,KAAK;AAER,UAAM,OAAO,IAAI,KAAK,CAAC,YAAY,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACzE,UAAM,MAAM,IAAI,gBAAgB,IAAI;AACpC,U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