# @mdast2docx/remark-docx

> A unified plugin to prepare MDAST trees for DOCX conversion using mdast2docx.

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

## Install

```sh
npm install @mdast2docx/remark-docx
pnpm add @mdast2docx/remark-docx
yarn add @mdast2docx/remark-docx
bun add @mdast2docx/remark-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.4.0 |
| Published | 2026-10-22 |
| First published | 2025-03-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 15 |
| Author | Mayank Kumar Chaudhari |
| Maintainers | mayank1513 |
| Keywords | remark-docx, remark-plugin, markdown-to-docx, mdast-to-docx, docx-formatting, text-processing, mdast-extensions, unist-custom-nodes, nodes, images, hyperlinks, footnotes, converter, plugin, markdown, mdast, unist, remark, unified, docx, ms-word, document-generator, document-generation, typescript, open-source, customizable, seamless-integration, modern, web-development, frontend, automation, google-sheets, generative-ai, rich-text, cutting-edge, compatibility, progressive, md2docx, mdast2docx, m2d, mayank1513 |

## Links

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

## Dependencies (1)

- [@m2d/remark-docx](https://npm.io/package/@m2d/remark-docx.md) 1.4.0

## 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.4.0 (latest) — 2026-10-22
- 1.2.2 — 2025-11-15
- 1.2.1 — 2025-11-15
- 1.2.0 — 2025-11-15
- 1.1.0 — 2025-10-31
- 1.0.0 — 2025-09-06
- 0.1.0 — 2025-04-08
- 0.0.5 — 2025-03-28
- 0.0.4 — 2025-03-26

## README

# @m2d/remark-docx <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/@m2d/remark-docx" rel="noopener noreferrer">
    <img alt="codecov" src="https://codecov.io/gh/md2docx/md2docx/graph/badge.svg?flag=@m2d/remark-docx" />
  </a> 
  <a href="https://npmjs.com/package/@m2d/remark-docx" rel="noopener noreferrer">
    <img alt="npm version" src="https://img.shields.io/npm/v/@m2d/remark-docx" />
  </a>
  <a href="https://npmjs.com/package/@m2d/remark-docx" rel="noopener noreferrer">
    <img alt="npm downloads" src="https://img.shields.io/npm/d18m/@m2d/remark-docx" />
  </a>
  <a href="https://npmjs.com/package/@m2d/remark-docx" rel="noopener noreferrer">
    <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/@m2d/remark-docx" />
  </a>
  <img alt="license" src="https://img.shields.io/npm/l/@m2d/remark-docx" />
</p>

> @m2d/remark-docx: Unified & Remark compiler plugin that transforms Markdown directly into Microsoft Word (`.docx`) documents.

---

## ✨ Features

- 🔌 **Unified & Remark Compiler**: Plugs directly into `unified().use(remarkDocx)` to compile MDAST syntax trees into Word OpenXML.
- 📦 **Auto-Injected Plugins**: Automatically configures tables, math, lists, images, emojis, and HTML plugins when none are specified.
- 🌐 **Isomorphic Execution**: Runs in both browser (generating client-side `Blob`s) and Node.js (generating `Buffer`s for file writing).
- ⚙️ **Configurable Outputs**: Supports `"blob"`, `"buffer"`, `"base64"`, and `"uint8array"` formats.
- ⚡ **Dual Execution APIs**: Compatible with both async `.process()` and synchronous `.processSync()` pipelines.

---

## 📦 Installation


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

<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, **@m2d/remark-docx** is the primary source of truth.
</details>

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

* **Use @mdast2docx/remark-docx** if you prefer the shorter name or specific branding or ESM Only.
* **Use @m2d/remark-docx** for the most stable long-term reference and standard alignment.

| Feature | @m2d/remark-docx | @mdast2docx/remark-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 @m2d/remark-docx docx unified remark-parse remark-gfm
```

**_or_**

```bash
$ npm install @m2d/remark-docx docx unified remark-parse remark-gfm
```

**_or_**

```bash
$ yarn add @m2d/remark-docx docx unified remark-parse remark-gfm
```

---

## 🚀 Quick Start

### Browser (Download as DOCX)

```typescript
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkGfm from "remark-gfm";
import { remarkDocx } from "@m2d/remark-docx";

const processor = unified()
  .use(remarkParse)
  .use(remarkGfm)
  .use(remarkDocx, "blob");

const file = await processor.process("# Hello World\n\nExported directly to Word!");
const blob = (await file.result) as Blob;

// Trigger browser download
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = "document.docx";
link.click();
URL.revokeObjectURL(url);
```

### Node.js (with Native Images & Mermaid Support)

For Node.js environments, use [`@m2d/remark-docx-node`](../remark-docx-node) to automatically wire native server-side image resolution (`@m2d/image-node`) and diagram rendering (`@m2d/mermaid-node`):

```typescript
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 file = await processor.process("# Server Report\n\nWritten via Node.js with native image and Mermaid rasterization.");
const buffer = (await file.result) as Buffer;

await fs.writeFile("report.docx", buffer);
```

---

## ⚙️ Plugin Signature

```typescript
import { OutputType } from "docx";
import { IDocxProps, ISectionProps } from "mdast2docx";

remarkDocx(
  outputType?: "blob" | "buffer" | "base64" | "uint8array", // Default: "blob"
  docxProps?: IDocxProps,                                  // Global Word document options
  sectionProps?: ISectionProps,                            // Section margins, headers, and plugins
  pluginProps?: {                                          // Options passed to auto-injected plugins
    table?: TablePluginOptions;
    list?: ListPluginOptions;
    mermaid?: MermaidPluginOptions;
    image?: ImagePluginOptions;
    emoji?: EmojiPluginOptions;
  }
);
```

---

## 📚 Deep Dive Guides

- 🔌 **[Unified Pipeline Integration Guide](./docs/unified-pipeline-integration.mdx)**: Architecture, plugin auto-injection, and manual plugin overrides.
- 💾 **[Output Formats & Environments Guide](./docs/output-formats-and-environments.mdx)**: Browser downloads, server writing, sync execution, and binary output types.

---

## 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/@mdast2docx/remark-docx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
