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.cjs
CHANGED
|
@@ -260,11 +260,110 @@ function findScrollParent(el) {
|
|
|
260
260
|
return null;
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
// src/mermaidCache.ts
|
|
264
|
+
var svgCache = /* @__PURE__ */ new Map();
|
|
265
|
+
|
|
266
|
+
// src/mermaidLoader.ts
|
|
267
|
+
var mermaidInstance = null;
|
|
268
|
+
var mermaidLoading = null;
|
|
269
|
+
var isDark = () => typeof document !== "undefined" && document.documentElement.classList.contains("dark");
|
|
270
|
+
async function getMermaid() {
|
|
271
|
+
if (mermaidInstance) return mermaidInstance;
|
|
272
|
+
if (!mermaidLoading) {
|
|
273
|
+
mermaidLoading = import('mermaid').then((mod) => {
|
|
274
|
+
const m = mod.default;
|
|
275
|
+
m.initialize({
|
|
276
|
+
startOnLoad: false,
|
|
277
|
+
theme: isDark() ? "dark" : "default",
|
|
278
|
+
securityLevel: "strict",
|
|
279
|
+
suppressErrorRendering: true
|
|
280
|
+
});
|
|
281
|
+
mermaidInstance = m;
|
|
282
|
+
return m;
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
return mermaidLoading;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/renderMermaidBlocks.ts
|
|
289
|
+
async function renderMermaidBlocks(container, options = {}) {
|
|
290
|
+
const { className = "mermaid", onError } = options;
|
|
291
|
+
const codeBlocks = container.querySelectorAll(
|
|
292
|
+
'pre > code.language-mermaid, pre > code[class*="language-mermaid"]'
|
|
293
|
+
);
|
|
294
|
+
if (codeBlocks.length === 0) return;
|
|
295
|
+
const mermaid = await getMermaid();
|
|
296
|
+
const renderPromises = Array.from(codeBlocks).map(async (codeEl) => {
|
|
297
|
+
const preEl = codeEl.parentElement;
|
|
298
|
+
if (!preEl) return;
|
|
299
|
+
const code = codeEl.textContent || "";
|
|
300
|
+
if (!code.trim()) return;
|
|
301
|
+
const cached = svgCache.get(code);
|
|
302
|
+
if (cached) {
|
|
303
|
+
replaceWithSvg(preEl, cached, className);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
let hash = 0;
|
|
308
|
+
for (let i = 0; i < code.length; i++) {
|
|
309
|
+
hash = (hash << 5) - hash + code.charCodeAt(i);
|
|
310
|
+
hash = hash & hash;
|
|
311
|
+
}
|
|
312
|
+
const id = `mermaid-${Math.abs(hash).toString(36)}-${Date.now()}`;
|
|
313
|
+
const { svg } = await mermaid.render(id, code);
|
|
314
|
+
svgCache.set(code, svg);
|
|
315
|
+
replaceWithSvg(preEl, svg, className);
|
|
316
|
+
} catch (err) {
|
|
317
|
+
if (onError) {
|
|
318
|
+
onError(code, err instanceof Error ? err : new Error(String(err)));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
await Promise.all(renderPromises);
|
|
323
|
+
}
|
|
324
|
+
function replaceWithSvg(preEl, svg, className) {
|
|
325
|
+
const wrapper = document.createElement("div");
|
|
326
|
+
wrapper.className = className;
|
|
327
|
+
wrapper.innerHTML = svg;
|
|
328
|
+
preEl.replaceWith(wrapper);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// src/resolveLinks.ts
|
|
332
|
+
function resolveLinks(html, options = {}) {
|
|
333
|
+
const { basePath = "/", rewriter, currentPath = "" } = options;
|
|
334
|
+
const parts = currentPath.split("/");
|
|
335
|
+
parts.pop();
|
|
336
|
+
const currentDir = parts.join("/");
|
|
337
|
+
return html.replace(
|
|
338
|
+
/href="([^"]*?)"/g,
|
|
339
|
+
(_match, href) => {
|
|
340
|
+
if (href.startsWith("http://") || href.startsWith("https://") || href.startsWith("mailto:") || href.startsWith("data:") || href.startsWith("#") || href.startsWith("/")) {
|
|
341
|
+
return `href="${href}"`;
|
|
342
|
+
}
|
|
343
|
+
if (rewriter) {
|
|
344
|
+
const result = rewriter(href, currentPath);
|
|
345
|
+
if (result !== null) {
|
|
346
|
+
return `href="${result}"`;
|
|
347
|
+
}
|
|
348
|
+
return `href="${href}"`;
|
|
349
|
+
}
|
|
350
|
+
const [pathPart, hashPart] = href.split("#");
|
|
351
|
+
const cleanHref = pathPart.replace(/^\.\//, "");
|
|
352
|
+
const resolvedPath = currentDir ? `${currentDir}/${cleanHref}` : cleanHref;
|
|
353
|
+
const base = basePath.endsWith("/") ? basePath : `${basePath}/`;
|
|
354
|
+
const finalHref = `${base}${resolvedPath}${hashPart ? `#${hashPart}` : ""}`;
|
|
355
|
+
return `href="${finalHref}"`;
|
|
356
|
+
}
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
263
360
|
exports.clearLineAnchorHighlights = clearLineAnchorHighlights;
|
|
264
361
|
exports.parseFrontmatter = parseFrontmatter;
|
|
265
362
|
exports.parseLineAnchor = parseLineAnchor;
|
|
266
363
|
exports.rehypeSourceLines = rehypeSourceLines_default;
|
|
267
364
|
exports.renderMarkdown = renderMarkdown;
|
|
365
|
+
exports.renderMermaidBlocks = renderMermaidBlocks;
|
|
366
|
+
exports.resolveLinks = resolveLinks;
|
|
268
367
|
exports.sanitizeSchema = sanitizeSchema;
|
|
269
368
|
exports.scrollToLineAnchor = scrollToLineAnchor;
|
|
270
369
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rehypeSourceLines.ts","../src/sanitize.ts","../src/frontmatter.ts","../src/renderMarkdown.ts","../src/scrollToLineAnchor.ts"],"names":["defaultSchema","parseTOML","YAML","remarkGfm","remarkMath","rehypeRaw","rehypeSanitize","rehypeSlug","rehypeHighlight","rehypeKatex","unified","remarkParse","remarkRehype","rehypeStringify"],"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,IAAO,yBAAA,GAAQ;ACxCR,IAAM,cAAA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AAU,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.cjs","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":["defaultSchema","parseTOML","YAML","remarkGfm","remarkMath","rehypeRaw","rehypeSanitize","rehypeSlug","rehypeHighlight","rehyp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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.cjs","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/index.d.cts
CHANGED
|
@@ -108,4 +108,83 @@ declare function parseFrontmatter(content: string): ParsedFrontmatter;
|
|
|
108
108
|
type Schema = typeof defaultSchema;
|
|
109
109
|
declare const sanitizeSchema: Schema;
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Client-side utility to find and render mermaid code blocks in a container.
|
|
113
|
+
*
|
|
114
|
+
* After calling `renderMarkdown()`, mermaid blocks come through as
|
|
115
|
+
* `<pre><code class="language-mermaid">...</code></pre>`. This function
|
|
116
|
+
* finds those blocks and replaces them with rendered SVG diagrams.
|
|
117
|
+
*
|
|
118
|
+
* Framework-agnostic — works in any browser environment.
|
|
119
|
+
*/
|
|
120
|
+
interface RenderMermaidOptions {
|
|
121
|
+
/** CSS class to add to the SVG wrapper div (default: "mermaid") */
|
|
122
|
+
className?: string;
|
|
123
|
+
/** Called when a diagram fails to render */
|
|
124
|
+
onError?: (code: string, error: Error) => void;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Find all `<pre><code class="language-mermaid">` blocks in a container
|
|
128
|
+
* and replace them with rendered SVG diagrams.
|
|
129
|
+
*
|
|
130
|
+
* @param container - DOM element containing rendered markdown HTML
|
|
131
|
+
* @param options - Optional configuration
|
|
132
|
+
* @returns Promise that resolves when all diagrams are rendered
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* import { renderMarkdown, renderMermaidBlocks } from "vantage-md";
|
|
137
|
+
*
|
|
138
|
+
* const { html } = await renderMarkdown(content);
|
|
139
|
+
* container.innerHTML = html;
|
|
140
|
+
* await renderMermaidBlocks(container);
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function renderMermaidBlocks(container: HTMLElement, options?: RenderMermaidOptions): Promise<void>;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Rewrite relative links in rendered markdown HTML.
|
|
147
|
+
*
|
|
148
|
+
* After `renderMarkdown()` produces HTML, relative `href` values need to
|
|
149
|
+
* be mapped to the consumer's routing structure. This utility handles that
|
|
150
|
+
* without requiring a DOM — it operates on the HTML string directly.
|
|
151
|
+
*/
|
|
152
|
+
interface ResolveLinkOptions {
|
|
153
|
+
/** Base path to prepend to relative links (default: "/") */
|
|
154
|
+
basePath?: string;
|
|
155
|
+
/**
|
|
156
|
+
* Custom rewriter function. Called for every relative href.
|
|
157
|
+
* Return the rewritten href, or null to leave it unchanged.
|
|
158
|
+
* If provided, basePath is ignored.
|
|
159
|
+
*/
|
|
160
|
+
rewriter?: (href: string, currentPath: string) => string | null;
|
|
161
|
+
/** Current file path — used to resolve relative references like `./other.md` */
|
|
162
|
+
currentPath?: string;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Rewrite relative links in rendered HTML.
|
|
166
|
+
*
|
|
167
|
+
* Processes all `href="..."` attributes, skipping:
|
|
168
|
+
* - Absolute URLs (http://, https://, mailto:, etc.)
|
|
169
|
+
* - Anchor-only links (#section)
|
|
170
|
+
* - Already-absolute paths (/path/to/file)
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* import { renderMarkdown, resolveLinks } from "vantage-md";
|
|
175
|
+
*
|
|
176
|
+
* const { html } = await renderMarkdown(content);
|
|
177
|
+
*
|
|
178
|
+
* // Simple: prepend a base path
|
|
179
|
+
* const resolved = resolveLinks(html, { basePath: "/docs/", currentPath: "guides/setup.md" });
|
|
180
|
+
*
|
|
181
|
+
* // Custom: full control over link rewriting
|
|
182
|
+
* const resolved = resolveLinks(html, {
|
|
183
|
+
* currentPath: "guides/setup.md",
|
|
184
|
+
* rewriter: (href, currentPath) => `/kb/${currentPath}/../${href}`,
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
declare function resolveLinks(html: string, options?: ResolveLinkOptions): string;
|
|
189
|
+
|
|
190
|
+
export { type FrontmatterFormat, type ParsedFrontmatter, type RenderMermaidOptions, type RenderOptions, type RenderResult, type ResolveLinkOptions, clearLineAnchorHighlights, parseFrontmatter, parseLineAnchor, rehypeSourceLines, renderMarkdown, renderMermaidBlocks, resolveLinks, sanitizeSchema, scrollToLineAnchor };
|
package/dist/index.d.ts
CHANGED
|
@@ -108,4 +108,83 @@ declare function parseFrontmatter(content: string): ParsedFrontmatter;
|
|
|
108
108
|
type Schema = typeof defaultSchema;
|
|
109
109
|
declare const sanitizeSchema: Schema;
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Client-side utility to find and render mermaid code blocks in a container.
|
|
113
|
+
*
|
|
114
|
+
* After calling `renderMarkdown()`, mermaid blocks come through as
|
|
115
|
+
* `<pre><code class="language-mermaid">...</code></pre>`. This function
|
|
116
|
+
* finds those blocks and replaces them with rendered SVG diagrams.
|
|
117
|
+
*
|
|
118
|
+
* Framework-agnostic — works in any browser environment.
|
|
119
|
+
*/
|
|
120
|
+
interface RenderMermaidOptions {
|
|
121
|
+
/** CSS class to add to the SVG wrapper div (default: "mermaid") */
|
|
122
|
+
className?: string;
|
|
123
|
+
/** Called when a diagram fails to render */
|
|
124
|
+
onError?: (code: string, error: Error) => void;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Find all `<pre><code class="language-mermaid">` blocks in a container
|
|
128
|
+
* and replace them with rendered SVG diagrams.
|
|
129
|
+
*
|
|
130
|
+
* @param container - DOM element containing rendered markdown HTML
|
|
131
|
+
* @param options - Optional configuration
|
|
132
|
+
* @returns Promise that resolves when all diagrams are rendered
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts
|
|
136
|
+
* import { renderMarkdown, renderMermaidBlocks } from "vantage-md";
|
|
137
|
+
*
|
|
138
|
+
* const { html } = await renderMarkdown(content);
|
|
139
|
+
* container.innerHTML = html;
|
|
140
|
+
* await renderMermaidBlocks(container);
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function renderMermaidBlocks(container: HTMLElement, options?: RenderMermaidOptions): Promise<void>;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Rewrite relative links in rendered markdown HTML.
|
|
147
|
+
*
|
|
148
|
+
* After `renderMarkdown()` produces HTML, relative `href` values need to
|
|
149
|
+
* be mapped to the consumer's routing structure. This utility handles that
|
|
150
|
+
* without requiring a DOM — it operates on the HTML string directly.
|
|
151
|
+
*/
|
|
152
|
+
interface ResolveLinkOptions {
|
|
153
|
+
/** Base path to prepend to relative links (default: "/") */
|
|
154
|
+
basePath?: string;
|
|
155
|
+
/**
|
|
156
|
+
* Custom rewriter function. Called for every relative href.
|
|
157
|
+
* Return the rewritten href, or null to leave it unchanged.
|
|
158
|
+
* If provided, basePath is ignored.
|
|
159
|
+
*/
|
|
160
|
+
rewriter?: (href: string, currentPath: string) => string | null;
|
|
161
|
+
/** Current file path — used to resolve relative references like `./other.md` */
|
|
162
|
+
currentPath?: string;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Rewrite relative links in rendered HTML.
|
|
166
|
+
*
|
|
167
|
+
* Processes all `href="..."` attributes, skipping:
|
|
168
|
+
* - Absolute URLs (http://, https://, mailto:, etc.)
|
|
169
|
+
* - Anchor-only links (#section)
|
|
170
|
+
* - Already-absolute paths (/path/to/file)
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* import { renderMarkdown, resolveLinks } from "vantage-md";
|
|
175
|
+
*
|
|
176
|
+
* const { html } = await renderMarkdown(content);
|
|
177
|
+
*
|
|
178
|
+
* // Simple: prepend a base path
|
|
179
|
+
* const resolved = resolveLinks(html, { basePath: "/docs/", currentPath: "guides/setup.md" });
|
|
180
|
+
*
|
|
181
|
+
* // Custom: full control over link rewriting
|
|
182
|
+
* const resolved = resolveLinks(html, {
|
|
183
|
+
* currentPath: "guides/setup.md",
|
|
184
|
+
* rewriter: (href, currentPath) => `/kb/${currentPath}/../${href}`,
|
|
185
|
+
* });
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
declare function resolveLinks(html: string, options?: ResolveLinkOptions): string;
|
|
189
|
+
|
|
190
|
+
export { type FrontmatterFormat, type ParsedFrontmatter, type RenderMermaidOptions, type RenderOptions, type RenderResult, type ResolveLinkOptions, clearLineAnchorHighlights, parseFrontmatter, parseLineAnchor, rehypeSourceLines, renderMarkdown, renderMermaidBlocks, resolveLinks, sanitizeSchema, scrollToLineAnchor };
|
package/dist/index.js
CHANGED
|
@@ -244,6 +244,103 @@ function findScrollParent(el) {
|
|
|
244
244
|
return null;
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
|
|
247
|
+
// src/mermaidCache.ts
|
|
248
|
+
var svgCache = /* @__PURE__ */ new Map();
|
|
249
|
+
|
|
250
|
+
// src/mermaidLoader.ts
|
|
251
|
+
var mermaidInstance = null;
|
|
252
|
+
var mermaidLoading = null;
|
|
253
|
+
var isDark = () => typeof document !== "undefined" && document.documentElement.classList.contains("dark");
|
|
254
|
+
async function getMermaid() {
|
|
255
|
+
if (mermaidInstance) return mermaidInstance;
|
|
256
|
+
if (!mermaidLoading) {
|
|
257
|
+
mermaidLoading = import('mermaid').then((mod) => {
|
|
258
|
+
const m = mod.default;
|
|
259
|
+
m.initialize({
|
|
260
|
+
startOnLoad: false,
|
|
261
|
+
theme: isDark() ? "dark" : "default",
|
|
262
|
+
securityLevel: "strict",
|
|
263
|
+
suppressErrorRendering: true
|
|
264
|
+
});
|
|
265
|
+
mermaidInstance = m;
|
|
266
|
+
return m;
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
return mermaidLoading;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// src/renderMermaidBlocks.ts
|
|
273
|
+
async function renderMermaidBlocks(container, options = {}) {
|
|
274
|
+
const { className = "mermaid", onError } = options;
|
|
275
|
+
const codeBlocks = container.querySelectorAll(
|
|
276
|
+
'pre > code.language-mermaid, pre > code[class*="language-mermaid"]'
|
|
277
|
+
);
|
|
278
|
+
if (codeBlocks.length === 0) return;
|
|
279
|
+
const mermaid = await getMermaid();
|
|
280
|
+
const renderPromises = Array.from(codeBlocks).map(async (codeEl) => {
|
|
281
|
+
const preEl = codeEl.parentElement;
|
|
282
|
+
if (!preEl) return;
|
|
283
|
+
const code = codeEl.textContent || "";
|
|
284
|
+
if (!code.trim()) return;
|
|
285
|
+
const cached = svgCache.get(code);
|
|
286
|
+
if (cached) {
|
|
287
|
+
replaceWithSvg(preEl, cached, className);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
try {
|
|
291
|
+
let hash = 0;
|
|
292
|
+
for (let i = 0; i < code.length; i++) {
|
|
293
|
+
hash = (hash << 5) - hash + code.charCodeAt(i);
|
|
294
|
+
hash = hash & hash;
|
|
295
|
+
}
|
|
296
|
+
const id = `mermaid-${Math.abs(hash).toString(36)}-${Date.now()}`;
|
|
297
|
+
const { svg } = await mermaid.render(id, code);
|
|
298
|
+
svgCache.set(code, svg);
|
|
299
|
+
replaceWithSvg(preEl, svg, className);
|
|
300
|
+
} catch (err) {
|
|
301
|
+
if (onError) {
|
|
302
|
+
onError(code, err instanceof Error ? err : new Error(String(err)));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
await Promise.all(renderPromises);
|
|
307
|
+
}
|
|
308
|
+
function replaceWithSvg(preEl, svg, className) {
|
|
309
|
+
const wrapper = document.createElement("div");
|
|
310
|
+
wrapper.className = className;
|
|
311
|
+
wrapper.innerHTML = svg;
|
|
312
|
+
preEl.replaceWith(wrapper);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// src/resolveLinks.ts
|
|
316
|
+
function resolveLinks(html, options = {}) {
|
|
317
|
+
const { basePath = "/", rewriter, currentPath = "" } = options;
|
|
318
|
+
const parts = currentPath.split("/");
|
|
319
|
+
parts.pop();
|
|
320
|
+
const currentDir = parts.join("/");
|
|
321
|
+
return html.replace(
|
|
322
|
+
/href="([^"]*?)"/g,
|
|
323
|
+
(_match, href) => {
|
|
324
|
+
if (href.startsWith("http://") || href.startsWith("https://") || href.startsWith("mailto:") || href.startsWith("data:") || href.startsWith("#") || href.startsWith("/")) {
|
|
325
|
+
return `href="${href}"`;
|
|
326
|
+
}
|
|
327
|
+
if (rewriter) {
|
|
328
|
+
const result = rewriter(href, currentPath);
|
|
329
|
+
if (result !== null) {
|
|
330
|
+
return `href="${result}"`;
|
|
331
|
+
}
|
|
332
|
+
return `href="${href}"`;
|
|
333
|
+
}
|
|
334
|
+
const [pathPart, hashPart] = href.split("#");
|
|
335
|
+
const cleanHref = pathPart.replace(/^\.\//, "");
|
|
336
|
+
const resolvedPath = currentDir ? `${currentDir}/${cleanHref}` : cleanHref;
|
|
337
|
+
const base = basePath.endsWith("/") ? basePath : `${basePath}/`;
|
|
338
|
+
const finalHref = `${base}${resolvedPath}${hashPart ? `#${hashPart}` : ""}`;
|
|
339
|
+
return `href="${finalHref}"`;
|
|
340
|
+
}
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export { clearLineAnchorHighlights, parseFrontmatter, parseLineAnchor, rehypeSourceLines_default as rehypeSourceLines, renderMarkdown, renderMermaidBlocks, resolveLinks, sanitizeSchema, scrollToLineAnchor };
|
|
248
345
|
//# sourceMappingURL=index.js.map
|
|
249
346
|
//# sourceMappingURL=index.js.map
|