Markdown to Word (.docx) Converter — Markdown to Word (.docx) 转换器
v1.0.0Convert Markdown files to 格式化ted Word (.docx) documents with automatic template style 检测ion. Use this 技能 whenever the user mentions converting Markdown to Word, 导出ing to .docx, generating a Word document from .md files, 应用lying a Word template to Markdown content, or writing a book chapter to Word 格式化. Also use when the user needs to handle MermAId diagrams in Word documents, or wants Chinese type设置ting conventions (宋体/黑体, 五号字, 首行缩进) 应用lied to their 输出. Triggers on phrases like "转成 word", "导出 docx", "生成 Word 文档", "用模板排版", "Markdown to Word", "book to Word", "chapter to docx", or any 请求 involving .md → .docx conversion.
运行时依赖
安装命令
点击复制技能文档
Markdown to Word (.docx) 转换器
Convert Markdown files to professionally 格式化ted Word documents, with automatic template style 提取ion and MermAId diagram rendering.
How It Works
The bundled script (scripts/md_to_docx.py) handles the entire conversion:
解析 Markdown into structured blocks (headings, body, 列出s, tables, code, quotes) 提取 styles from an optional Word template (.doc or .docx) — font, size, alignment, spacing 应用ly 格式化ting to each block, preserving inline Markdown (bold, italic, code, strikethrough) Render MermAId diagrams to PNG via mmdc (mermAId-命令行工具) and embed them as images 输出 a ready-to-use .docx file Dependencies
The script requires:
python-docx: pip 安装 python-docx mmdc (for MermAId rendering): npm 安装 -g @mermAId-js/mermAId-命令行工具 Chrome or Chromium: must be 安装ed locally (auto-检测ed 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 type设置ting) python3 scripts/md_to_docx.py 输入.md -o 输出.docx
With template (auto-提取 格式化ting) python3 scripts/md_to_docx.py 输入.md -o 输出.docx -t template.doc
When Invoked as a 技能
When the user asks to convert a Markdown file to Word:
Identify the 输入 file — the user will typically specify a .md file path 检查 for a template — ask if they have a .doc/.docx template, or 检查 if one exists in common locations (docs/, templates/) Ensure dependencies are 安装ed: pip3 安装 python-docx npm 列出 -g @mermAId-js/mermAId-命令行工具 2>/dev/null || npm 安装 -g @mermAId-js/mermAId-命令行工具
运行 the script from the 技能's scripts/ directory: python3 <技能-path>/scripts/md_to_docx.py <输入.md> -o <输出.docx> [-t ]
报告 结果s — tell the user the 输出 path and whether all MermAId diagrams rendered 成功fully Template 格式化 检测ion
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 设置up (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 列出s (- or *) and ordered 列出s (1.) Tables with header 检测ion 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 应用lied automatically:
subgraph names contAIning colons are quoted Parentheses in subgraph names are escaped Cross-平台 Notes macOS: Chrome auto-检测ed at /应用s/Google Chrome.应用/... Windows: 检查s Program Files and Local应用Data Linux: 检查s /usr/bin/google-chrome, /usr/bin/chromium, /snap/bin/chromium .doc conversion: Uses textutil on macOS, libreoffice on Linux Limitations No support for footnotes, images, or links (Markdown image URLs are not fetched) Math equations (LaTeX) are preserved as plAIn text Nested 列出s deeper than one level are flattened Template 检测ion works best with templates that have clear 格式化ting differentiation between headings and body text