Skip to Content
Md2Docx logo Md2Docx
Version 0.2.0

Overview

Updated 23 hr ago

CIcodecovnpm versionnpm downloadsnpm bundle sizelicense

The simplest way to convert Markdown → DOCX (Word). Batteries-included wrapper around all @m2d/* plugins and Unified — just one import, one call.

✨ Features

  • ✅ Supports GFM, HTML, tables, images, emoji, math (LaTeX), Mermaid diagrams, frontmatter, and more.
  • ✅ Works in Node.js & browser environments (auto-skips unsupported plugins on server).
  • ✅ Built on top of @m2d/core → produces real .docx files using docx.

📦 Installation

# with pnpm
pnpm add @m2d/md2docx

# or npm
npm install @m2d/md2docx

# or yarn
yarn add @m2d/md2docx

🚀 Quick Start

import { md2docx } from "@m2d/md2docx";
import { writeFileSync } from "node:fs";

const markdown = `
# Hello World 👋

- Supports **Markdown**
- Tables, math ($E = mc^2$), images, and more
`;

const docxBlob = await md2docx(markdown); // default outputType = 'blob'

// In Node: save to file
writeFileSync("output.docx", Buffer.from(await docxBlob.arrayBuffer()));

📖 API

md2docx(
  md: string,
  docxProps?: IDocxProps,
  defaultSectionProps?: ISectionProps,
  outputType?: OutputType, // "blob" | "buffer" | "base64" | "stream"
  pluginProps?: Mdast2DocxPluginProps,
): Promise<OutputTypeResult>;
ParamDescription
mdMarkdown string input.
docxPropsPassed directly to @m2d/core → document metadata (title, creator), styles, and definitionsScope ("shared" or "section").
defaultSectionPropsDefaults for sections — page size, margins, plugins, orientation.
outputType"blob" (browser default) — or "buffer", "base64", "stream".
pluginPropsOptional config passed to specific @m2d/* plugins.

🧠 What’s Included Under the Hood

FeaturePlugin
Markdown parsingremark-parse, remark-gfm, remark-frontmatter
Math (inline & block)remark-math, @m2d/math
HTML inside Markdown@m2d/html (client-only)
Emoji support@m2d/emoji
Tables@m2d/table
Lists + task lists@m2d/list
Images (URL, base64, SVG)@m2d/image (client-only)
Mermaid diagrams@m2d/mermaid

License

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


with 💖 by Mayank Kumar Chaudhari

On this page