Version 0.1.0
Overview
Updated 22 Oct 2026
Server-side HTML to MDAST plugin for md2docx using linkedom. Converts embedded HTML in Markdown into structured DOCX-compatible MDAST nodes on Node.js.
✨ Why @m2d/html-node?
- ⚡ Lightweight Server DOM: Uses
linkedom(~150KB) for fast, low-memory DOM parsing on Node.js without heavyweight JSDOM dependencies. - 🎨 Rich HTML & Inline CSS: Supports
<div style="...">,<span style="...">,<p>,<strong>,<em>,<h1>-<h6>,<br>,<img>,<table>, and inline styles (colors, borders, alignments, text transforms). - 🧩 Pluggable & Universal: Seamlessly integrates into
unified,remark,mdast2docx, and@m2d/remark-docx-node.
📦 Installation
pnpm add @m2d/html-nodeor
npm install @m2d/html-nodeor
yarn add @m2d/html-node🚀 Usage
import { nodeHtmlPlugin } from "@m2d/html-node";
import { toDocx } from "mdast2docx";
import remarkParse from "remark-parse";
import { unified } from "unified";
const markdown = `
<div style="border: 2px solid #0052cc; color: #172b4d;">
<p>Rendered with <strong>native server-side HTML parsing</strong>!</p>
</div>
`;
const mdast = unified().use(remarkParse).parse(markdown);
const docxBuffer = await toDocx(mdast, {}, { plugins: [nodeHtmlPlugin()] }, "nodebuffer");License
This library is licensed under the MIT open-source license.
with 💖 by Mayank Kumar Chaudhari