📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

@mdast2docx/html

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mdast2docx/html

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

1.0.0
latest
Source
npm
Version published
Weekly downloads
7
-70.83%
Maintainers
1
Weekly downloads
 
Created
Source

@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

  • Parses raw embedded HTML using the DOM.
  • Converts DOM nodes to extended MDAST nodes.
  • 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.

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

Made with 💖 by Mayank Kumar Chaudhari

Keywords

html

FAQs

Package last updated on 07 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts