An open API service indexing awesome lists of open source software.

https://github.com/md2docx/html

Parses embedded **HTML** into extended **MDAST nodes** to unlock full HTML-to-DOCX conversion support.
https://github.com/md2docx/html

Last synced: 9 months ago
JSON representation

Parses embedded **HTML** into extended **MDAST nodes** to unlock full HTML-to-DOCX conversion support.

Awesome Lists containing this project

README

          

# `@m2d/html`

[![Version](https://img.shields.io/npm/v/@m2d/html?color=green)](https://www.npmjs.com/package/@m2d/html) ![Downloads](https://img.shields.io/npm/d18m/@m2d/html) ![Bundle Size](https://img.shields.io/bundlephobia/minzip/@m2d/html)

> Parses embedded **HTML** into extended **MDAST nodes** to unlock full HTML-to-DOCX conversion support.

---

## ๐Ÿ“ฆ Installation

```bash
npm install @m2d/html
```

```bash
pnpm add @m2d/html
```

```bash
yarn add @m2d/html
```

---

## ๐Ÿš€ Overview

The `@m2d/html` plugin for [`mdast2docx`](https://github.com/mayankchaudhari/mdast2docx) enables the parsing and transformation of **embedded raw HTML** inside Markdown into **extended MDAST**. This unlocks the ability to support features like images, tables, checkboxes, styles, and more โ€” using HTML tags directly inside your Markdown documents.

---

## โš ๏ธ Important

> **This plugin must be registered early in the plugin pipeline.**
> It transforms raw HTML into extended MDAST nodes, which are then handled by other `@m2d/*` plugins (such as `@m2d/image`, `@m2d/table`, etc).
> If used after other plugins, the HTML content, e.g, images, tables, or lists may be ignored or lost in the DOCX output.

---

## ๐Ÿ› ๏ธ Usage

```ts
import { htmlPlugin } from "@m2d/html";

const plugins = [
htmlPlugin(), // โœ… Must come first
imagePlugin(),
tablePlugin(),
];
```

---

## ๐Ÿงฉ How It Works

1. Parses raw embedded HTML using the DOM.
2. Converts DOM nodes to extended MDAST nodes.
3. Other `@m2d/*` plugins or the `@m2d/core` package consume these extended nodes to generate DOCX output.

> This plugin enriches the AST to enable other plugins and core engine to convert it to docx.

---

## โœ… Supported Elements

| HTML Element | MDAST Node | Notes |
| ------------------------- | ----------------- | ------------------------------------ |
| `` | `image` | Supports styles and attributes |
| `
` | `break` | Line breaks |
| ``, `` | `strong` | Bold text |
| ``, `` | `emphasis` | Italics |
| ``, `` | `delete` | Strike-through |
| `` | `link` | Hyperlinks |
| `
` | `table`, `row` | Basic tables supported |
| `` | `checkbox` | Readonly checkboxes |
| `


` | `thematicBreak` | Horizontal line |
| `
` | `blockquote` | Blockquotes |
| Others | `paragraph`, etc. | Styled or inline nodes with rich AST |

---

## ๐ŸŽจ Style Support

- `text-align`, `color`, `background-color`
- `font-weight`, `font-style`, `text-decoration`
- `text-transform`
- `border`, `border-left`, etc.
- `display: inline-block` and similar behaviors

---

## โš ๏ธ Limitations

- External `` tags or CSS files are not supported.
- Complex or deeply nested HTML may be simplified.
- Table `rowSpan` and `colSpan` are not yet supported.
- Script tags and non-visual elements are ignored.

---

## ๐Ÿงช Production Ready

While this plugin was originally experimental, it is now **stable and production-ready**.
It powers the rich HTML support in `mdast2docx`, including checkboxes, tables, and styled images.

> ๐Ÿงต **Contributions, ideas, and feedback are welcome!** Open an issue or PR anytime.

---

## ๐Ÿ”Œ Related Plugins/Packages

| Plugin | Purpose |
| ---------------------------------------------------- | -------------------------------------- |
| [`@m2d/core`](https://npmjs.com/package/@m2d/core) | Converts extended MDAST to DOCX |
| [`@m2d/image`](https://npmjs.com/package/@m2d/image) | Renders image nodes to DOCX |
| [`@m2d/table`](https://npmjs.com/package/@m2d/table) | Renders table nodes to DOCX |
| [`@m2d/list`](https://npmjs.com/package/@m2d/list) | Enhanced list support (tasks, bullets) |

---

## โญ Support Us

If you find this useful:

- โญ Star [mdast2docx](https://github.com/tiny-md/mdast2docx) on GitHub
- โค๏ธ Consider [sponsoring](https://github.com/sponsors/mayank1513)

---

## ๐Ÿงพ License

MIT ยฉ [Mayank Chaudhari](https://github.com/mayankchaudhari)

<p align="center">Made with ๐Ÿ’– by <a href="https://mayank-chaudhari.vercel.app" target="_blank">Mayank Kumar Chaudhari</a></p>