# Md2docx: 다이어그램까지 Word 문서로 변환하기
# Md2docx: Markdown to Word, diagrams included

- Site: https://select1.dev/2026-11-05 (English), https://select1.dev/ko/2026-11-05 (Korean)
- Entry: 026
- Published: 2026-11-05 (KST). Launch date: 2026-11-04
- Pick: Md2docx <https://md2docx.js.org/> (source: Show HN)
- Verified: ran
- What: Md2docx 는 마크다운을 Word 문서(.docx)로 변환하는 프로덕트다. 표와 수식은 Word 의 표와 수식이 된다. 텍스트로 작성한 Mermaid 다이어그램은 이미지로 들어간다.
- What (en): 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.
- Why: 오늘의 픽으로 선정한 이유는 AI 의 마크다운 답변을 Word 파일로 변환할 수 있기 때문이다. 다이어그램 6종도 이미지로 바뀐다.
- Why (en): 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.
- Verdict: 작동한다. 예제 파일의 표 5개가 Word 표로, 다이어그램 6개가 이미지로 변환됐다.
- Verdict (en): It works. The sample file’s 5 tables became Word tables, and 6 diagrams became images.
- Tags: markdown, docx, word, mermaid, latex, converter

## Checked against the README

- [fail] LaTeX 수식을 Word 에서 편집할 수 있는 수식으로 변환한다(LaTeX math formulas rendered as native editable Word equations) — 예제 파일 sample.md 의 수식 7개 가운데 5개가 Word 수식이 됐다. 행렬 하나와 여러 줄 수식 하나는 빈 수식이 됐다. 수식 플러그인 문서에는 행렬과 여러 줄 수식을 지원하지 않는다고 나와 있다. 제작자는 위첨자를 지원한다고 밝혔지만, `e^{-x^2}` 처럼 중괄호 안에서 중첩된 위첨자는 `x^2` 라는 일반 텍스트가 됐다
- [pass] 그리지 못한 다이어그램은 원래 코드를 Word 코드 블록으로 넣는다(Graceful Fallback, embedding the source as a formatted Word code block) — 예제 파일의 다이어그램 11개 가운데 간트 차트, 파이 차트, Git 그래프, 마인드맵, 사분면 차트 5개는 Consolas 글꼴의 코드 블록이 됐다. 변환은 끝까지 진행됐다
- [pass] Node.js 에서 Mermaid 를 그릴 때 Chromium, Puppeteer, JSDOM 이 필요 없다(without Chromium, Puppeteer, or JSDOM) — npm 으로 설치한 의존성 103 MB 에 Puppeteer, Playwright, Chromium, jsdom 이 없었다. 다이어그램 6개가 이미지로 들어갔다

## Measured

- 15,001줄 마크다운 파일을 .docx 로 변환하는 시간. 4코어 가상 머신: Md2docx 5.2~5.9초(2회), Pandoc 3.1.3 3.0~3.5초(3회) (마크다운 파일에 섹션 1,000개를 만들고, 섹션마다 제목, 문단, 목록, 표, 인라인 수식을 넣었다. 이 파일을 Md2docx 와 Pandoc 으로 각각 변환해 경과 시간을 측정했다)

## Progress (days after launch; full history https://select1.dev/2026-11-05/progress)

- day 3 (checked 2026-11-07) [some] commits since launch 1, stars 41, releases 29, contributors 2, last commit 2026-11-05
- day 7 (checked 2026-11-11) [active] commits since launch 41, stars 41, releases 56, contributors 2, last commit 2026-11-10
  - Nested superscripts and subscripts inside braces now convert to Word equations. Entry 026 reported this (@m2d/math 0.1.3).
  - Fixed a ReDoS vulnerability in the regex that finds math block markers (@m2d/math 0.1.3).
  - Code blocks get syntax highlighting. It is on by default in the CLI and remark-docx, and new plugins use lowlight or shiki (@m2d/code 0.1.0, @m2d/cli 1.1.0).
  - `frontmatterPlugin` now takes its options as the first argument. Code that passed an unused first argument must change (@m2d/frontmatter 1.0.0).
  - In documents split into sections, reference links and footnotes resolve across sections. `definitionsScope` sets this (@m2d/core 1.10.0).
- day 15 (checked 2026-11-19) [quiet] commits since launch 41, stars 43, releases 56, contributors 2, last commit 2026-11-10

## 한국어

## 무엇이 문제인가

README 에 따르면 생성형 AI 도구는 결과를 마크다운으로 출력한다. 이 결과를 Word 문서로 만들 때는 마크다운 안의 표, 수식, 다이어그램도 Word 의 표, 수식, 이미지가 돼야 한다.

Pandoc 사용자 가이드에 따르면 Pandoc 은 docx 로 변환할 때 LaTeX 수식을 Word 의 수식 형식으로 바꾼다. 같은 가이드에는 Mermaid 다이어그램에 대한 설명이 없다. Pandoc 은 다이어그램 코드를 코드 블록 그대로 남긴다. 이미지로 바꾸려면 필터 프로그램을 따로 적용해야 한다.

## 어떻게 해결했나

Md2docx 는 2026년 11월 4일 Hacker News 에 Show HN 글로 올라왔다. Mayank Kumar Chaudhari 가 만들어 JavaScript 라이브러리와 CLI 로 공개했다.

Md2docx 는 마크다운을 AST로 파싱한 뒤, 노드를 하나씩 Word 의 요소로 바꾼다. 표와 LaTeX 수식은 Word 의 표와 수식이 된다. Mermaid 코드 블록은 이미지가 된다. 노드의 종류마다 변환을 맡는 플러그인이 따로 있다.

Node.js 에서는 Mermaid 다이어그램을 브라우저 없이 그린다. beautiful-mermaid 라이브러리로 SVG 를 만들고, 이미지 라이브러리 sharp 로 이 SVG 를 PNG 로 바꿔 문서에 넣는다. 그리지 못한 다이어그램은 원래 코드를 코드 블록으로 넣는다.

## 무엇이 다른가

첫째, 다이어그램을 처리하는 방식이 다르다. Md2docx 는 필터 없이 Node.js 에서 Mermaid 코드를 이미지로 바꿔 Word 문서에 넣는다. 브라우저를 실행하지 않고 TypeScript 코드만으로 다이어그램의 배치를 계산하기 때문이다. 모든 다이어그램을 지원하지는 않는다. README 에 따르면 Node.js 에서는 순서도, 시퀀스, 클래스, 상태, ER, XY 차트의 6종만 그린다. 제작자는 모든 다이어그램을 지원하려면 브라우저에서 변환하라고 했다.

둘째, 변환기를 실행하는 방식이 다르다. Pandoc 은 Haskell 로 만든 CLI 프로그램이다. JavaScript 앱에서 Pandoc 을 사용하려면 따로 설치하고 외부 프로그램으로 실행해야 한다. Md2docx 는 npm 패키지라 앱 안에서 함수로 호출한다. mdast2docx 패키지에는 핵심 엔진과 공식 플러그인이 모두 들어 있다. 이 패키지를 사용하면 앱은 마크다운을 직접 파싱해 AST 로 만든 뒤, 플러그인 목록과 함께 이 패키지에 넘긴다. 새 문법을 변환하는 플러그인을 직접 작성해 이 목록에 추가할 수도 있다. 제작자에 따르면 Md2docx 는 브라우저에서도 .docx 파일을 만든다. 트레이드오프는 지원 범위다. Pandoc 은 여러 입력 형식과 출력 형식을 지원한다. 수식도 오늘 sample.md 에서는 Pandoc 이 더 많이 변환했다. Md2docx 는 LaTeX 를 자체 파서로 읽는다.

## 어떻게 만들었나

- 커밋 207개는 2026년 10월 5일부터 26일 사이에 작성됐다. 199개는 제작자가, 8개는 GitHub Actions 봇이 작성했다. Co-authored-by 트레일러가 있는 커밋은 없다.
- 저장소에 AI 코딩 도구용 지침 파일 AGENTS.md 가 있다.

## 실행해 보니

Node.js 22 에서 @m2d/cli 1.0.1 을 npm 으로 설치하고, 저장소의 예제 파일 sample.md(652줄)를 변환했다. 같은 파일을 Pandoc 3.1.3 으로도 변환해 비교했다.

1. 설치. 설치한 의존성은 103 MB 였다.
2. 변환. sample.md 는 3.6초 만에 108 KB 의 .docx 파일이 됐다. 로그에는 다이어그램 오류 5건이 출력됐다. 마지막 줄은 `Successfully generated` 였다.
3. 문서 확인. python-docx 로 연 문서에는 제목 64개, 표 5개, 이미지 10개가 있었다. 이미지 가운데 6개는 Mermaid 다이어그램이다. 그리지 못한 다이어그램 5개는 원래 코드가 코드 블록으로 들어갔다.
4. 수식. 예제 파일의 수식 7개 가운데 5개가 Word 수식이 됐다. 행렬(`pmatrix`) 하나와 여러 줄 수식(`aligned`) 하나는 빈 수식이 됐다. 수식 플러그인 문서에는 `pmatrix` 와 `aligned` 를 지원하지 않는다고 나와 있다. 변환 로그에는 경고가 없었다.
5. 중첩된 위첨자와 아래첨자. `e^{-x^2}` 의 지수 안에 있는 `^2` 는 위첨자가 되지 않고 `x^2` 라는 일반 텍스트가 됐다. 따로 만든 네 줄짜리 파일로 `a^{b^2}` 와 `x_{i_j}` 를 변환해도 `b^2` 와 `i_j` 가 일반 텍스트가 됐다. Pandoc 은 sample.md 의 수식 7개를 모두 변환했고, `e^{-x^2}` 의 `^2` 도 위첨자로 만들었다.
6. 큰 파일. 섹션 1,000개를 이어 붙여 15,001줄 파일을 만들었다. 섹션마다 제목, 문단, 목록, 표, 인라인 수식이 있다. 변환에 Md2docx 는 5.2~5.9초(2회), Pandoc 은 3.0~3.5초(3회)가 걸렸다. Md2docx 의 결과에는 표 1,000개가 모두 들어 있었다.

```
[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
```

## 확인하지 못한 것

- 브라우저에서 변환. @m2d/md2docx 로 브라우저에서 sample.md 를 변환해, 다이어그램 11개를 모두 그리는지 확인하자.
- Word 에서 편집. Microsoft Word 로 결과 파일을 열어 표와 수식을 편집할 수 있는지 확인하자.

## 판정

작동한다. 예제 파일의 표 5개가 Word 표로, 다이어그램 6개가 이미지로 변환됐다. 다만 수식 플러그인 @m2d/math 0.1.2 는 중괄호 안에서 중첩된 위첨자와 아래첨자를 일반 텍스트로 변환하고, 행렬과 여러 줄 수식은 경고 없이 빈 수식으로 출력한다. 제작자는 11월 9일 @m2d/math 0.1.3 에서 위첨자와 아래첨자 문제를 수정했다고 밝혔다. 다이어그램이 든 마크다운 문서를 Word 파일로 보내야 하는 경우에 써 볼 만하다.

## 얻어갈 것

- 변환기가 성공 메시지를 출력해도 결과를 그대로 믿지 말자. 원본 마크다운과 결과 Word 파일의 표, 수식, 이미지 개수를 비교하자. Md2docx 는 행렬과 여러 줄 수식이 빈 수식이 됐는데도 `Successfully generated` 를 출력했다.
- 변환기를 만든다면 변환하지 못한 입력이 결과 파일에 드러나게 하자. Md2docx 는 이미지로 바꾸지 못한 다이어그램을 코드 블록 그대로 넣었다. 그래서 Word 문서에서 어느 다이어그램이 변환되지 않았는지 바로 보인다. 반면 행렬과 여러 줄 수식은 경고 없이 빈 수식으로 넣었다. 문서를 열어 수식을 하나씩 확인하지 않으면 빠진 것을 알 수 없다.

### 용어

- Pandoc: 마크다운, HTML, Word 같은 여러 문서 형식을 서로 변환하는 오픈소스 CLI 프로그램이다.
- LaTeX: 수식이 들어간 논문 같은 문서를 작성할 때 사용하는 언어다. 마크다운에서는 달러 기호 사이에 이 문법으로 수식을 작성한다.
- Mermaid: 순서도나 시퀀스 다이어그램 같은 이미지를 텍스트로 작성하는 문법이자 도구다. 이 텍스트를 마크다운 코드 블록에 넣으면 Mermaid 를 지원하는 뷰어가 이미지로 렌더링한다.
- AST: 소스 코드나 마크다운 같은 텍스트를 문법 구조에 따라 트리로 나타낸 자료 구조다. 컴파일러와 분석 도구가 코드를 읽을 때 만든다.

## English

## 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 Pandoc User’s Guide, Pandoc renders LaTeX math as Word’s equation format in docx output. The same guide says nothing about Mermaid 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 AST 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.

### Terms

- Pandoc: An open-source command-line program that converts documents between many formats, such as Markdown, HTML and Word.
- LaTeX: A language for writing documents with math, such as papers. In Markdown, math is written in LaTeX syntax between dollar signs.
- Mermaid: A 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.
- AST: Abstract 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.

## Launches the same day

- trustmebro.reviews <https://www.trustmebro.reviews/> (Show HN, 10): 제품 의견 검색 사이트. Reddit 과 HN 에서 제품 48,000개에 대한 의견 13,000,000개를 추출했다고 소개한다.
- Spooler <https://spooler.sh/> (Show HN, 9): 관리형 메시지 큐 서비스. 큐 서버는 제작자가 운영한다.
- AI Gude <https://github.com/alex0ptr/aigude> (Show HN, 7): 피드 팟캐스트 도구. 구독한 피드를 AI 로 읽어 매일 듣는 팟캐스트로 만든다.
- Chinese sentence checker <https://sentencecoach.com/chinese-grammar-checker> (Show HN, 7): 중국어 문장 검사기. 병음과 영어 설명을 붙여 문법을 고쳐 준다.
- HackerSCAD <https://hackerscad.com/> (Show HN, 7): 3D 모델링 언어. OpenSCAD 처럼 코드로 모델을 만들고, 모서리 둥글리기와 C 와 비슷한 문법을 더했다.
- Md2docx <https://md2docx.js.org/> (Show HN, 5): 마크다운 변환기. 표, 수식, 다이어그램을 Word 문서의 요소로 바꾼다.
- Muse4AI <https://github.com/andrew-babo/muse4ai> (GitHub, 475): AI 에이전트용 Windows 브리지. 에이전트가 Muse 로 이미지와 영상을 만들게 한다고 소개한다.
- Wanaka Studio <https://www.producthunt.com/products/wanaka-studio> (Product Hunt, 336): 3D 게임 제작 도구. AI 게임 엔진으로 3D 게임을 만든다고 소개한다.
- Floot Payments <https://www.producthunt.com/products/floot> (Product Hunt, 279): 앱 결제 도구. ChatGPT 와 Claude 에서 만든 앱이 결제를 받게 한다고 소개한다.
- Prelulu <https://www.producthunt.com/products/prelulu> (Product Hunt, 201): 롤플레이 앱. 사용자가 주인공이 되어 채팅과 영상으로 이야기를 이끌어 간다고 소개한다.

## Getting started

- Steps: npm install @m2d/cli ; npx m2d report.md -o report.docx
- Needs: Node.js. 계정과 키는 필요 없다.
- Cost: MIT, 무료.
- Note: README 에 따르면 Node.js 에서는 Mermaid 다이어그램 가운데 6종만 이미지로 바꾼다. 간트 차트, 파이 차트 같은 나머지 다이어그램은 코드 블록으로 남는다.
