🧩 Plugin for @m2d/core that renders Mermaid diagrams and mindmaps from Markdown code blocks and converts them into DOCX-compatible SVG images.
- Supports
mermaid
,mmd
, andmindmap
code blocks. - Converts diagrams to inline SVG for high-quality DOCX rendering.
- Compatible with the
mdast2docx
and@m2d
plugin ecosystem. - Fully customizable via Mermaid config options.
- Handles rendering quirks with default sane settings (e.g.,
fontFamily
).
pnpm install @m2d/mermaid
or
yarn add @m2d/mermaid
or
npm add @m2d/mermaid
---
## 📦 Usage
```ts
import { mermaidPlugin } from "@m2d/mermaid";
import { imagePlugin } from "@m2d/image";
import { toDocx } from "@m2d/core";
const converter = await toDocx({
plugins: [mermaidPlugin(), imagePlugin()],
});
const docxBuffer = await converter.convert(`# Diagram\n\n\`\`\`mermaid\ngraph TD; A-->B;\`\`\``);
You can also use
mindmap
ormmd
as code block languages. The plugin will auto-adjust for Mermaid syntax quirks.
mermaidPlugin({
mermaidConfig: {
theme: "default",
fontFamily: "Arial",
// See all options: https://mermaid.js.org/configuration.html
},
});
- Scans for code blocks with language
mermaid
,mmd
, ormindmap
. - Uses Mermaid to render diagrams as SVG.
- Injects the SVG as an
mdast
node, ready for DOCX embedding.
Licensed under the MPL-2.0 License.
If you find this useful:
- ⭐ Star mdast2docx on GitHub
- ❤️ Consider sponsoring
Made with 💖 by Mayank Kumar Chaudhari