将 Markdown 文件转换为带自动模板样式检测的 Word (.docx) 文档。在用户提到转换 Markdown 时使用此技能。
Convert Markdown files to professionally formatted Word documents, with automatic template style extraction and Mermaid diagram rendering.
The bundled script ( scripts/md_to_docx.py) handles the entire conversion:
mmdc (mermaid-cli) and embed them as imagesThe script requires:
pip install python-docxnpm install -g @mermaid-js/mermaid-cliOn macOS, .doc templates are converted via the built-in textutil. On Linux, LibreOffice is used as fallback.
bash
python3 scripts/md_to_docx.py input.md -o output.docx
bash
python3 scripts/md_to_docx.py input.md -o output.docx -t template.doc
When the user asks to convert a Markdown file to Word:
Identify the input file — the user will typically specify a .md file path
Check for a template — ask if they have a .doc/ .docx template, or check if one exists in common locations ( docs/, templates/)
Ensure dependencies are installed: bash
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:
bash
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
When a template is provided, the script analyzes it automatically:
If no template is provided, these defaults are used (Chinese publishing standard):
ElementFontSizeAlignmentChapter title (h1)黑体18ptCenterSection title (h2)黑体16ptCenterSubsection (h3)黑体14ptLeftBody text宋体10.5pt (五号)Justify, 2-char indentCodeConsolas9ptLeftQuote楷体10.5ptLeft indent, italic
code, strikethrough, bold italic- or *) and ordered lists ( 1.)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:
subgraph names containing colons are quoted/Applications/Google Chrome.app/...Program Files and LocalAppData/usr/bin/google-chrome, /usr/bin/chromium, /snap/bin/chromium.doc conversion: Uses textutil on macOS, libreoffice on Linux