vantage-md 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +99 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -1
- package/dist/index.d.ts +80 -1
- package/dist/index.js +98 -1
- package/dist/index.js.map +1 -1
- package/dist/prose.css +165 -0
- package/dist/react.cjs +74 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +80 -1
- package/dist/react.d.ts +80 -1
- package/dist/react.js +73 -1
- package/dist/react.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rehypeSourceLines.ts","../src/sanitize.ts","../src/frontmatter.ts","../src/renderMarkdown.ts","../src/scrollToLineAnchor.ts"],"names":["parseTOML"],"mappings":";;;;;;;;;;;;;;;;;AAWA,IAAM,UAAA,uBAAiB,GAAA,CAAI;AAAA,EACzB,GAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,YAAA;AAAA,EACA,KAAA;AAAA,EACA,OAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,SAAS,MAAM,IAAA,EAAsB;AACnC,EAAA,IAAI,cAAc,IAAA,EAAM;AACtB,IAAA,KAAA,MAAW,KAAA,IAAS,KAAK,QAAA,EAAU;AACjC,MAAA,IAAI,KAAA,CAAM,SAAS,SAAA,EAAW;AAC5B,QAAA,IAAI,UAAA,CAAW,IAAI,KAAA,CAAM,OAAO,KAAK,KAAA,CAAM,QAAA,EAAU,OAAO,IAAA,EAAM;AAChE,UAAA,KAAA,CAAM,UAAA,GAAa,KAAA,CAAM,UAAA,IAAc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,IAAI,YAAA,EAAc;AAChB,QAAA,MAAM,MAAA,GACJ,WAAY,qBAAA,EAAsB,CAAE,MACpC,YAAA,CAAa,qBAAA,EAAsB,CAAE,GAAA,GACrC,YAAA,CAAa,SAAA;AACf,QAAA,YAAA,CAAa,SAAS,EAAE,GAAA,EAAK,SAAS,EAAA,EAAI,QAAA,EAAU,UAAU,CAAA;AAAA,MAChE,CAAA,MAAO;AACL,QAAA,UAAA,CAAY,eAAe,EAAE,QAAA,EAAU,QAAA,EAAU,KAAA,EAAO,SAAS,CAAA;AAAA,MACnE;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AAEA,EAAA,OAAO,MAAM,0BAA0B,SAAS,CAAA;AAClD;AAEA,SAAS,iBAAiB,EAAA,EAAqC;AAC7D,EAAA,IAAI,IAAA,GAA2B,EAAA;AAC/B,EAAA,OAAO,IAAA,EAAM;AACX,IAAA,MAAM,QAAA,GAAW,gBAAA,CAAiB,IAAI,CAAA,CAAE,SAAA;AACxC,IAAA,IAAI,QAAA,KAAa,MAAA,IAAU,QAAA,KAAa,QAAA,EAAU,OAAO,IAAA;AACzD,IAAA,IAAA,GAAO,IAAA,CAAK,aAAA;AAAA,EACd;AACA,EAAA,OAAO,IAAA;AACT","file":"index.js","sourcesContent":["/**\n * Rehype plugin that adds `data-source-line` attributes to block-level\n * elements based on their position in the original markdown source.\n *\n * This enables GitHub-style line anchors (#L42, #L42-L50) by giving\n * each rendered block a traceable line number from the source.\n */\n\nimport type { Root, Element } from \"hast\";\nimport type { Plugin } from \"unified\";\n\nconst BLOCK_TAGS = new Set([\n \"p\",\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n \"li\",\n \"blockquote\",\n \"pre\",\n \"table\",\n \"tr\",\n \"ul\",\n \"ol\",\n \"hr\",\n \"div\",\n]);\n\nfunction visit(node: Root | Element) {\n if (\"children\" in node) {\n for (const child of node.children) {\n if (child.type === \"element\") {\n if (BLOCK_TAGS.has(child.tagName) && child.position?.start?.line) {\n child.properties = child.properties || {};\n child.properties[\"dataSourceLine\"] = child.position.start.line;\n }\n visit(child);\n }\n }\n }\n}\n\nconst rehypeSourceLines: Plugin<[], Root> = () => {\n return (tree: Root) => {\n visit(tree);\n };\n};\n\nexport default rehypeSourceLines;\n","/**\n * Sanitization schema for the rendering pipeline.\n * Allows GFM, KaTeX MathML, syntax highlighting classes, and\n * data-source-line attributes while blocking XSS vectors.\n */\n\nimport { defaultSchema } from \"rehype-sanitize\";\n\ntype Schema = typeof defaultSchema;\n\nexport const sanitizeSchema: Schema = {\n ...defaultSchema,\n tagNames: [\n ...(defaultSchema.tagNames || []),\n // KaTeX MathML elements\n \"math\",\n \"semantics\",\n \"mrow\",\n \"mi\",\n \"mo\",\n \"mn\",\n \"msup\",\n \"msub\",\n \"mfrac\",\n \"mover\",\n \"munder\",\n \"msqrt\",\n \"mroot\",\n \"mtable\",\n \"mtr\",\n \"mtd\",\n \"mtext\",\n \"mspace\",\n \"annotation\",\n // Other\n \"figure\",\n \"figcaption\",\n \"summary\",\n \"details\",\n ],\n attributes: {\n ...defaultSchema.attributes,\n \"*\": [\n ...(defaultSchema.attributes?.[\"*\"] || []),\n \"className\",\n \"style\",\n \"dataSourceLine\",\n ],\n code: [...(defaultSchema.attributes?.code || []), \"className\"],\n span: [...(defaultSchema.attributes?.span || []), \"className\", \"style\"],\n div: [...(defaultSchema.attributes?.div || []), \"className\", \"style\"],\n a: [...(defaultSchema.attributes?.a || []), \"id\", \"className\"],\n math: [\"xmlns\"],\n annotation: [\"encoding\"],\n img: [...(defaultSchema.attributes?.img || []), \"loading\"],\n td: [...(defaultSchema.attributes?.td || []), \"style\"],\n th: [...(defaultSchema.attributes?.th || []), \"style\"],\n },\n};\n","/**\n * Frontmatter parser for YAML (---) and TOML (+++) delimited content.\n * Works in both browser and server environments.\n */\n\nimport YAML from \"yaml\";\nimport { parse as parseTOML } from \"smol-toml\";\n\nexport type FrontmatterFormat = \"yaml\" | \"toml\" | \"none\";\n\nexport interface ParsedFrontmatter {\n frontmatter: Record<string, unknown>;\n body: string;\n format: FrontmatterFormat;\n}\n\n/**\n * Parse frontmatter from markdown content.\n * Supports YAML (delimited by ---) and TOML (delimited by +++).\n */\nexport function parseFrontmatter(content: string): ParsedFrontmatter {\n if (content.startsWith(\"+++\")) {\n return parseFrontmatterWithDelimiter(content, \"+++\", \"toml\");\n }\n if (content.startsWith(\"---\")) {\n return parseFrontmatterWithDelimiter(content, \"---\", \"yaml\");\n }\n return { frontmatter: {}, body: content, format: \"none\" };\n}\n\nfunction parseFrontmatterWithDelimiter(\n content: string,\n delimiter: string,\n format: \"yaml\" | \"toml\",\n): ParsedFrontmatter {\n const searchStart = delimiter.length;\n const endIndex = content.indexOf(`\\n${delimiter}`, searchStart);\n if (endIndex === -1) {\n return { frontmatter: {}, body: content, format: \"none\" };\n }\n\n const raw = content.slice(searchStart + 1, endIndex).trim();\n const bodyStart = endIndex + 1 + delimiter.length;\n const body = content.slice(bodyStart).replace(/^\\n/, \"\");\n\n try {\n const frontmatter =\n format === \"toml\"\n ? (parseTOML(raw) as Record<string, unknown>)\n : (YAML.parse(raw) as Record<string, unknown>);\n return { frontmatter: frontmatter || {}, body, format };\n } catch {\n return { frontmatter: {}, body: content, format: \"none\" };\n }\n}\n","/**\n * Framework-agnostic markdown -> HTML rendering pipeline.\n * Uses the same remark/rehype chain as the Vantage viewer.\n */\n\nimport { unified } from \"unified\";\nimport remarkParse from \"remark-parse\";\nimport remarkGfm from \"remark-gfm\";\nimport remarkMath from \"remark-math\";\nimport remarkRehype from \"remark-rehype\";\nimport rehypeRaw from \"rehype-raw\";\nimport rehypeSanitize from \"rehype-sanitize\";\nimport rehypeHighlight from \"rehype-highlight\";\nimport rehypeKatex from \"rehype-katex\";\nimport rehypeSlug from \"rehype-slug\";\nimport rehypeStringify from \"rehype-stringify\";\nimport rehypeSourceLines from \"./rehypeSourceLines.js\";\nimport { sanitizeSchema } from \"./sanitize.js\";\nimport { parseFrontmatter } from \"./frontmatter.js\";\nimport type { ParsedFrontmatter } from \"./frontmatter.js\";\n\nexport interface RenderOptions {\n /** Enable GFM tables, strikethrough, task lists (default: true) */\n gfm?: boolean;\n /** Enable KaTeX math rendering (default: true) */\n math?: boolean;\n /** Enable syntax highlighting (default: true) */\n highlight?: boolean;\n /** Add data-source-line attributes for line anchors (default: true) */\n sourceLines?: boolean;\n /** Enable XSS sanitization (default: true) */\n sanitize?: boolean;\n /** Parse and strip frontmatter (default: true) */\n frontmatter?: boolean;\n}\n\nexport interface RenderResult {\n /** The rendered HTML string */\n html: string;\n /** Parsed frontmatter (empty object if none or disabled) */\n frontmatter: Record<string, unknown>;\n /** The markdown body with frontmatter stripped */\n body: string;\n}\n\n/**\n * Render a markdown string to HTML using the full Vantage pipeline.\n *\n * Features (all enabled by default):\n * - GitHub Flavored Markdown (tables, strikethrough, task lists)\n * - KaTeX math rendering ($$...$$ blocks)\n * - Syntax highlighting via highlight.js\n * - `data-source-line` attributes for line anchors\n * - XSS sanitization\n * - Heading slugs/anchors\n * - YAML/TOML frontmatter parsing\n *\n * Mermaid diagrams are NOT rendered server-side (they require a browser).\n * Mermaid code blocks are preserved as `<pre><code class=\"language-mermaid\">`.\n * Use the React `<MarkdownViewer>` component for client-side mermaid rendering.\n */\nexport async function renderMarkdown(\n content: string,\n options: RenderOptions = {},\n): Promise<RenderResult> {\n const {\n gfm = true,\n math = true,\n highlight = true,\n sourceLines = true,\n sanitize = true,\n frontmatter: parseFm = true,\n } = options;\n\n // Parse frontmatter\n let parsed: ParsedFrontmatter;\n if (parseFm) {\n parsed = parseFrontmatter(content);\n } else {\n parsed = { frontmatter: {}, body: content, format: \"none\" };\n }\n\n // Build the unified pipeline using a single chain.\n // We use `any` for the processor to avoid unified's strict generic\n // type constraints that make conditional plugin registration painful.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const remarkPlugins: [any, ...any[]][] = [];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const rehypePlugins: [any, ...any[]][] = [];\n\n if (gfm) remarkPlugins.push([remarkGfm, { singleTilde: false }]);\n if (math) remarkPlugins.push([remarkMath, { singleDollarTextMath: false }]);\n\n rehypePlugins.push([rehypeRaw]);\n if (sourceLines) rehypePlugins.push([rehypeSourceLines]);\n if (sanitize) rehypePlugins.push([rehypeSanitize, sanitizeSchema]);\n rehypePlugins.push([rehypeSlug]);\n if (highlight) rehypePlugins.push([rehypeHighlight]);\n if (math) rehypePlugins.push([rehypeKatex]);\n\n // Build the processor. We type as `any` because unified's generic\n // Processor type changes shape with every .use() call, making\n // conditional plugin registration impractical with strict types.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let processor: any = unified().use(remarkParse);\n for (const [plugin, ...args] of remarkPlugins) {\n processor = processor.use(plugin, ...args);\n }\n processor = processor.use(remarkRehype, { allowDangerousHtml: true });\n for (const [plugin, ...args] of rehypePlugins) {\n processor = processor.use(plugin, ...args);\n }\n processor = processor.use(rehypeStringify);\n\n const result = await processor.process(parsed.body);\n\n return {\n html: String(result),\n frontmatter: parsed.frontmatter,\n body: parsed.body,\n };\n}\n","/**\n * Framework-agnostic line anchor utilities.\n * Parse GitHub-style line anchors (#L42, #L42-L50) and scroll/highlight\n * matching elements in a container.\n */\n\nconst HIGHLIGHT_CLASS = \"line-anchor-highlight\";\n\n/**\n * Parse a GitHub-style line anchor hash.\n * Supports: #L42, #L42-L50, #L42-50\n * Returns null if the hash is not a line anchor.\n */\nexport function parseLineAnchor(\n hash: string,\n): { start: number; end: number } | null {\n if (!hash) return null;\n const frag = hash.startsWith(\"#\") ? hash.slice(1) : hash;\n const match = frag.match(/^L(\\d+)(?:-L?(\\d+))?$/);\n if (!match) return null;\n\n const start = parseInt(match[1], 10);\n const end = match[2] ? parseInt(match[2], 10) : start;\n return { start: Math.min(start, end), end: Math.max(start, end) };\n}\n\n/**\n * Clear all line anchor highlights from a container.\n */\nexport function clearLineAnchorHighlights(container: HTMLElement): void {\n container.querySelectorAll(`.${HIGHLIGHT_CLASS}`).forEach((node) => {\n (node as HTMLElement).classList.remove(HIGHLIGHT_CLASS);\n });\n}\n\n/**\n * Scroll to and highlight line-anchored elements in a container.\n *\n * @param container - The DOM element containing rendered markdown\n * @param hash - The URL hash (e.g. \"#L42\" or \"#L42-L50\")\n * @returns A cleanup function that removes the highlights\n */\nexport function scrollToLineAnchor(\n container: HTMLElement,\n hash: string,\n): (() => void) | null {\n clearLineAnchorHighlights(container);\n\n const range = parseLineAnchor(hash);\n if (!range) return null;\n\n const blocks = container.querySelectorAll(\"[data-source-line]\");\n let firstMatch: HTMLElement | null = null;\n\n for (const block of blocks) {\n const line = parseInt(\n (block as HTMLElement).dataset.sourceLine || \"0\",\n 10,\n );\n if (line >= range.start && line <= range.end) {\n (block as HTMLElement).classList.add(HIGHLIGHT_CLASS);\n if (!firstMatch) firstMatch = block as HTMLElement;\n }\n }\n\n // If exact line not found, find the nearest block before the target line\n if (!firstMatch) {\n let closest: HTMLElement | null = null;\n let closestLine = 0;\n for (const block of blocks) {\n const line = parseInt(\n (block as HTMLElement).dataset.sourceLine || \"0\",\n 10,\n );\n if (line <= range.start && line > closestLine) {\n closestLine = line;\n closest = block as HTMLElement;\n }\n }\n if (closest) {\n closest.classList.add(HIGHLIGHT_CLASS);\n firstMatch = closest;\n }\n }\n\n // Scroll to the first highlighted element\n if (firstMatch) {\n requestAnimationFrame(() => {\n // Find the nearest scrollable ancestor\n const scrollParent = findScrollParent(container);\n if (scrollParent) {\n const offset =\n firstMatch!.getBoundingClientRect().top -\n scrollParent.getBoundingClientRect().top +\n scrollParent.scrollTop;\n scrollParent.scrollTo({ top: offset - 32, behavior: \"smooth\" });\n } else {\n firstMatch!.scrollIntoView({ behavior: \"smooth\", block: \"start\" });\n }\n });\n }\n\n return () => clearLineAnchorHighlights(container);\n}\n\nfunction findScrollParent(el: HTMLElement): HTMLElement | null {\n let node: HTMLElement | null = el;\n while (node) {\n const overflow = getComputedStyle(node).overflowY;\n if (overflow === \"auto\" || overflow === \"scroll\") return node;\n node = node.parentElement;\n }\n return null;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/rehypeSourceLines.ts","../src/sanitize.ts","../src/frontmatter.ts","../src/renderMarkdown.ts","../src/scrollToLineAnchor.ts","../src/mermaidCache.ts","../src/mermaidLoader.ts","../src/renderMermaidBlocks.ts","../src/resolveLinks.ts"],"names":["parseTOML"],"mappings":";;;;;;;;;;;;;;;;;AAWA,IAAM,UAAA,uBAAiB,GAAA,CAAI;AAAA,EACzB,GAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,YAAA;AAAA,EACA,KAAA;AAAA,EACA,OAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,SAAS,MAAM,IAAA,EAAsB;AACnC,EAAA,IAAI,cAAc,IAAA,EAAM;AACtB,IAAA,KAAA,MAAW,KAAA,IAAS,KAAK,QAAA,EAAU;AACjC,MAAA,IAAI,KAAA,CAAM,SAAS,SAAA,EAAW;AAC5B,QAAA,IAAI,UAAA,CAAW,IAAI,KAAA,CAAM,OAAO,KAAK,KAAA,CAAM,QAAA,EAAU,OAAO,IAAA,EAAM;AAChE,UAAA,KAAA,CAAM,UAAA,GAAa,KAAA,CAAM,UAAA,IAAc,EAAC;AACxC,UAAA,KAAA,CAAM,UAAA,CAAW,gBAAgB,CAAA,GAAI,KAAA,CAAM,SAAS,KAAA,CAAM,IAAA;AAAA,QAC5D;AACA,QAAA,KAAA,CAAM,KAAK,CAAA;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAM,oBAAsC,MAAM;AAChD,EAAA,OAAO,CAAC,IAAA,KAAe;AACrB,IAAA,KAAA,CAAM,IAAI,CAAA;AAAA,EACZ,CAAA;AACF,CAAA;AAEA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AA,CAAK,UAAA,CAAW,SAAS,KACzB,IAAA,CAAK,UAAA,CAAW,OAAO,CAAA,IACvB,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,IACnB,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,EACnB;AACA,QAAA,OAAO,SAAS,IAAI,CAAA,CAAA,CAAA;AAAA,MACtB;AAEA,MAAA,IAAI,QAAA,EAAU;AACZ,QAAA,MAAM,MAAA,GAAS,QAAA,CAAS,IAAA,EAAM,WAAW,CAAA;AACzC,QAAA,IAAI,WAAW,IAAA,EAAM;AACnB,UAAA,OAAO,SAAS,MAAM,CAAA,CAAA,CAAA;AAAA,QACxB;AACA,QAAA,OAAO,SAAS,IAAI,CAAA,CAAA,CAAA;AAAA,MACtB;AAGA,MAAA,MAAM,CAAC,QAAA,EAAU,QAAQ,CAAA,GAAI,IAAA,CAAK,MAAM,GAAG,CAAA;AAC3C,MAAA,MAAM,SAAA,GAAY,QAAA,CAAS,OAAA,CAAQ,OAAA,EAAS,EAAE,CAAA;AAC9C,MAAA,MAAM,eAAe,UAAA,GACjB,CAAA,EAAG,UAAU,CAAA,CAAA,EAAI,SAAS,CAAA,CAAA,GAC1B,SAAA;AACJ,MAAA,MAAM,OAAO,QAAA,CAAS,QAAA,CAAS,GAAG,CAAA,GAAI,QAAA,GAAW,GAAG,QAAQ,CAAA,CAAA,CAAA;AAC5D,MAAA,MAAM,SAAA,GAAY,CAAA,EAAG,IAAI,CAAA,EAAG,YAAY,GAAG,QAAA,GAAW,CAAA,CAAA,EAAI,QAAQ,CAAA,CAAA,GAAK,EAAE,CAAA,CAAA;AAEzE,MAAA,OAAO,SAAS,SAAS,CAAA,CAAA,CAAA;AAAA,IAC3B;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * Rehype plugin that adds `data-source-line` attributes to block-level\n * elements based on their position in the original markdown source.\n *\n * This enables GitHub-style line anchors (#L42, #L42-L50) by giving\n * each rendered block a traceable line number from the source.\n */\n\nimport type { Root, Element } from \"hast\";\nimport type { Plugin } from \"unified\";\n\nconst BLOCK_TAGS = new Set([\n \"p\",\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n \"li\",\n \"blockquote\",\n \"pre\",\n \"table\",\n \"tr\",\n \"ul\",\n \"ol\",\n \"hr\",\n \"div\",\n]);\n\nfunction visit(node: Root | Element) {\n if (\"children\" in node) {\n for (const child of node.children) {\n if (child.type === \"element\") {\n if (BLOCK_TAGS.has(child.tagName) && child.position?.start?.line) {\n child.properties = child.properties || {};\n child.properties[\"dataSourceLine\"] = child.position.start.line;\n }\n visit(child);\n }\n }\n }\n}\n\nconst rehypeSourceLines: Plugin<[], Root> = () => {\n return (tree: Root) => {\n visit(tree);\n };\n};\n\nexport default rehypeSourceLines;\n","/**\n * Sanitization schema for the rendering pipeline.\n * Allows GFM, KaTeX MathML, syntax highlighting classes, and\n * data-source-line attributes while blocking XSS vectors.\n */\n\nimport { defaultSchema } from \"rehype-sanitize\";\n\ntype Schema = typeof defaultSchema;\n\nexport const sanitizeSchema: Schema = {\n ...defaultSchema,\n tagNames: [\n ...(defaultSchema.tagNames || []),\n // KaTeX MathML elements\n \"math\",\n \"semantics\",\n \"mrow\",\n \"mi\",\n \"mo\",\n \"mn\",\n \"msup\",\n \"msub\",\n \"mfrac\",\n \"mover\",\n \"munder\",\n \"msqrt\",\n \"mroot\",\n \"mtable\",\n \"mtr\",\n \"mtd\",\n \"mtext\",\n \"mspace\",\n \"annotation\",\n // Other\n \"figure\",\n \"figcaption\",\n \"summary\",\n \"details\",\n ],\n attributes: {\n ...defaultSchema.attributes,\n \"*\": [\n ...(defaultSchema.attributes?.[\"*\"] || []),\n \"className\",\n \"style\",\n \"dataSourceLine\",\n ],\n code: [...(defaultSchema.attributes?.code || []), \"className\"],\n span: [...(defaultSchema.attributes?.span || []), \"className\", \"style\"],\n div: [...(defaultSchema.attributes?.div || []), \"className\", \"style\"],\n a: [...(defaultSchema.attributes?.a || []), \"id\", \"className\"],\n math: [\"xmlns\"],\n annotation: [\"encoding\"],\n img: [...(defaultSchema.attributes?.img || []), \"loading\"],\n td: [...(defaultSchema.attributes?.td || []), \"style\"],\n th: [...(defaultSchema.attributes?.th || []), \"style\"],\n },\n};\n","/**\n * Frontmatter parser for YAML (---) and TOML (+++) delimited content.\n * Works in both browser and server environments.\n */\n\nimport YAML from \"yaml\";\nimport { parse as parseTOML } from \"smol-toml\";\n\nexport type FrontmatterFormat = \"yaml\" | \"toml\" | \"none\";\n\nexport interface ParsedFrontmatter {\n frontmatter: Record<string, unknown>;\n body: string;\n format: FrontmatterFormat;\n}\n\n/**\n * Parse frontmatter from markdown content.\n * Supports YAML (delimited by ---) and TOML (delimited by +++).\n */\nexport function parseFrontmatter(content: string): ParsedFrontmatter {\n if (content.startsWith(\"+++\")) {\n return parseFrontmatterWithDelimiter(content, \"+++\", \"toml\");\n }\n if (content.startsWith(\"---\")) {\n return parseFrontmatterWithDelimiter(content, \"---\", \"yaml\");\n }\n return { frontmatter: {}, body: content, format: \"none\" };\n}\n\nfunction parseFrontmatterWithDelimiter(\n content: string,\n delimiter: string,\n format: \"yaml\" | \"toml\",\n): ParsedFrontmatter {\n const searchStart = delimiter.length;\n const endIndex = content.indexOf(`\\n${delimiter}`, searchStart);\n if (endIndex === -1) {\n return { frontmatter: {}, body: content, format: \"none\" };\n }\n\n const raw = content.slice(searchStart + 1, endIndex).trim();\n const bodyStart = endIndex + 1 + delimiter.length;\n const body = content.slice(bodyStart).replace(/^\\n/, \"\");\n\n try {\n const frontmatter =\n format === \"toml\"\n ? (parseTOML(raw) as Record<string, unknown>)\n : (YAML.parse(raw) as Record<string, unknown>);\n return { frontmatter: frontmatter || {}, body, format };\n } catch {\n return { frontmatter: {}, body: content, format: \"none\" };\n }\n}\n","/**\n * Framework-agnostic markdown -> HTML rendering pipeline.\n * Uses the same remark/rehype chain as the Vantage viewer.\n */\n\nimport { unified } from \"unified\";\nimport remarkParse from \"remark-parse\";\nimport remarkGfm from \"remark-gfm\";\nimport remarkMath from \"remark-math\";\nimport remarkRehype from \"remark-rehype\";\nimport rehypeRaw from \"rehype-raw\";\nimport rehypeSanitize from \"rehype-sanitize\";\nimport rehypeHighlight from \"rehype-highlight\";\nimport rehypeKatex from \"rehype-katex\";\nimport rehypeSlug from \"rehype-slug\";\nimport rehypeStringify from \"rehype-stringify\";\nimport rehypeSourceLines from \"./rehypeSourceLines.js\";\nimport { sanitizeSchema } from \"./sanitize.js\";\nimport { parseFrontmatter } from \"./frontmatter.js\";\nimport type { ParsedFrontmatter } from \"./frontmatter.js\";\n\nexport interface RenderOptions {\n /** Enable GFM tables, strikethrough, task lists (default: true) */\n gfm?: boolean;\n /** Enable KaTeX math rendering (default: true) */\n math?: boolean;\n /** Enable syntax highlighting (default: true) */\n highlight?: boolean;\n /** Add data-source-line attributes for line anchors (default: true) */\n sourceLines?: boolean;\n /** Enable XSS sanitization (default: true) */\n sanitize?: boolean;\n /** Parse and strip frontmatter (default: true) */\n frontmatter?: boolean;\n}\n\nexport interface RenderResult {\n /** The rendered HTML string */\n html: string;\n /** Parsed frontmatter (empty object if none or disabled) */\n frontmatter: Record<string, unknown>;\n /** The markdown body with frontmatter stripped */\n body: string;\n}\n\n/**\n * Render a markdown string to HTML using the full Vantage pipeline.\n *\n * Features (all enabled by default):\n * - GitHub Flavored Markdown (tables, strikethrough, task lists)\n * - KaTeX math rendering ($$...$$ blocks)\n * - Syntax highlighting via highlight.js\n * - `data-source-line` attributes for line anchors\n * - XSS sanitization\n * - Heading slugs/anchors\n * - YAML/TOML frontmatter parsing\n *\n * Mermaid diagrams are NOT rendered server-side (they require a browser).\n * Mermaid code blocks are preserved as `<pre><code class=\"language-mermaid\">`.\n * Use the React `<MarkdownViewer>` component for client-side mermaid rendering.\n */\nexport async function renderMarkdown(\n content: string,\n options: RenderOptions = {},\n): Promise<RenderResult> {\n const {\n gfm = true,\n math = true,\n highlight = true,\n sourceLines = true,\n sanitize = true,\n frontmatter: parseFm = true,\n } = options;\n\n // Parse frontmatter\n let parsed: ParsedFrontmatter;\n if (parseFm) {\n parsed = parseFrontmatter(content);\n } else {\n parsed = { frontmatter: {}, body: content, format: \"none\" };\n }\n\n // Build the unified pipeline using a single chain.\n // We use `any` for the processor to avoid unified's strict generic\n // type constraints that make conditional plugin registration painful.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const remarkPlugins: [any, ...any[]][] = [];\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const rehypePlugins: [any, ...any[]][] = [];\n\n if (gfm) remarkPlugins.push([remarkGfm, { singleTilde: false }]);\n if (math) remarkPlugins.push([remarkMath, { singleDollarTextMath: false }]);\n\n rehypePlugins.push([rehypeRaw]);\n if (sourceLines) rehypePlugins.push([rehypeSourceLines]);\n if (sanitize) rehypePlugins.push([rehypeSanitize, sanitizeSchema]);\n rehypePlugins.push([rehypeSlug]);\n if (highlight) rehypePlugins.push([rehypeHighlight]);\n if (math) rehypePlugins.push([rehypeKatex]);\n\n // Build the processor. We type as `any` because unified's generic\n // Processor type changes shape with every .use() call, making\n // conditional plugin registration impractical with strict types.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let processor: any = unified().use(remarkParse);\n for (const [plugin, ...args] of remarkPlugins) {\n processor = processor.use(plugin, ...args);\n }\n processor = processor.use(remarkRehype, { allowDangerousHtml: true });\n for (const [plugin, ...args] of rehypePlugins) {\n processor = processor.use(plugin, ...args);\n }\n processor = processor.use(rehypeStringify);\n\n const result = await processor.process(parsed.body);\n\n return {\n html: String(result),\n frontmatter: parsed.frontmatter,\n body: parsed.body,\n };\n}\n","/**\n * Framework-agnostic line anchor utilities.\n * Parse GitHub-style line anchors (#L42, #L42-L50) and scroll/highlight\n * matching elements in a container.\n */\n\nconst HIGHLIGHT_CLASS = \"line-anchor-highlight\";\n\n/**\n * Parse a GitHub-style line anchor hash.\n * Supports: #L42, #L42-L50, #L42-50\n * Returns null if the hash is not a line anchor.\n */\nexport function parseLineAnchor(\n hash: string,\n): { start: number; end: number } | null {\n if (!hash) return null;\n const frag = hash.startsWith(\"#\") ? hash.slice(1) : hash;\n const match = frag.match(/^L(\\d+)(?:-L?(\\d+))?$/);\n if (!match) return null;\n\n const start = parseInt(match[1], 10);\n const end = match[2] ? parseInt(match[2], 10) : start;\n return { start: Math.min(start, end), end: Math.max(start, end) };\n}\n\n/**\n * Clear all line anchor highlights from a container.\n */\nexport function clearLineAnchorHighlights(container: HTMLElement): void {\n container.querySelectorAll(`.${HIGHLIGHT_CLASS}`).forEach((node) => {\n (node as HTMLElement).classList.remove(HIGHLIGHT_CLASS);\n });\n}\n\n/**\n * Scroll to and highlight line-anchored elements in a container.\n *\n * @param container - The DOM element containing rendered markdown\n * @param hash - The URL hash (e.g. \"#L42\" or \"#L42-L50\")\n * @returns A cleanup function that removes the highlights\n */\nexport function scrollToLineAnchor(\n container: HTMLElement,\n hash: string,\n): (() => void) | null {\n clearLineAnchorHighlights(container);\n\n const range = parseLineAnchor(hash);\n if (!range) return null;\n\n const blocks = container.querySelectorAll(\"[data-source-line]\");\n let firstMatch: HTMLElement | null = null;\n\n for (const block of blocks) {\n const line = parseInt(\n (block as HTMLElement).dataset.sourceLine || \"0\",\n 10,\n );\n if (line >= range.start && line <= range.end) {\n (block as HTMLElement).classList.add(HIGHLIGHT_CLASS);\n if (!firstMatch) firstMatch = block as HTMLElement;\n }\n }\n\n // If exact line not found, find the nearest block before the target line\n if (!firstMatch) {\n let closest: HTMLElement | null = null;\n let closestLine = 0;\n for (const block of blocks) {\n const line = parseInt(\n (block as HTMLElement).dataset.sourceLine || \"0\",\n 10,\n );\n if (line <= range.start && line > closestLine) {\n closestLine = line;\n closest = block as HTMLElement;\n }\n }\n if (closest) {\n closest.classList.add(HIGHLIGHT_CLASS);\n firstMatch = closest;\n }\n }\n\n // Scroll to the first highlighted element\n if (firstMatch) {\n requestAnimationFrame(() => {\n // Find the nearest scrollable ancestor\n const scrollParent = findScrollParent(container);\n if (scrollParent) {\n const offset =\n firstMatch!.getBoundingClientRect().top -\n scrollParent.getBoundingClientRect().top +\n scrollParent.scrollTop;\n scrollParent.scrollTo({ top: offset - 32, behavior: \"smooth\" });\n } else {\n firstMatch!.scrollIntoView({ behavior: \"smooth\", block: \"start\" });\n }\n });\n }\n\n return () => clearLineAnchorHighlights(container);\n}\n\nfunction findScrollParent(el: HTMLElement): HTMLElement | null {\n let node: HTMLElement | null = el;\n while (node) {\n const overflow = getComputedStyle(node).overflowY;\n if (overflow === \"auto\" || overflow === \"scroll\") return node;\n node = node.parentElement;\n }\n return null;\n}\n","// Global cache for rendered SVGs to prevent re-renders\nexport const svgCache = new Map<string, string>();\n\nexport function clearMermaidCache() {\n svgCache.clear();\n}\n","import type mermaidAPI from \"mermaid\";\n\nlet mermaidInstance: typeof mermaidAPI | null = null;\nlet mermaidLoading: Promise<typeof mermaidAPI> | null = null;\n\nconst isDark = () =>\n typeof document !== \"undefined\" &&\n document.documentElement.classList.contains(\"dark\");\n\nexport async function getMermaid(): Promise<typeof mermaidAPI> {\n if (mermaidInstance) return mermaidInstance;\n if (!mermaidLoading) {\n mermaidLoading = import(\"mermaid\").then((mod) => {\n const m = mod.default;\n m.initialize({\n startOnLoad: false,\n theme: isDark() ? \"dark\" : \"default\",\n securityLevel: \"strict\",\n suppressErrorRendering: true,\n });\n mermaidInstance = m;\n return m;\n });\n }\n return mermaidLoading;\n}\n\nexport function resetMermaidLoader() {\n mermaidInstance = null;\n mermaidLoading = null;\n}\n","/**\n * Client-side utility to find and render mermaid code blocks in a container.\n *\n * After calling `renderMarkdown()`, mermaid blocks come through as\n * `<pre><code class=\"language-mermaid\">...</code></pre>`. This function\n * finds those blocks and replaces them with rendered SVG diagrams.\n *\n * Framework-agnostic — works in any browser environment.\n */\n\nimport { svgCache } from \"./mermaidCache.js\";\nimport { getMermaid } from \"./mermaidLoader.js\";\n\nexport interface RenderMermaidOptions {\n /** CSS class to add to the SVG wrapper div (default: \"mermaid\") */\n className?: string;\n /** Called when a diagram fails to render */\n onError?: (code: string, error: Error) => void;\n}\n\n/**\n * Find all `<pre><code class=\"language-mermaid\">` blocks in a container\n * and replace them with rendered SVG diagrams.\n *\n * @param container - DOM element containing rendered markdown HTML\n * @param options - Optional configuration\n * @returns Promise that resolves when all diagrams are rendered\n *\n * @example\n * ```ts\n * import { renderMarkdown, renderMermaidBlocks } from \"vantage-md\";\n *\n * const { html } = await renderMarkdown(content);\n * container.innerHTML = html;\n * await renderMermaidBlocks(container);\n * ```\n */\nexport async function renderMermaidBlocks(\n container: HTMLElement,\n options: RenderMermaidOptions = {},\n): Promise<void> {\n const { className = \"mermaid\", onError } = options;\n\n const codeBlocks = container.querySelectorAll(\n 'pre > code.language-mermaid, pre > code[class*=\"language-mermaid\"]',\n );\n if (codeBlocks.length === 0) return;\n\n const mermaid = await getMermaid();\n\n const renderPromises = Array.from(codeBlocks).map(async (codeEl) => {\n const preEl = codeEl.parentElement;\n if (!preEl) return;\n\n const code = codeEl.textContent || \"\";\n if (!code.trim()) return;\n\n // Check cache first\n const cached = svgCache.get(code);\n if (cached) {\n replaceWithSvg(preEl, cached, className);\n return;\n }\n\n try {\n // Generate a stable ID from code hash\n let hash = 0;\n for (let i = 0; i < code.length; i++) {\n hash = (hash << 5) - hash + code.charCodeAt(i);\n hash = hash & hash;\n }\n const id = `mermaid-${Math.abs(hash).toString(36)}-${Date.now()}`;\n\n const { svg } = await mermaid.render(id, code);\n svgCache.set(code, svg);\n replaceWithSvg(preEl, svg, className);\n } catch (err) {\n if (onError) {\n onError(code, err instanceof Error ? err : new Error(String(err)));\n }\n }\n });\n\n await Promise.all(renderPromises);\n}\n\nfunction replaceWithSvg(\n preEl: HTMLElement,\n svg: string,\n className: string,\n): void {\n const wrapper = document.createElement(\"div\");\n wrapper.className = className;\n wrapper.innerHTML = svg;\n preEl.replaceWith(wrapper);\n}\n","/**\n * Rewrite relative links in rendered markdown HTML.\n *\n * After `renderMarkdown()` produces HTML, relative `href` values need to\n * be mapped to the consumer's routing structure. This utility handles that\n * without requiring a DOM — it operates on the HTML string directly.\n */\n\nexport interface ResolveLinkOptions {\n /** Base path to prepend to relative links (default: \"/\") */\n basePath?: string;\n /**\n * Custom rewriter function. Called for every relative href.\n * Return the rewritten href, or null to leave it unchanged.\n * If provided, basePath is ignored.\n */\n rewriter?: (href: string, currentPath: string) => string | null;\n /** Current file path — used to resolve relative references like `./other.md` */\n currentPath?: string;\n}\n\n/**\n * Rewrite relative links in rendered HTML.\n *\n * Processes all `href=\"...\"` attributes, skipping:\n * - Absolute URLs (http://, https://, mailto:, etc.)\n * - Anchor-only links (#section)\n * - Already-absolute paths (/path/to/file)\n *\n * @example\n * ```ts\n * import { renderMarkdown, resolveLinks } from \"vantage-md\";\n *\n * const { html } = await renderMarkdown(content);\n *\n * // Simple: prepend a base path\n * const resolved = resolveLinks(html, { basePath: \"/docs/\", currentPath: \"guides/setup.md\" });\n *\n * // Custom: full control over link rewriting\n * const resolved = resolveLinks(html, {\n * currentPath: \"guides/setup.md\",\n * rewriter: (href, currentPath) => `/kb/${currentPath}/../${href}`,\n * });\n * ```\n */\nexport function resolveLinks(\n html: string,\n options: ResolveLinkOptions = {},\n): string {\n const { basePath = \"/\", rewriter, currentPath = \"\" } = options;\n\n // Resolve the directory of the current file\n const parts = currentPath.split(\"/\");\n parts.pop(); // remove filename\n const currentDir = parts.join(\"/\");\n\n return html.replace(\n /href=\"([^\"]*?)\"/g,\n (_match: string, href: string): string => {\n // Skip absolute URLs, anchors, and already-absolute paths\n if (\n href.startsWith(\"http://\") ||\n href.startsWith(\"https://\") ||\n href.startsWith(\"mailto:\") ||\n href.startsWith(\"data:\") ||\n href.startsWith(\"#\") ||\n href.startsWith(\"/\")\n ) {\n return `href=\"${href}\"`;\n }\n\n if (rewriter) {\n const result = rewriter(href, currentPath);\n if (result !== null) {\n return `href=\"${result}\"`;\n }\n return `href=\"${href}\"`;\n }\n\n // Default: resolve relative to currentPath, prepend basePath\n const [pathPart, hashPart] = href.split(\"#\");\n const cleanHref = pathPart.replace(/^\\.\\//, \"\");\n const resolvedPath = currentDir\n ? `${currentDir}/${cleanHref}`\n : cleanHref;\n const base = basePath.endsWith(\"/\") ? basePath : `${basePath}/`;\n const finalHref = `${base}${resolvedPath}${hashPart ? `#${hashPart}` : \"\"}`;\n\n return `href=\"${finalHref}\"`;\n },\n );\n}\n"]}
|
package/dist/prose.css
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/* src/styles/prose.css */
|
|
2
|
+
.vantage-prose {
|
|
3
|
+
color: #334155;
|
|
4
|
+
line-height: 1.7;
|
|
5
|
+
max-width: none;
|
|
6
|
+
}
|
|
7
|
+
.dark .vantage-prose {
|
|
8
|
+
color: #cbd5e1;
|
|
9
|
+
}
|
|
10
|
+
.vantage-prose h1,
|
|
11
|
+
.vantage-prose h2,
|
|
12
|
+
.vantage-prose h3,
|
|
13
|
+
.vantage-prose h4,
|
|
14
|
+
.vantage-prose h5,
|
|
15
|
+
.vantage-prose h6 {
|
|
16
|
+
font-weight: 600;
|
|
17
|
+
letter-spacing: -0.01em;
|
|
18
|
+
color: #0f172a;
|
|
19
|
+
}
|
|
20
|
+
.dark .vantage-prose h1,
|
|
21
|
+
.dark .vantage-prose h2,
|
|
22
|
+
.dark .vantage-prose h3,
|
|
23
|
+
.dark .vantage-prose h4,
|
|
24
|
+
.dark .vantage-prose h5,
|
|
25
|
+
.dark .vantage-prose h6 {
|
|
26
|
+
color: #f1f5f9;
|
|
27
|
+
}
|
|
28
|
+
.vantage-prose h1 {
|
|
29
|
+
font-size: 2em;
|
|
30
|
+
margin-bottom: 0.75rem;
|
|
31
|
+
padding-bottom: 0.3em;
|
|
32
|
+
border-bottom: 1px solid #e2e8f0;
|
|
33
|
+
}
|
|
34
|
+
.dark .vantage-prose h1 {
|
|
35
|
+
border-bottom-color: #334155;
|
|
36
|
+
}
|
|
37
|
+
.vantage-prose h2 {
|
|
38
|
+
font-size: 1.5em;
|
|
39
|
+
margin-top: 1.5rem;
|
|
40
|
+
margin-bottom: 0.75rem;
|
|
41
|
+
padding-bottom: 0.3em;
|
|
42
|
+
border-bottom: 1px solid #e2e8f0;
|
|
43
|
+
}
|
|
44
|
+
.dark .vantage-prose h2 {
|
|
45
|
+
border-bottom-color: #334155;
|
|
46
|
+
}
|
|
47
|
+
.vantage-prose h3 {
|
|
48
|
+
font-size: 1.25em;
|
|
49
|
+
margin-top: 1.5rem;
|
|
50
|
+
margin-bottom: 0.5rem;
|
|
51
|
+
}
|
|
52
|
+
.vantage-prose h4 {
|
|
53
|
+
font-size: 1em;
|
|
54
|
+
margin-top: 1.5rem;
|
|
55
|
+
margin-bottom: 0.5rem;
|
|
56
|
+
}
|
|
57
|
+
.vantage-prose p {
|
|
58
|
+
margin-top: 16px;
|
|
59
|
+
margin-bottom: 16px;
|
|
60
|
+
line-height: 1.5;
|
|
61
|
+
}
|
|
62
|
+
.vantage-prose ul {
|
|
63
|
+
margin-top: 16px;
|
|
64
|
+
margin-bottom: 16px;
|
|
65
|
+
list-style-type: disc;
|
|
66
|
+
padding-left: 2em;
|
|
67
|
+
}
|
|
68
|
+
.vantage-prose ol {
|
|
69
|
+
margin-top: 16px;
|
|
70
|
+
margin-bottom: 16px;
|
|
71
|
+
padding-left: 2em;
|
|
72
|
+
}
|
|
73
|
+
.vantage-prose li {
|
|
74
|
+
margin-top: 0.125rem;
|
|
75
|
+
margin-bottom: 0.125rem;
|
|
76
|
+
}
|
|
77
|
+
.vantage-prose pre {
|
|
78
|
+
background: #f8fafc;
|
|
79
|
+
border: 1px solid #e2e8f0;
|
|
80
|
+
padding: 1rem;
|
|
81
|
+
border-radius: 0.375rem;
|
|
82
|
+
font-size: 85%;
|
|
83
|
+
line-height: 1.45;
|
|
84
|
+
overflow-x: auto;
|
|
85
|
+
}
|
|
86
|
+
.dark .vantage-prose pre {
|
|
87
|
+
background: #1e293b;
|
|
88
|
+
border-color: #334155;
|
|
89
|
+
}
|
|
90
|
+
.vantage-prose code {
|
|
91
|
+
background: #f1f5f9;
|
|
92
|
+
padding: 0.2em 0.4em;
|
|
93
|
+
border-radius: 0.375rem;
|
|
94
|
+
font-size: 85%;
|
|
95
|
+
font-family:
|
|
96
|
+
ui-monospace,
|
|
97
|
+
SFMono-Regular,
|
|
98
|
+
Menlo,
|
|
99
|
+
Monaco,
|
|
100
|
+
Consolas,
|
|
101
|
+
monospace;
|
|
102
|
+
font-weight: normal;
|
|
103
|
+
border: 1px solid rgb(226 232 240 / 0.5);
|
|
104
|
+
color: #1e293b;
|
|
105
|
+
}
|
|
106
|
+
.dark .vantage-prose code {
|
|
107
|
+
background: #1e293b;
|
|
108
|
+
border-color: rgb(51 65 85 / 0.5);
|
|
109
|
+
color: #e2e8f0;
|
|
110
|
+
}
|
|
111
|
+
.vantage-prose pre code {
|
|
112
|
+
background: none;
|
|
113
|
+
padding: 0;
|
|
114
|
+
border-radius: 0;
|
|
115
|
+
font-size: inherit;
|
|
116
|
+
border: none;
|
|
117
|
+
color: inherit;
|
|
118
|
+
}
|
|
119
|
+
.vantage-prose a {
|
|
120
|
+
color: #2563eb;
|
|
121
|
+
text-decoration: none;
|
|
122
|
+
}
|
|
123
|
+
.vantage-prose a:hover {
|
|
124
|
+
text-decoration: underline;
|
|
125
|
+
}
|
|
126
|
+
.dark .vantage-prose a {
|
|
127
|
+
color: #60a5fa;
|
|
128
|
+
}
|
|
129
|
+
.vantage-prose img {
|
|
130
|
+
border-radius: 0.5rem;
|
|
131
|
+
margin-top: 1rem;
|
|
132
|
+
margin-bottom: 1rem;
|
|
133
|
+
}
|
|
134
|
+
.vantage-prose blockquote {
|
|
135
|
+
border-left: 0.25em solid #cbd5e1;
|
|
136
|
+
padding-left: 1rem;
|
|
137
|
+
color: #475569;
|
|
138
|
+
font-style: italic;
|
|
139
|
+
}
|
|
140
|
+
.dark .vantage-prose blockquote {
|
|
141
|
+
border-left-color: #475569;
|
|
142
|
+
color: #94a3b8;
|
|
143
|
+
}
|
|
144
|
+
.vantage-prose table {
|
|
145
|
+
font-size: 0.875rem;
|
|
146
|
+
border-collapse: collapse;
|
|
147
|
+
width: 100%;
|
|
148
|
+
}
|
|
149
|
+
.vantage-prose th,
|
|
150
|
+
.vantage-prose td {
|
|
151
|
+
padding: 0.375rem 0.75rem;
|
|
152
|
+
border: 1px solid #e2e8f0;
|
|
153
|
+
}
|
|
154
|
+
.dark .vantage-prose th,
|
|
155
|
+
.dark .vantage-prose td {
|
|
156
|
+
border-color: #334155;
|
|
157
|
+
}
|
|
158
|
+
.vantage-prose hr {
|
|
159
|
+
border: none;
|
|
160
|
+
border-top: 1px solid #e2e8f0;
|
|
161
|
+
margin: 1.5rem 0;
|
|
162
|
+
}
|
|
163
|
+
.dark .vantage-prose hr {
|
|
164
|
+
border-top-color: #334155;
|
|
165
|
+
}
|
package/dist/react.cjs
CHANGED
|
@@ -838,6 +838,78 @@ async function renderMarkdown(content, options = {}) {
|
|
|
838
838
|
};
|
|
839
839
|
}
|
|
840
840
|
|
|
841
|
+
// src/renderMermaidBlocks.ts
|
|
842
|
+
async function renderMermaidBlocks(container, options = {}) {
|
|
843
|
+
const { className = "mermaid", onError } = options;
|
|
844
|
+
const codeBlocks = container.querySelectorAll(
|
|
845
|
+
'pre > code.language-mermaid, pre > code[class*="language-mermaid"]'
|
|
846
|
+
);
|
|
847
|
+
if (codeBlocks.length === 0) return;
|
|
848
|
+
const mermaid = await getMermaid();
|
|
849
|
+
const renderPromises = Array.from(codeBlocks).map(async (codeEl) => {
|
|
850
|
+
const preEl = codeEl.parentElement;
|
|
851
|
+
if (!preEl) return;
|
|
852
|
+
const code = codeEl.textContent || "";
|
|
853
|
+
if (!code.trim()) return;
|
|
854
|
+
const cached = svgCache.get(code);
|
|
855
|
+
if (cached) {
|
|
856
|
+
replaceWithSvg(preEl, cached, className);
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
try {
|
|
860
|
+
let hash = 0;
|
|
861
|
+
for (let i = 0; i < code.length; i++) {
|
|
862
|
+
hash = (hash << 5) - hash + code.charCodeAt(i);
|
|
863
|
+
hash = hash & hash;
|
|
864
|
+
}
|
|
865
|
+
const id = `mermaid-${Math.abs(hash).toString(36)}-${Date.now()}`;
|
|
866
|
+
const { svg } = await mermaid.render(id, code);
|
|
867
|
+
svgCache.set(code, svg);
|
|
868
|
+
replaceWithSvg(preEl, svg, className);
|
|
869
|
+
} catch (err) {
|
|
870
|
+
if (onError) {
|
|
871
|
+
onError(code, err instanceof Error ? err : new Error(String(err)));
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
await Promise.all(renderPromises);
|
|
876
|
+
}
|
|
877
|
+
function replaceWithSvg(preEl, svg, className) {
|
|
878
|
+
const wrapper = document.createElement("div");
|
|
879
|
+
wrapper.className = className;
|
|
880
|
+
wrapper.innerHTML = svg;
|
|
881
|
+
preEl.replaceWith(wrapper);
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
// src/resolveLinks.ts
|
|
885
|
+
function resolveLinks(html, options = {}) {
|
|
886
|
+
const { basePath = "/", rewriter, currentPath = "" } = options;
|
|
887
|
+
const parts = currentPath.split("/");
|
|
888
|
+
parts.pop();
|
|
889
|
+
const currentDir = parts.join("/");
|
|
890
|
+
return html.replace(
|
|
891
|
+
/href="([^"]*?)"/g,
|
|
892
|
+
(_match, href) => {
|
|
893
|
+
if (href.startsWith("http://") || href.startsWith("https://") || href.startsWith("mailto:") || href.startsWith("data:") || href.startsWith("#") || href.startsWith("/")) {
|
|
894
|
+
return `href="${href}"`;
|
|
895
|
+
}
|
|
896
|
+
if (rewriter) {
|
|
897
|
+
const result = rewriter(href, currentPath);
|
|
898
|
+
if (result !== null) {
|
|
899
|
+
return `href="${result}"`;
|
|
900
|
+
}
|
|
901
|
+
return `href="${href}"`;
|
|
902
|
+
}
|
|
903
|
+
const [pathPart, hashPart] = href.split("#");
|
|
904
|
+
const cleanHref = pathPart.replace(/^\.\//, "");
|
|
905
|
+
const resolvedPath = currentDir ? `${currentDir}/${cleanHref}` : cleanHref;
|
|
906
|
+
const base = basePath.endsWith("/") ? basePath : `${basePath}/`;
|
|
907
|
+
const finalHref = `${base}${resolvedPath}${hashPart ? `#${hashPart}` : ""}`;
|
|
908
|
+
return `href="${finalHref}"`;
|
|
909
|
+
}
|
|
910
|
+
);
|
|
911
|
+
}
|
|
912
|
+
|
|
841
913
|
exports.FrontmatterDisplay = FrontmatterDisplay;
|
|
842
914
|
exports.MarkdownViewer = MarkdownViewer;
|
|
843
915
|
exports.MermaidDiagram = MermaidDiagram;
|
|
@@ -846,6 +918,8 @@ exports.parseFrontmatter = parseFrontmatter;
|
|
|
846
918
|
exports.parseLineAnchor = parseLineAnchor;
|
|
847
919
|
exports.rehypeSourceLines = rehypeSourceLines_default;
|
|
848
920
|
exports.renderMarkdown = renderMarkdown;
|
|
921
|
+
exports.renderMermaidBlocks = renderMermaidBlocks;
|
|
922
|
+
exports.resolveLinks = resolveLinks;
|
|
849
923
|
exports.sanitizeSchema = sanitizeSchema;
|
|
850
924
|
exports.scrollToLineAnchor = scrollToLineAnchor;
|
|
851
925
|
exports.useLineAnchor = useLineAnchor;
|