Gathering detailed insights and metrics for mdast-to-docx
Gathering detailed insights and metrics for mdast-to-docx
Gathering detailed insights and metrics for mdast-to-docx
Gathering detailed insights and metrics for mdast-to-docx
@m2d/mdast
Extended MDAST types and custom node data for mdast2docx with support for DOCX formatting.
remark-docx
remark plugin to compile markdown to docx (Microsoft Word, Office Open XML).
md-to-docx
Convert Markdown Abstract Syntax Tree (MDAST) to DOCX seamlessly. Supports footnotes, images, links, and customizable document properties.
@mdast2docx/mdast
Extended MDAST types and custom node data for mdast2docx with support for DOCX formatting.
Utility to convert MDAST (Markdown Abstract Syntax Tree) to DOCX
npm install mdast-to-docx
Typescript
Module System
Node Version
NPM Version
TypeScript (46.11%)
JavaScript (34.45%)
SCSS (19.44%)
Total Downloads
1,816
Last Day
1
Last Week
23
Last Month
313
Last Year
1,816
MPL-2.0 License
15 Stars
647 Commits
3 Forks
1 Watchers
11 Branches
1 Contributors
Updated on Aug 16, 2025
Latest Version
1.4.1
Package Id
mdast-to-docx@1.4.1
Unpacked Size
633.65 kB
Size
184.84 kB
File Count
26
NPM Version
10.8.2
Node Version
20.19.2
Published on
Jun 25, 2025
Cumulative downloads
Total Downloads
Last Day
-50%
1
Compared to previous day
Last Week
-25.8%
23
Compared to previous week
Last Month
-41.7%
313
Compared to previous month
Last Year
0%
1,816
Compared to previous year
🚀 Effortlessly convert Markdown Abstract Syntax Trees (MDAST) to DOCX.
✅ MDAST to DOCX conversion — Supports standard Markdown elements
✅ Footnotes handling — Converts Markdown footnotes to DOCX format
✅ Tables support — Converts Markdown tables into DOCX tables
✅ Hyperlink support — External and internal hyperlinks are now fully functional
✅ New Plugin Architecture — Extend and customize DOCX output with plugins
✅ Customizable image handling — Images are now supported via @m2d/image
plugin
Note: Images are no longer supported by default. To enable image support, use the image plugin from
@m2d/image
ormdast2docx/plugins
explicitly.
This change helps us keep the library lean and extensible by community via plugins.
Modern Generative AI tools often produce structured content in Markdown (MD) format. However, converting this AI-generated Markdown into professional DOCX documents requires an additional transformation step. This is where MDAST to DOCX comes in.
By integrating MDAST to DOCX, AI applications can seamlessly export Markdown-based content into DOCX, making it more accessible, editable, and shareable. 🚀
1pnpm add mdast2docx
1pnpm add @m2d/core @m2d/html @m2d/image @m2d/math @m2d/table @m2d/list @m2d/mdast
1import { toDocx } from "mdast2docx"; 2import { unified } from "unified"; 3import remarkParse from "remark-parse"; 4import remarkMmd from "remark-mmd"; // Assumed MMD plugin 5 6const markdown = ` 7# Sample Document 8This is a **bold** text and _italic_ text. 9 10> A blockquote example 11 12- List Item 1 13- List Item 2 14 15[Click Here](https://example.com) 16 17This is a footnote reference[^1]. 18 19[^1]: This is the footnote content. 20`; 21 22const mdast = unified().use(remarkParse).use(remarkMmd).parse(markdown); 23 24(async () => { 25 const docxBlob = await toDocx(mdast, { title: "My Document" }, {}); 26 const url = URL.createObjectURL(docxBlob as Blob); 27 const link = document.createElement("a"); 28 link.href = url; 29 link.download = "document.docx"; 30 link.click(); 31 URL.revokeObjectURL(url); 32})();
toDocx(astInputs, docxProps, defaultSectionProps, outputType?)
Parameter | Type | Description |
---|---|---|
astInputs | Root | { ast: Root; props?: ISectionProps }[] | Single or multiple MDAST trees with optional section properties. |
docxProps | IDocxProps | General document properties (title, styles, metadata). |
defaultSectionProps | ISectionProps | Default properties for document sections. |
outputType (optional) | "blob" (default) | "buffer" | "base64" | Format of the generated DOCX document. |
📌 Returns: A Promise
resolving to a DOCX document in the chosen format.
Markdown Syntax | Supported in DOCX |
---|---|
Headings # H1 to ###### H6 | ✅ |
Paragraphs | ✅ |
Bold **text** & Italics _text_ | ✅ |
Blockquotes > quote | ✅ |
Lists (ordered & unordered) | ✅ (ordered lists via listPlugin ) |
Links [text](url) | ✅ |
Images  | ✅ (via imagePlugin ) |
Code Blocks `code` | ✅ |
Footnotes [^1] | ✅ |
Tables | ✅ (via tablePlugin ) |
Hyperlinks (external & internal) | ✅ |
Latex Math | ✅ (via mathPlugin ) |
HTML Tags | ✅ (via htmlPlugin ) |
You can customize the DOCX output using ISectionProps
and IDocxProps
.
1const docxProps = { 2 title: "Styled Document", 3 author: "John Doe", 4}; 5 6const sectionProps = { 7 page: { margin: { top: 1000, bottom: 1000, left: 1200, right: 1200 } }, 8}; 9 10const docxBlob = await toDocx(mdast, docxProps, sectionProps);
Plugins allow extending functionality like adding image or table support.
1import { toDocx } from "@m2d/core"; 2import { imagePlugin } from "@m2d/image"; 3import { tablePlugin } from "@m2d/table"; 4import { listPlugin } from "@m2d/list"; 5import { mathPlugin } from "@m2d/math"; 6 7const downloadDocx = () => { 8 toDocx( 9 mdast, 10 {}, 11 { plugins: [imagePlugin(), tablePlugin(), listPlugin(), mathPlugin()] }, 12 "blob", 13 ).then(blob => { 14 const url = URL.createObjectURL(blob as Blob); 15 const link = document.createElement("a"); 16 link.href = url; 17 link.download = "my-document.docx"; 18 link.click(); 19 URL.revokeObjectURL(url); 20 }); 21};
📖 More details:
AI tools often generate Markdown as output (e.g., reports, documentation, summaries). This library makes it easy to convert those Markdown-based outputs into rich DOCX documents.
unified
and remark
to parse Markdown into MDAST, and then convert to DOCX seamlesslyWe welcome contributions! To get started:
git checkout -b feature-new
)git commit -m "Add new feature"
)git push origin feature-new
)The community can create plugins to extend the functionality of this library. For inspiration, check out the existing plugins in the lib/src/plugins
folder.
This project is licensed under MPL-2.0. See the LICENSE file for details.
Thanks to the docx.js and unified.js ecosystems for making this possible.
⭐ Star this repository if you find it useful!
❤️ Support our work by sponsoring.
Made with 💖 by Mayank Kumar Chaudhari
No vulnerabilities found.