Version 0.1.1
Overview
Updated 22 Oct 2026
@m2d/remark-docx-node: Unified & Remark compiler plugin that converts Markdown AST trees to Microsoft Word (.docx) on Node.js with native image rasterization and Mermaid diagram rendering.
✨ Why @m2d/remark-docx-node?
- 🚀 Server-Side Native Rendering: Uses
@m2d/image-node(powered bysharp) and@m2d/mermaid-node(powered bybeautiful-mermaid) for high-performance server generation. - 🖼️ Local & Remote Images: Automatically loads images from disk, HTTPS URLs, and data URIs without headless browser overhead.
- 📊 Mermaid Diagrams: Compiles flowcharts, sequence diagrams, and architecture charts directly into Word DrawingML images.
- 📦 Zero DOM Requirement: Runs purely on Node.js without requiring JSDOM, Puppeteer, or Canvas polyfills.
💡 Looking for browser / client-side compilation? Use @m2d/remark-docx.
📦 Installation
# with pnpm
$ pnpm add @m2d/remark-docx-node docx unified remark-parse remark-gfmor
# with npm
$ npm install @m2d/remark-docx-node docx unified remark-parse remark-gfmor
# with yarn
$ yarn add @m2d/remark-docx-node docx unified remark-parse remark-gfm🚀 Quick Start
import fs from "node:fs/promises";
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkGfm from "remark-gfm";
import { remarkDocx } from "@m2d/remark-docx-node";
const processor = unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkDocx, "buffer");
const markdown = `
# Server Report 🚀
Here is a diagram:
\`\`\`mermaid
graph TD
Client --> API
API --> Database
\`\`\`
`;
const file = await processor.process(markdown);
const buffer = (await file.result) as Buffer;
await fs.writeFile("report.docx", buffer);⚙️ Options & Plugin Configuration
import { remarkDocx } from "@m2d/remark-docx-node";
const processor = unified().use(
remarkDocx,
"buffer", // outputType
{ title: "My Document" }, // docxProps
{}, // sectionProps
{
// Node-specific plugin configurations
image: { pathPrefix: "./assets", maxW: 600 },
mermaid: { transparent: true },
list: { defaultBullets: true },
table: {},
emoji: {},
},
);License
This library is licensed under the MIT open-source license.
with 💖 by Mayank Kumar Chaudhari