md-to-docx
Convert Markdown files to formatted Word (.docx) documents with automatic template style detection. Use this skill whenever the user mentions converting Markdown to Word, exporting to .docx, generating a Word document from .md files, applying a Word template to Markdown content, or writing a book chapter to Word format. Also use when the user needs to handle Mermaid diagrams in Word documents, or wants Chinese typesetting conventions (宋体/黑体, 五号字, 首行缩进) applied to their output. Triggers on phrases like "转成 word", "导出 docx", "生成 Word 文档", "用模板排版", "Markdown to Word", "book to Word", "chapter to docx", or any request involving .md → .docx conversion.
- License 许可
- MIT
- 最近更新
- 2026-06-10
- Stars
- ★ 3
- Forks
- 0
01 前言 Front Matter
- name
- md-to-docx
- description
- Convert Markdown files to formatted Word (.docx) documents with automatic template style detection. Use this skill whenever the user mentions converting Markdown to Word, exporting to .docx, generating a Word document from .md files, applying a Word template to Markdown content, or writing a book chapter to Word format. Also use when the user needs to handle Mermaid diagrams in Word documents, or wants Chinese typesetting conventions (宋体/黑体, 五号字, 首行缩进) applied to their output. Triggers on phrases like "转成 word", "导出 docx", "生成 Word 文档", "用模板排版", "Markdown to Word", "book to Word", "chapter to docx", or any request involving .md → .docx conversion.
03 SKILL.md 正文
Markdown to Word (.docx) Converter
Convert Markdown files to professionally formatted Word documents, with automatic template style extraction and Mermaid diagram rendering.
How It Works
The bundled script (scripts/md_to_docx.py) handles the entire conversion:
- Parse Markdown into structured blocks (headings, body, lists, tables, code, quotes)
- Extract styles from an optional Word template (.doc or .docx) — font, size, alignment, spacing
- Apply formatting to each block, preserving inline Markdown (bold, italic, code, strikethrough)
- Render Mermaid diagrams to PNG via
mmdc(mermaid-cli) and embed them as images - Output a ready-to-use .docx file
Dependencies
The script requires:
- python-docx:
pip install python-docx - mmdc (for Mermaid rendering):
npm install -g @mermaid-js/mermaid-cli - Chrome or Chromium: must be installed locally (auto-detected on macOS/Windows/Linux)
On macOS, .doc templates are converted via the built-in textutil. On Linux, LibreOffice is used as fallback.
Usage
Basic conversion (default Chinese typesetting)
python3 scripts/md_to_docx.py input.md -o output.docx
With template (auto-extract formatting)
python3 scripts/md_to_docx.py input.md -o output.docx -t template.doc
When Invoked as a Skill
When the user asks to convert a Markdown file to Word:
- Identify the input file — the user will typically specify a
.mdfile path - Check for a template — ask if they have a
.doc/.docxtemplate, or check if one exists in common locations (docs/,templates/) - Ensure dependencies are installed:
pip3 install python-docx npm list -g @mermaid-js/mermaid-cli 2>/dev/null || npm install -g @mermaid-js/mermaid-cli - Run the script from the skill's
scripts/directory:python3 <skill-path>/scripts/md_to_docx.py <input.md> -o <output.docx> [-t <template.doc>] - Report results — tell the user the output path and whether all Mermaid diagrams rendered successfully
Template Format Detection
When a template is provided, the script analyzes it automatically:
- Title levels are identified by font size and alignment (largest centered = chapter title, etc.)
- Body text is identified by paragraphs with first-line indentation
- Page setup (margins, paper size) is copied from the template
- Chinese font pairing is preserved (e.g., Times New Roman ↔ 宋体, Arial ↔ 黑体)
If no template is provided, these defaults are used (Chinese publishing standard):
| Element | Font | Size | Alignment |
|---|---|---|---|
| Chapter title (h1) | 黑体 | 18pt | Center |
| Section title (h2) | 黑体 | 16pt | Center |
| Subsection (h3) | 黑体 | 14pt | Left |
| Body text | 宋体 | 10.5pt (五号) | Justify, 2-char indent |
| Code | Consolas | 9pt | Left |
| Quote | 楷体 | 10.5pt | Left indent, italic |
Supported Markdown Features
- Headings: h1–h6 (h1 = chapter, h2 = section, h3 = subsection, h4+ = sub-subsection)
- Body text with inline: bold, italic,
code,strikethrough, bold italic - Bullet lists (
-or*) and ordered lists (1.) - Tables with header detection
- Code blocks with language label
- Mermaid diagrams rendered to embedded PNG images
- Block quotes and horizontal rules
Mermaid Diagram Handling
Mermaid code blocks are rendered to PNG via mmdc using the local Chrome browser. If rendering fails (e.g., Chrome not found, syntax error), the diagram falls back to a code block display.
Common Mermaid compatibility fixes are applied automatically:
subgraphnames containing colons are quoted- Parentheses in subgraph names are escaped
Cross-Platform Notes
- macOS: Chrome auto-detected at
/Applications/Google Chrome.app/... - Windows: Checks
Program FilesandLocalAppData - Linux: Checks
/usr/bin/google-chrome,/usr/bin/chromium,/snap/bin/chromium .docconversion: Usestextutilon macOS,libreofficeon Linux
Limitations
- No support for footnotes, images, or links (Markdown image URLs are not fetched)
- Math equations (LaTeX) are preserved as plain text
- Nested lists deeper than one level are flattened
- Template detection works best with templates that have clear formatting differentiation between headings and body text
04 同仓库更多 Skills
youtube-content
YouTube transcripts to summaries, threads, blogs.
xurl
X/Twitter via xurl CLI: post, search, DM, media, v2 API.
touchdesigner-mcp
Control a running TouchDesigner instance via twozero MCP — create operators, set parameters, wire connections, execute Python, build real-time visuals. 36 native tools.
test-driven-development
TDD: enforce RED-GREEN-REFACTOR, tests before code.
teams-meeting-pipeline
Operate the Teams meeting summary pipeline via Hermes CLI — summarize meetings, inspect pipeline status, replay jobs, manage Microsoft Graph subscriptions.
systematic-debugging
4-phase root cause debugging: understand bugs before fixing.