SELECT 1
Entry 026Thu 2026.11.05
One launch a day. Picked, run, explained.

Thu 2026.11.05

Md2docx: Markdown to Word, diagrams included

Today's pick: Md2docx

Md2docx is a product that converts Markdown into Word documents (.docx). Tables and math become native Word tables and equations. Mermaid diagrams written as text become images.

It is today’s pick because it can turn AI answers written in Markdown into Word files. It also turns 6 kinds of diagrams into images.

exit 0Ran itIt works. The sample file’s 5 tables became Word tables, and 6 diagrams became images.
Found on
Show HN
Built with
TypeScript, unified, docx, sharp, beautiful-mermaid

The problem

According to the README, generative AI tools produce their output in Markdown. When that output becomes a Word document, its tables, math and diagrams should become Word tables, equations and images.

According to the PandocAn open-source command-line program that converts documents between many formats, such as Markdown, HTML and Word. User’s Guide, Pandoc renders LaTeXA language for writing documents with math, such as papers. In Markdown, math is written in LaTeX syntax between dollar signs. math as Word’s equation format in docx output. The same guide says nothing about MermaidA text syntax and tool for diagrams such as flowcharts and sequence diagrams. Markdown viewers that support Mermaid render a diagram in a code block as an image. diagrams. Pandoc leaves diagram code as a code block. Turning it into an image takes a separate filter program.

How it solves it

Md2docx was posted on Hacker News as a Show HN on November 4, 2026. It is a JavaScript library and CLI by Mayank Kumar Chaudhari.

Md2docx parses Markdown into an ASTAbstract syntax tree. A tree that shows the structure of source code or text such as Markdown. Compilers and analysis tools build it to read code. and turns each node into a Word element. Tables become Word tables, and LaTeX math becomes Word equations. Mermaid code blocks become images. Each kind of node has its own plugin.

In Node.js, Mermaid diagrams are drawn without a browser. The beautiful-mermaid library makes an SVG, and the image library sharp turns it into a PNG for the document. If a diagram cannot be drawn, its source is kept as a code block.

What is different

The first difference is how diagrams are handled. Md2docx turns Mermaid code into images in Node.js, without a filter. It lays out the diagram in TypeScript code and does not start a browser. According to the README, the tradeoff is that it draws only 6 types in Node.js: flowchart, sequence, class, state, ER and XY chart. The maker says to convert in a browser if you need every type.

The second difference is how the converter runs. Pandoc is a command-line program written in Haskell. To use Pandoc, a JavaScript app has to install it and run it as a separate program. Md2docx is an npm package, so the app calls it as a function. The mdast2docx package bundles the core engine and all official plugins. With it, the app parses the Markdown into an AST itself and passes the AST to the package with a list of plugins. You can write your own plugin for new syntax and add it to that list. The maker says Md2docx can also make .docx files in a browser. The tradeoff is that Pandoc supports many input and output formats. On today’s sample.md, Pandoc also converted more equations. Md2docx reads LaTeX with its own parser.

How it was built

  • All 207 commits were made between October 5 and 26, 2026. The maker authored 199 commits, and a GitHub Actions bot authored 8. No commit has a Co-authored-by trailer.
  • The repository has an AGENTS.md file with instructions for AI coding tools.

Running it

I installed @m2d/cli 1.0.1 with npm on Node.js 22 and converted the repository’s sample file, sample.md (652 lines). I also converted the same file with Pandoc 3.1.3 to compare.

  1. Install. The installed dependencies took 103 MB.
  2. Conversion. sample.md became a 108 KB .docx file in 3.6 seconds. The log showed 5 diagram errors, and the last line was Successfully generated.
  3. Checking the document. I opened the document with python-docx. It had 64 headings, 5 tables and 10 images. 6 of the images were Mermaid diagrams. The 5 diagrams that could not be drawn stayed as code blocks.
  4. Math. 5 of the 7 equations in the sample became Word equations. The matrix (pmatrix) equation and the multi-line (aligned) equation came out empty. The math plugin’s docs say pmatrix and aligned are not supported. The conversion log showed no warning.
  5. Nested superscripts and subscripts. In e^{-x^2}, the ^2 inside the exponent did not become a superscript. It stayed as the text x^2. I also made a separate four-line file with a^{b^2} and x_{i_j} and converted it. b^2 and i_j stayed as text in the same way. Pandoc converted all 7 equations in sample.md and rendered the ^2 in e^{-x^2} as a superscript.
  6. A large file. I built a 15,001-line file from 1,000 sections, each with a heading, paragraphs, a list, a table and inline math. Md2docx took 5.2 to 5.9 seconds (2 runs), and Pandoc took 3.0 to 3.5 seconds (3 runs). The Md2docx output had all 1,000 tables.
[m2d/mermaid-node] Failed to render diagram: Error: Invalid mermaid header: "gantt". Expected "graph TD", "flowchart LR", "stateDiagram-v2", etc.
[m2d/image-node] Error resolving image:  Error: Empty SVG string encountered
[2026-11-04T20:49:03.269Z] [md2docx:INFO] Successfully generated /tmp/run/app/sample.docx

Not checked

  • Converting in a browser. Convert sample.md in a browser with @m2d/md2docx and check that all 11 diagrams are drawn.
  • Editing in Word. Open the output in Microsoft Word and check that the tables and equations can be edited.

Verdict

It works. The sample file’s 5 tables became Word tables, and 6 diagrams became images. But the math plugin @m2d/math 0.1.2 leaves nested superscripts and subscripts inside braces as text and produces empty matrix and multi-line equations without a warning. The maker says the superscript and subscript problem was fixed in @m2d/math 0.1.3 on November 9. It is worth trying if you need to send Markdown documents with diagrams as Word files.

What to take away

  • Do not trust a converter's success message alone. Compare the number of tables, equations and images in the source Markdown with the output Word file. Md2docx printed Successfully generated even though the matrix and multi-line equations came out empty.
  • If you build a converter, make unconverted input visible in the output file. Md2docx kept the diagrams it could not turn into images as code blocks, so the Word file shows which diagrams were not converted. The matrix and multi-line equations became empty equations with no warning. You only notice they are missing if you open the document and check each equation.

Getting started

  1. npm install @m2d/cli
  2. npx m2d report.md -o report.docx
You need
Node.js. No account or key is needed.
Cost
Free under the MIT license.

According to the README, Md2docx renders only 6 kinds of Mermaid diagrams as images in Node.js. Other kinds, such as Gantt and pie charts, stay as code blocks.

Steps select 1 ran.

Progress

  1. Day 3Some commits
  2. Day 7Active
  3. Day 15Quiet
  4. Day 30Upcoming
  5. Day 90Upcoming
  6. Day 180Upcoming
  7. Day 365Upcoming

Latest check Day 15, Thu 2026.11.19

Commits since launch
0 → 41
Stars
41 → 43
Latest release
mdast2docx@1.8.0
Last commit
2026.11.10

No commits in this period.

Full history →