Version 1.6.2
Overview
Updated 5 min ago
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
$ pnpm add mdast2docx docxor
$ npm install mdast2docx docxor
$ 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
Production Best Practices & Migration
Architectural best practices for LLM pipelines, server vs browser execution, and migrating from legacy versions.
Umbrella Architecture & Package Structure
Why mdast2docx acts as the all-in-one distribution bundle and how to choose between umbrella vs scoped packages.