Skip to content

About

The modular document compiler ecosystem to transform Markdown and ASTs into high-fidelity DOCX documents.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

207 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Md2Docx

Md2Docx Banner

CI codecov npm version npm downloads npm bundle size license

Md2Docx: A powerful, pluggable, and extensible Markdown to Microsoft Word (.docx) document engine for Node.js and browsers, backed by a rich suite of official plugins.


✨ Why Md2Docx?

Modern applications, technical platforms, and Generative AI tools produce structured output in Markdown. Md2Docx transforms Markdown Abstract Syntax Trees (MDAST) into professionally formatted Word documents with native tables, vector diagrams, editable equations, and custom section layouts.

  • πŸ“ Authentic Word Elements: Converts Markdown directly into native Microsoft Word OpenXML elements (docx.Table, docx.Math, docx.ImageRun, outline numbering).
  • 🧩 Pluggable Core & Rich Plugin Suite: Fully extensible Unified/MDAST architecture. Use the all-in-one package, cherry-pick official @m2d/* plugins, or author custom plugins for bespoke syntax.
  • 🌐 Isomorphic Runtimes: Zero-server client-side generation (Blob) in browsers, or high-throughput batch generation (Buffer) in Node.js.
  • πŸ›‘οΈ Resilient by Default: Graceful fallbacks for failed diagrams, self-healing syntax auto-repair, and protection against runaway markdown syntax.

πŸ“¦ Monorepo Packages

Package Version Description
@m2d/md2docx npm All-in-one batteries-included Markdown to DOCX converter for browser & client applications.
mdast2docx npm Umbrella bundle containing @m2d/core and all official plugins.
@m2d/core npm Core conversion engine, plugin pipeline, and caching layer.
@m2d/cli npm Universal CLI binary for converting Markdown to DOCX on Node.js.
@m2d/table npm Rich tables with borders, cell fills, alignments, and repeating headers.
@m2d/list npm Multi-level outline numbering (1.1.1) and nested bullet glyphs.
@m2d/math npm LaTeX math formulas rendered as native editable Word MathML equations.
@m2d/mermaid npm Browser Mermaid diagrams with auto-healing syntax repair.
@m2d/mermaid-node npm Server-side Mermaid rendering with zero browser/DOM dependencies.
@m2d/image npm Browser image and SVG rasterization with persistent caching.
@m2d/image-node npm Server-side image and SVG rasterizer powered by sharp.
@m2d/html npm Embedded HTML tag parsing and inline CSS styling to MDAST (browser DOM).
@m2d/html-node npm Server-side DOM-less HTML parsing powered by linkedom.
@m2d/remark-docx npm Official Unified / Remark compiler plugin for direct DOCX output.
@m2d/remark-docx-node npm Server-side Remark compiler plugin with native image & diagram support.
@m2d/react-markdown npm SSR-friendly React renderer with AST retention for instant DOCX export.
@m2d/cache npm High-performance in-memory and persistent caching layer.
@m2d/mdast npm Extended MDAST and HAST TypeScript type definitions.

πŸš€ Quick Start

$ pnpm add mdast2docx docx unified remark-parse remark-gfm remark-math
import { toDocx } from "mdast2docx";
import {
  htmlPlugin,
  imagePlugin,
  listPlugin,
  mathPlugin,
  mermaidPlugin,
  tablePlugin,
} from "mdast2docx/plugins";
import remarkGfm from "remark-gfm";
import remarkMath from "remark-math";
import remarkParse from "remark-parse";
import { unified } from "unified";

const markdown = `
# Project Report

Executive summary with **bold** text and [links](https://github.com/md2docx/md2docx).

## System Flow

\`\`\`mermaid
graph LR
  Client --> Gateway --> Database
\`\`\`

Formula: $E = mc^2$
`;

// 1. Parse markdown
const mdast = unified()
  .use(remarkParse)
  .use(remarkGfm)
  .use(remarkMath)
  .parse(markdown);

// 2. Generate Word DOCX Blob
const docxBlob = await toDocx(
  mdast,
  {},
  {
    plugins: [
      htmlPlugin(),
      mermaidPlugin(),
      imagePlugin(),
      tablePlugin(),
      listPlugin(),
      mathPlugin(),
    ],
  },
);

πŸ“– Documentation

Visit the official documentation site: https://md2docx.js.org


License

This library is licensed under the MIT open-source license.


with πŸ’– by Mayank Kumar Chaudhari

About

The modular document compiler ecosystem to transform Markdown and ASTs into high-fidelity DOCX documents.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages