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.
python3 scripts/md_to_docx.py input.md -o output.docx
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:
.md file path.doc/.docx template, or check if one exists in common locations (docs/, templates/)```bash
pip3 install python-docx
npm list -g @mermaid-js/mermaid-cli 2>/dev/null || npm install -g @mermaid-js/mermaid-cli
```
scripts/ directory:```bash
python3
```
When a template is provided, the script analyzes it automatically:
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 |
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共 1 个版本