# @mdast2docx/html

> Extend MDAST by parsing embedded HTML in Markdown. Converts HTML into structured MDAST nodes compatible with @m2d/core for DOCX generation.

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

## Install

```sh
npm install @mdast2docx/html
pnpm add @mdast2docx/html
yarn add @mdast2docx/html
bun add @mdast2docx/html
```

## 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.2.0 |
| Published | 2026-10-22 |
| First published | 2025-03-25 |
| 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 | 1 |
| Author | Mayank Kumar Chaudhari |
| Maintainers | mayank1513 |
| Keywords | html, html-in-markdown, html-to-mdast, extended-mdast, mdast, plugin, markdown, markdown-to-docx, mdast-to-docx, md2docx, mdast2docx, converter, remark, unified, docx, ms-word, document-generator, document-generation, parser, text-processing, rich-text, export, images, hyperlinks, footnotes, typescript, open-source, customizable, modern, seamless-integration, cutting-edge, compatibility, progressive, web-development, frontend, automation, google-sheets, generative-ai, m2d, mayank1513 |

## Links

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

## Dependencies (1)

- [@m2d/html](https://npm.io/package/@m2d/html.md) 1.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.2.0 (latest) — 2026-10-22
- 1.1.11 — 2025-10-31
- 1.1.10 — 2025-08-05
- 1.1.9 — 2025-07-31
- 1.1.8 — 2025-06-25
- 1.1.7 — 2025-06-17
- 1.1.6 — 2025-06-17
- 1.1.5 — 2025-06-17
- 1.1.4 — 2025-06-17
- 1.1.3 — 2025-06-16
- 1.1.2 — 2025-06-06
- 1.1.1 — 2025-06-06
- 1.1.0 — 2025-06-06
- 1.0.3 — 2025-05-29
- 1.0.1 — 2025-05-16
- … 3 more at https://npm.io/package/@mdast2docx/html/versions

## README

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

> @m2d/html: HTML to Extended MDAST preprocessing plugin for `@m2d/core`. Transforms raw embedded HTML strings into structured MDAST nodes for rich Word DOCX conversion.

---

## ✨ Features

- 🌐 **Embedded HTML Parsing**: Converts raw HTML tags inside Markdown into structured MDAST nodes, enabling HTML-to-Word generation.
- 🎨 **Inline CSS Resolution**: Extracts and translates inline CSS (`color`, `background-color`, `text-align`, `font-weight`, `font-size`, `borders`) into native Word OpenXML styling.
- 🧩 **Deep Ecosystem Integration**: Upgrades raw `<img>`, `<table>`, and list tags so that downstream plugins (`@m2d/image`, `@m2d/table`, `@m2d/list`) can process them seamlessly.
- ☑️ **Interactive Elements**: Translates `<input type="checkbox">` elements into clean Unicode checkbox representations (`☑` / `☐`).
- ⚡ **Lightweight DOM Parsing**: Fast, robust stack-based parsing that pairs closing tags across sibling Markdown nodes without mangling surrounding content.

---

## 📦 Installation


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

<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/html** is the primary source of truth.
</details>

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

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

| Feature | @m2d/html | @mdast2docx/html |
| --- | --- | --- |
| **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/html @m2d/core docx
```

**_or_**

```bash
$ npm install @m2d/html @m2d/core docx
```

**_or_**

```bash
$ yarn add @m2d/html @m2d/core docx
```

---

## 🚀 Quick Start

```typescript
import { toDocx } from "@m2d/core";
import { htmlPlugin } from "@m2d/html";
import { imagePlugin } from "@m2d/image";
import { tablePlugin } from "@m2d/table";
import remarkParse from "remark-parse";
import { unified } from "unified";

const markdown = `
# Project Report

<span style="color: #2563EB; font-weight: bold;">Important Alert:</span>
The schedule has moved forward by 2 weeks.

<table>
  <tr>
    <th style="background-color: #1E293B; color: #FFFFFF;">Milestone</th>
    <th style="background-color: #1E293B; color: #FFFFFF;">Target</th>
  </tr>
  <tr>
    <td>Alpha Release</td>
    <td>November 1st</td>
  </tr>
</table>
`;

const mdast = unified().use(remarkParse).parse(markdown);

const docxBlob = await toDocx(mdast, {}, {
  plugins: [
    htmlPlugin(),  // 1. MUST BE REGISTERED FIRST: Converts raw HTML to MDAST nodes
    tablePlugin(), // 2. Formats table nodes generated by htmlPlugin
    imagePlugin(), // 3. Rasterizes image nodes generated by htmlPlugin
  ],
});
```

> ⚠️ **Important Pipeline Order**: Always register `htmlPlugin()` **at the beginning** of your plugins array. It executes during the `preprocess` phase to generate the MDAST nodes that subsequent plugins rely upon.

### Standalone Utilities (`@m2d/html/utils`)

```typescript
import { standardizeColor, type DocumentLike } from "@m2d/html/utils";

// Normalizes CSS colors ('#ff0000', 'red', 'rgb(...)') into DOCX 6-digit hex ('ff0000')
const hexColor = standardizeColor("red"); // "ff0000"
```

---

## 📚 Deep Dive Guides

- 🔄 **[AST Transformation & Pipeline Order Guide](./docs/ast-transformation-and-pipeline-order.mdx)**: Tag-matching stack architecture and execution sequence in `@m2d/core`.
- 🎨 **[Supported Elements & Inline CSS Guide](./docs/supported-elements-and-inline-css.mdx)**: Supported HTML elements, inline style mappings, and known limitations.

---

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