mdast2docx 
mdast2docx: The complete, all-in-one Markdown Abstract Syntax Tree (MDAST) to Microsoft Word DOCX compiler bundle.
Features
- All-in-One Distribution: Includes
@m2d/coreand the complete official plugin ecosystem (table,list,image,math,mermaid,html,emoji). - Optimized for Generative AI: Perfect bridge for converting LLM-generated Markdown into professionally styled Word documents.
- Native Word Structures: Renders genuine OpenXML tables, native editable equations (
docx.Math), multi-tier outline numbering, and vector diagrams. - Isomorphic Runtimes: Works identically on both the client (browser downloads via
Blob) and server (high-throughput Node.js batch generation viaBuffer). - Streamlined Subpaths: Clean access via
mdast2docx,mdast2docx/plugins,mdast2docx/section, andmdast2docx/utils.
Installation
This package (md-to-docx) is an official alias of mdast2docx.
Why does this exist?
We provide this package to offer shorter import paths and improved discoverability. While both packages provide identical functionality, mdast2docx is the primary source of truth.
Which one should I use?
- Use md-to-docx if you prefer the shorter name or specific branding or ESM Only.
- Use mdast2docx for the most stable long-term reference and standard alignment.
| Feature | mdast2docx | md-to-docx |
|---|---|---|
| Source Code | Primary | Proxy |
| Updates | Immediate | Synchronized (Immediately) |
| Bundle Size | 100% | 100% (Zero overhead) |
| Format | ESM + CJS | ESM Only |
| Maintenance | Primary | Proxy (inherits) |
| Security | Primary | Proxy (inherits) |
Maintenance & Support
Security: Security audits are performed on the canonical package; this alias inherits all security patches automatically.
$ pnpm add mdast2docx docx
or
$ npm install mdast2docx docx
or
$ yarn add mdast2docx docx
Quick Start
import { toDocx } from "mdast2docx";
import {
htmlPlugin,
imagePlugin,
listPlugin,
mathPlugin,
mermaidPlugin,
tablePlugin,
} from "mdast2docx/plugins";
import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import remarkParse from "remark-parse";
import { unified } from "unified";
const markdown = `
# Executive Summary
This document was generated automatically from **Markdown**.
## Key Metrics
| Metric | Target | Actual |
| :----- | :----: | -----: |
| Latency | < 50ms | 28ms |
| Uptime | 99.9% | 99.99% |
## System Flowchart
\`\`\`mermaid
graph LR
Ingest --> Process --> Storage
\`\`\`
Inline formula: $E = mc^2$
`;
// 1. Parse markdown with unified
const mdast = unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkMath)
.parse(markdown);
// 2. Compile to Word DOCX with bundled plugins
const docxBlob = await toDocx(mdast, {}, {
plugins: [
htmlPlugin(),
mermaidPlugin(),
imagePlugin(),
tablePlugin(),
listPlugin(),
mathPlugin(),
],
});
Bundled Plugins
The mdast2docx/plugins subpath provides instant access to all official plugins:
| Plugin | Source Package | Capability |
|---|---|---|
tablePlugin |
@m2d/table |
Rich borders, repeating headers, cell fills, and column alignment |
listPlugin |
@m2d/list |
Hierarchical decimal numbering (1.1.1) and multi-tier bullet glyphs |
imagePlugin |
@m2d/image |
SVG and URL image resolution, rasterization, and dimensions |
mermaidPlugin |
@m2d/mermaid |
Client-side Mermaid diagrams with auto-healing syntax |
mathPlugin |
@m2d/math |
LaTeX math translated to native editable Word MathML equations |
htmlPlugin |
@m2d/html |
Embedded HTML tag parsing and inline CSS styles |
emojiPlugin |
@m2d/emoji |
GitHub emoji shortcodes to Unicode characters |
Deep Dive Guides
- Umbrella Architecture & Package Structure Guide: Subpath exports, ecosystem structure, and choosing between umbrella vs scoped packages.
- Production Best Practices & Migration Guide: AI pipelines, server vs browser deployment, table layouts, and v1.x migration.
License
This library is licensed under the MIT open-source license.
with by Mayank Kumar Chaudhari
Keywords
mdastmarkdowngenerative-aidocxmd2docxmarkdown-to-docxmdast-to-docxconverterremarkunifiedfootnotesimageshyperlinkstext-processingdocument-generatortypescriptopen-sourcemoderncustomizableseamless-integrationcutting-edgecompatibilityprogressivefrontenddocument-generationweb-developmentrich-textexportgoogle-sheetsms-wordautomationmayank1513