npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@m2d/md2docx

v0.0.1

Published

The simplest way to convert Markdown to DOCX. Batteries-included wrapper around all @m2d/remark-docx package and Unified. One import, one call — full Markdown → Word conversion with HTML, images, math, tables, and more.

Readme

@m2d/md2docx

test codecov Version Downloads npm bundle size

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

✅ 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?: {
    mermaid?: MermaidOptions;
    list?: ListOptions;
    table?: TableOptions;
    emoji?: EmojiOptions;
    image?: ImageOptions;
  }
): Promise<OutputTypeResult>;

| Param | Description | | --------------------- | ------------------------------------------------------------------- | | md | Markdown string input. | | docxProps | Passed directly to @m2d/core → document metadata, styles, etc. | | defaultSectionProps | Defaults for sections — page size, margins, plugins. | | outputType | "blob" (browser default) — or "buffer", "base64", "stream". | | pluginProps | Optional config passed to specific @m2d/* plugins. |


🧠 What’s Included (Under the Hood)

| Feature | Plugin | | ------------------------- | -------------------------------------------------- | | Markdown parsing | remark-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 |

👉 On Node/server-side, HTML & image plugins are skipped automatically to avoid DOM/canvas issues.


🛠 Example – Custom Options

import { md2docx } from "@m2d/md2docx";

await md2docx(
  markdown,
  { title: "My Doc", author: "Mayank" }, // docxProps
  undefined, // keep default section props
  "buffer", // outputType
  {
    image: { maxWidth: 500 },
    mermaid: { theme: "dark" },
  }
);

⚠️ Notes & Best Practices

  • When using HTML (<div>, <span>, etc.), sanitize input if it's user-generated.
  • For full control or custom Node pipelines, use lower-level packages like @m2d/core.
  • Mermaid & image rendering may require browser/polyfill contexts.

📚 Related Packages

| Package | Purpose | | --------------------- | --------------------------------------------- | | @m2d/core | Converts MDAST → DOCX using docx. | | @m2d/html | Parses HTML nodes inside Markdown. | | @m2d/image | Handles images, caching, base64, URLs. | | @m2d/math | LaTeX equations → DOCX. | | @m2d/table | GitHub-style Markdown tables. | | @m2d/react-markdown | Lightweight Markdown → React (exports MDAST). |


🤝 Contributing

Pull requests and issue reports welcome! If your team uses this in production, please consider starring the repo or posting feedback.


📜 License

MPL-2.0 © Mayank Chaudhari and contributors