1.1.2 โ€ข Published 5 months ago

@mdast2docx/html v1.1.2

Weekly downloads
-
License
MPL-2.0
Repository
github
Last release
5 months ago

@m2d/html

Version Downloads Bundle Size

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


๐Ÿ“ฆ Installation

npm install @m2d/html
pnpm add @m2d/html
yarn add @m2d/html

๐Ÿš€ Overview

The @m2d/html plugin for 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

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 ElementMDAST NodeNotes
<img>imageSupports styles and attributes
<br>breakLine breaks
<strong>, <b>strongBold text
<em>, <i>emphasisItalics
<del>, <s>deleteStrike-through
<a>linkHyperlinks
<table>table, rowBasic tables supported
<input type="checkbox">checkboxReadonly checkboxes
<hr>thematicBreakHorizontal line
<blockquote>blockquoteBlockquotes
Othersparagraph, 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 <style> 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

PluginPurpose
@m2d/coreConverts extended MDAST to DOCX
@m2d/imageRenders image nodes to DOCX
@m2d/tableRenders table nodes to DOCX
@m2d/listEnhanced list support (tasks, bullets)

โญ Support Us

If you find this useful:


๐Ÿงพ License

MIT ยฉ Mayank Chaudhari