# mdast-to-docx

> Convert Markdown Abstract Syntax Tree (MDAST) to DOCX seamlessly. Supports footnotes, images, links, and customizable document properties.

Latest version **1.6.4** (published 2026-10-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install mdast-to-docx
pnpm add mdast-to-docx
yarn add mdast-to-docx
bun add mdast-to-docx
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.6.4 |
| Published | 2026-10-22 |
| First published | 2025-03-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Author | Mayank Kumar Chaudhari |
| Maintainers | mayank1513 |
| Keywords | mdast, markdown, generative-ai, docx, md2docx, markdown-to-docx, mdast-to-docx, converter, remark, unified, footnotes, images, hyperlinks, text-processing, document-generator, typescript, open-source, modern, customizable, seamless-integration, cutting-edge, compatibility, progressive, frontend, document-generation, web-development, rich-text, export, google-sheets, ms-word, automation, mayank1513 |

## Links

- npm: https://www.npmjs.com/package/mdast-to-docx
- Repository: https://github.com/md2docx/md2docx
- Homepage: https://github.com/md2docx/md2docx/blob/main/packages/mdast2docx/README.md
- Issues: https://github.com/md2docx/md2docx/issues
- Funding: https://github.com/sponsors/md2docx
- npm.io page: https://npm.io/package/mdast-to-docx

## Dependencies (1)

- [mdast2docx](https://npm.io/package/mdast2docx.md) 1.6.4

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 1.6.4 (latest) — 2026-10-22
- 1.6.1 — 2025-10-31
- 1.6.0 — 2025-09-26
- 1.5.1 — 2025-09-25
- 1.5.0 — 2025-09-24
- 1.4.2 — 2025-09-06
- 1.4.1 — 2025-06-25
- 1.4.0 — 2025-06-24
- 1.3.5 — 2025-06-17
- 1.3.4 — 2025-06-17
- 1.3.3 — 2025-06-17
- 1.3.2 — 2025-06-17
- 1.3.1 — 2025-06-16
- 1.3.0 — 2025-06-12
- 1.2.0 — 2025-06-02
- … 16 more at https://npm.io/package/mdast-to-docx/versions

## README

# mdast2docx <img src="https://raw.githubusercontent.com/mayank1513/mayank1513/main/popper.png" style="height: 40px"/>

<p className="flex gap-2">
  <a href="https://github.com/md2docx/md2docx/actions/workflows/ci.yml" rel="noopener noreferrer">
    <img alt="CI" src="https://github.com/md2docx/md2docx/actions/workflows/ci.yml/badge.svg" />
  </a>
  <a href="https://codecov.io/gh/md2docx/md2docx/tree/main/packages/mdast2docx" rel="noopener noreferrer">
    <img alt="codecov" src="https://codecov.io/gh/md2docx/md2docx/graph/badge.svg?flag=mdast2docx" />
  </a> 
  <a href="https://npmjs.com/package/mdast2docx" rel="noopener noreferrer">
    <img alt="npm version" src="https://img.shields.io/npm/v/mdast2docx" />
  </a>
  <a href="https://npmjs.com/package/mdast2docx" rel="noopener noreferrer">
    <img alt="npm downloads" src="https://img.shields.io/npm/d18m/mdast2docx" />
  </a>
  <a href="https://npmjs.com/package/mdast2docx" rel="noopener noreferrer">
    <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/mdast2docx" />
  </a>
  <img alt="license" src="https://img.shields.io/npm/l/mdast2docx" />
</p>

> mdast2docx: The complete, all-in-one Markdown Abstract Syntax Tree (MDAST) to Microsoft Word DOCX compiler bundle.

---

## ✨ Features

- 📦 **All-in-One Distribution**: Includes `@m2d/core` and 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 via `Buffer`).
- ⚡ **Streamlined Subpaths**: Clean access via `mdast2docx`, `mdast2docx/plugins`, `mdast2docx/section`, and `mdast2docx/utils`.

---

## 📦 Installation


> [!TIP]
> **This package (mdast-to-docx) is an official alias of [mdast2docx](https://npmjs.com/package/mdast2docx).**

<details>
<summary>Why does this exist?</summary>

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.
</details>

<details>
<summary>Which one should I use?</summary>

* **Use mdast-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 | mdast-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) |

</details>

<details>
<summary>Maintenance & Support</summary>

> **Security:** Security audits are performed on the canonical package; this alias inherits all security patches automatically.
</details>

---



```bash
$ pnpm add mdast2docx docx
```

**_or_**

```bash
$ npm install mdast2docx docx
```

**_or_**

```bash
$ yarn add mdast2docx docx
```

---

## 🚀 Quick Start

```typescript
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`](https://npmjs.com/package/@m2d/table) | Rich borders, repeating headers, cell fills, and column alignment |
| `listPlugin` | [`@m2d/list`](https://npmjs.com/package/@m2d/list) | Hierarchical decimal numbering (`1.1.1`) and multi-tier bullet glyphs |
| `imagePlugin` | [`@m2d/image`](https://npmjs.com/package/@m2d/image) | SVG and URL image resolution, rasterization, and dimensions |
| `mermaidPlugin` | [`@m2d/mermaid`](https://npmjs.com/package/@m2d/mermaid) | Client-side Mermaid diagrams with auto-healing syntax |
| `mathPlugin` | [`@m2d/math`](https://npmjs.com/package/@m2d/math) | LaTeX math translated to native editable Word MathML equations |
| `htmlPlugin` | [`@m2d/html`](https://npmjs.com/package/@m2d/html) | Embedded HTML tag parsing and inline CSS styles |
| `emojiPlugin` | [`@m2d/emoji`](https://npmjs.com/package/@m2d/emoji) | GitHub emoji shortcodes to Unicode characters |

---

## 📚 Deep Dive Guides

- 📦 **[Umbrella Architecture & Package Structure Guide](./docs/umbrella-architecture.mdx)**: Subpath exports, ecosystem structure, and choosing between umbrella vs scoped packages.
- 🚀 **[Production Best Practices & Migration Guide](./docs/migration-and-best-practices.mdx)**: AI pipelines, server vs browser deployment, table layouts, and v1.x migration.

---

## License

This library is licensed under the MIT open-source license.

<hr />

<p align="center">with 💖 by <a href="https://mayankchaudhari.com" target="_blank">Mayank Kumar Chaudhari</a></p>

---
_Source: https://npm.io/package/mdast-to-docx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
