UNPKG

fumadocs-core

Version:

The React.js library for building a documentation website

31 lines (30 loc) • 817 B
import { replaceSource } from "./stringifier.js"; import { d as walk } from "../utils-C7sTEOQI.js"; // src/mdx-plugins/remark-mdx-mermaid.ts function toMDX(code) { return { type: "mdxJsxFlowElement", name: "Mermaid", attributes: [{ type: "mdxJsxAttribute", name: "chart", value: code.trim() }], children: [] }; } /** * Convert `mermaid` codeblocks into `<Mermaid />` MDX component */ function remarkMdxMermaid(options = {}) { const { lang = "mermaid" } = options; return (tree, file) => { walk(tree, (node, idx, parent) => { if (node.type !== "code") return; if (node.lang !== lang || !node.value || typeof idx !== "number" || !parent) return; replaceSource(file, node, (s) => s.stringify(node)); parent.children[idx] = toMDX(node.value); }); }; } export { remarkMdxMermaid };