
Product
Announcing Bun and vlt Support in Socket
Bringing supply chain security to the next generation of JavaScript package managers
@m2d/mermaid
Advanced tools
Enhance Markdown-to-DOCX conversion with Mermaid and mindmap diagram support using this plugin for @m2d/core. Converts code blocks into SVG images with customizable Mermaid config.
@m2d/mermaid🧠 A plugin for
@m2d/corethat transformsmermaid,mmd, andmindmapcode blocks into high-quality inline SVGs, ready for DOCX, HTML, or future PDF export. ✨ Built with caching, configurability, and AI/automation-friendly hooks in mind.
@m2d/mermaid?This plugin is part of the mdast2docx ecosystem — a modular pipeline to convert Markdown (via MDAST) into richly formatted documents.
Whether you're using this in a generative AI pipeline, a Markdown editor, or a publishing workflow, @m2d/mermaid helps you render diagrams just once, cache the result smartly, and export it across formats.
mermaid, mmd, and mindmap code blocks.@m2d/core and mdast2docx ecosystem.pnpm install @m2d/mermaid
or
yarn add @m2d/mermaid
or
npm add @m2d/mermaid
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(`# Flow\n\n\`\`\`mermaid\ngraph TD; A-->B;\`\`\``);
✅ You can use mindmap or mmd code blocks too — the plugin handles them all.
mermaidPlugin({
mermaidConfig: {
theme: "default",
fontFamily: "Arial",
// See all options: https://mermaid.js.org/configuration.html
},
idb: true, // Enable IndexedDB caching (default: true)
maxAgeMinutes: 60 * 24 * 30, // Optional cache expiry (default: 30 days)
fixMermaid: (code, error) => {
// Optional: auto-fix bad syntax using AI or heuristics
return code.replace(/;/g, " --> ");
},
});
Looks for code blocks with lang = mermaid, mmd, or mindmap.
Cleans and normalizes the code (but leaves sensitive diagram types untouched).
Uses Mermaid to generate an SVG.
Replaces the block with a centered <svg> node inside your MDAST.
Adds caching to speed up repeated renders:
Let’s say your users generate Mermaid charts via LLMs (and they sometimes mess up):
mermaidPlugin({
fixMermaid: async (code, error) => {
const response = await fetch("/fix-diagram", {
method: "POST",
body: JSON.stringify({ code, error: error.message }),
});
return await response.text(); // New (hopefully fixed) diagram code
},
});
📚 See Mermaid docs for supported syntax and examples.
@m2d EcosystemThis plugin works best when used with:
@m2d/core – Orchestrates plugins and generates DOCX@m2d/image – Handles image conversion and embedding@m2d/html – Parses inline HTML into MDAST nodes🌐 Try it live: mdast2docx.vercel.app
To avoid indexed-db bloat, the plugin:
cleanupDone flag.Licensed under the MPL-2.0 License.
Have an idea? Spotted a bug? Want to level up documentation?
Made with 💖 by Mayank Kumar Chaudhari and contributors
FAQs
Enhance Markdown-to-DOCX conversion with Mermaid and mindmap diagram support using this plugin for @m2d/core. Converts code blocks into SVG images with customizable Mermaid config.
We found that @m2d/mermaid demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies

Product
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.