@md2docx/mermaid
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

@m2d/mermaid

test Maintainability codecov Version Downloads npm bundle size

🧩 Plugin for @m2d/core that renders Mermaid diagrams and mindmaps from Markdown code blocks and converts them into DOCX-compatible SVG images.


✨ Features

  • Supports mermaid, mmd, and mindmap 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).

📦 Installation

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 or mmd as code block languages. The plugin will auto-adjust for Mermaid syntax quirks.


⚙️ Plugin Options

mermaidPlugin({
  mermaidConfig: {
    theme: "default",
    fontFamily: "Arial",
    // See all options: https://mermaid.js.org/configuration.html
  },
});

🧠 How It Works

  • Scans for code blocks with language mermaid, mmd, or mindmap.
  • Uses Mermaid to render diagrams as SVG.
  • Injects the SVG as an mdast node, ready for DOCX embedding.

📄 License

Licensed under the MPL-2.0 License.


⭐ Support Us

If you find this useful:


Made with 💖 by Mayank Kumar Chaudhari

Package Sidebar

Install

npm i @md2docx/mermaid

Weekly Downloads

14

Version

0.0.3

License

MPL-2.0

Unpacked Size

7.64 kB

Total Files

5

Last publish

Collaborators

  • mayank1513