# @m2d/image

> MDAST to DOCX plugin for resolving and embedding images. Supports base64, URLs, and custom resolvers for seamless DOCX image integration.

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

## Install

```sh
npm install @m2d/image
pnpm add @m2d/image
yarn add @m2d/image
bun add @m2d/image
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2026-10-22 |
| First published | 2025-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 48.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Mayank Kumar Chaudhari <https://mayankchaudhari.com> |
| Maintainers | mayank1513 |
| Keywords | images, image-plugin, image-resolver, image-embedding, base64, remote-image, docx-image, mdast, markdown, markdown-to-docx, mdast-to-docx, md2docx, mdast2docx, plugin, converter, remark, unified, docx, ms-word, document-generator, document-generation, text-processing, typescript, open-source, customizable, modern, seamless-integration, cutting-edge, compatibility, progressive, web-development, frontend, automation, export, google-sheets, generative-ai, rich-text, hyperlinks, footnotes, m2d, mayank1513 |

## Links

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

## Dependencies (4)

- [@m2d/core](https://npm.io/package/@m2d/core.md) 1.8.1
- [@m2d/cache](https://npm.io/package/@m2d/cache.md) 0.1.0
- [@svg-fns/io](https://npm.io/package/@svg-fns/io.md) ^1.0.1
- [@svg-fns/svg2img](https://npm.io/package/@svg-fns/svg2img.md) ^0.2.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.6.0 (latest) — 2026-10-22
- 1.5.1 — 2026-10-21
- 1.5.0 — 2026-10-20
- 1.4.1 — 2025-09-26
- 1.4.0 — 2025-09-26
- 1.3.2 — 2025-09-24
- 1.3.1 — 2025-06-12
- 1.3.0 — 2025-06-12
- 1.2.1 — 2025-06-06
- 1.2.0 — 2025-06-02
- 1.1.3 — 2025-06-02
- 1.1.2 — 2025-06-01
- 1.1.1 — 2025-05-30
- 1.1.0 — 2025-05-26
- 1.0.1 — 2025-05-20
- … 13 more at https://npm.io/package/@m2d/image/versions

## README

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

<p align="center">
  <img src="./apps/web/public/banner.svg" alt="Md2Docx Banner" width="100%" />
</p>

<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>

> **Md2Docx**: A powerful, modular, and extensible Markdown to Microsoft Word (`.docx`) document engine for Node.js and browsers.

---

## ✨ Why Md2Docx?

Modern applications, technical platforms, and **Generative AI** tools produce structured output in **Markdown**. `Md2Docx` transforms Markdown Abstract Syntax Trees (MDAST) into professionally formatted Word documents with native tables, vector diagrams, editable equations, and custom section layouts.

- 📐 **Authentic Word Elements**: Converts Markdown directly into native Microsoft Word OpenXML elements (`docx.Table`, `docx.Math`, `docx.ImageRun`, outline numbering).
- 🧩 **Modular Plugin Ecosystem**: Use the all-in-one `mdast2docx` umbrella or cherry-pick lightweight `@m2d/*` plugins.
- 🌐 **Isomorphic Runtimes**: Zero-server client-side generation (`Blob`) in browsers, or high-throughput batch generation (`Buffer`) in Node.js.
- 🛡️ **Resilient by Default**: Graceful fallbacks for failed diagrams, self-healing syntax auto-repair, and protection against runaway markdown syntax.

---

## 📦 Monorepo Packages

| Package | Version | Description |
| :--- | :--- | :--- |
| [`@m2d/md2docx`](./packages/md2docx) | [![npm](https://img.shields.io/npm/v/@m2d/md2docx)](https://npmjs.com/package/@m2d/md2docx) | **All-in-one** batteries-included Markdown to DOCX converter for browser & client applications. |
| [`mdast2docx`](./packages/mdast2docx) | [![npm](https://img.shields.io/npm/v/mdast2docx)](https://npmjs.com/package/mdast2docx) | **Umbrella bundle** containing `@m2d/core` and all official plugins. |
| [`@m2d/core`](./packages/core) | [![npm](https://img.shields.io/npm/v/@m2d/core)](https://npmjs.com/package/@m2d/core) | Core conversion engine, plugin pipeline, and caching layer. |
| [`@m2d/cli`](./packages/cli) | [![npm](https://img.shields.io/npm/v/@m2d/cli)](https://npmjs.com/package/@m2d/cli) | Universal CLI binary for converting Markdown to DOCX on Node.js. |
| [`@m2d/table`](./packages/table) | [![npm](https://img.shields.io/npm/v/@m2d/table)](https://npmjs.com/package/@m2d/table) | Rich tables with borders, cell fills, alignments, and repeating headers. |
| [`@m2d/list`](./packages/list) | [![npm](https://img.shields.io/npm/v/@m2d/list)](https://npmjs.com/package/@m2d/list) | Multi-level outline numbering (`1.1.1`) and nested bullet glyphs. |
| [`@m2d/math`](./packages/math) | [![npm](https://img.shields.io/npm/v/@m2d/math)](https://npmjs.com/package/@m2d/math) | LaTeX math formulas rendered as native editable Word MathML equations. |
| [`@m2d/mermaid`](./packages/mermaid) | [![npm](https://img.shields.io/npm/v/@m2d/mermaid)](https://npmjs.com/package/@m2d/mermaid) | Browser Mermaid diagrams with auto-healing syntax repair. |
| [`@m2d/mermaid-node`](./packages/mermaid-node) | [![npm](https://img.shields.io/npm/v/@m2d/mermaid-node)](https://npmjs.com/package/@m2d/mermaid-node) | Server-side Mermaid rendering with zero browser/DOM dependencies. |
| [`@m2d/image`](./packages/image) | [![npm](https://img.shields.io/npm/v/@m2d/image)](https://npmjs.com/package/@m2d/image) | Browser image and SVG rasterization with persistent caching. |
| [`@m2d/image-node`](./packages/image-node) | [![npm](https://img.shields.io/npm/v/@m2d/image-node)](https://npmjs.com/package/@m2d/image-node) | Server-side image and SVG rasterizer powered by `sharp`. |
| [`@m2d/html`](./packages/html) | [![npm](https://img.shields.io/npm/v/@m2d/html)](https://npmjs.com/package/@m2d/html) | Embedded HTML tag parsing and inline CSS styling to MDAST (browser DOM). |
| [`@m2d/html-node`](./packages/html-node) | [![npm](https://img.shields.io/npm/v/@m2d/html-node)](https://npmjs.com/package/@m2d/html-node) | Server-side DOM-less HTML parsing powered by `linkedom`. |
| [`@m2d/remark-docx`](./packages/remark-docx) | [![npm](https://img.shields.io/npm/v/@m2d/remark-docx)](https://npmjs.com/package/@m2d/remark-docx) | Official Unified / Remark compiler plugin for direct DOCX output. |
| [`@m2d/remark-docx-node`](./packages/remark-docx-node) | [![npm](https://img.shields.io/npm/v/@m2d/remark-docx-node)](https://npmjs.com/package/@m2d/remark-docx-node) | Server-side Remark compiler plugin with native image & diagram support. |
| [`@m2d/react-markdown`](./packages/react-markdown) | [![npm](https://img.shields.io/npm/v/@m2d/react-markdown)](https://npmjs.com/package/@m2d/react-markdown) | SSR-friendly React renderer with AST retention for instant DOCX export. |
| [`@m2d/cache`](./packages/cache) | [![npm](https://img.shields.io/npm/v/@m2d/cache)](https://npmjs.com/package/@m2d/cache) | High-performance in-memory and persistent caching layer. |
| [`@m2d/mdast`](./packages/mdast) | [![npm](https://img.shields.io/npm/v/@m2d/mdast)](https://npmjs.com/package/@m2d/mdast) | Extended MDAST and HAST TypeScript type definitions. |

---

## 🚀 Quick Start

```bash
$ pnpm add mdast2docx docx unified remark-parse remark-gfm remark-math
```

```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 = `
# Project Report

Executive summary with **bold** text and [links](https://github.com/md2docx/md2docx).

## System Flow

\`\`\`mermaid
graph LR
  Client --> Gateway --> Database
\`\`\`

Formula: $E = mc^2$
`;

// 1. Parse markdown
const mdast = unified()
  .use(remarkParse)
  .use(remarkGfm)
  .use(remarkMath)
  .parse(markdown);

// 2. Generate Word DOCX Blob
const docxBlob = await toDocx(mdast, {}, {
  plugins: [
    htmlPlugin(),
    mermaidPlugin(),
    imagePlugin(),
    tablePlugin(),
    listPlugin(),
    mathPlugin(),
  ],
});
```

---

## 📖 Documentation

Visit the official documentation site: [https://md2docx.js.org](https://md2docx.js.org)

---

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