Overview
Convert Markdown documents into Word documents that meet Chinese typesetting standards. Supports complete Markdown syntax and automatically applies professional formatting settings.
Dependency Requirements
Python Dependencies
pip install python-docx Pillow beautifulsoup4 PyYAML
Optional Dependencies
npm install -g @mermaid-js/mermaid-cli
Quick Start
Main conversion script:scripts/md2word.py
# 基本转换
python scripts/md2word.py input.md output.docx
# 使用预设格式
python scripts/md2word.py input.md --preset=academic
# 使用自定义配置
python scripts/md2word.py input.md --config=my-config.yaml
Configuration System
Built-in Presets
Preset information is dynamically read from YAML files. Run the following command to view the complete list:
python scripts/config.py --list
Common presets:
- legal — Legal document format (default)
- service-plan — Legal service proposal (with layered color scheme)
- minimal — Minimal format
- academic — Academic paper format
- report — Work report format
See the complete configuration in
assets/presets/*.yaml, and the design notes inassets/theme-notes/
Custom Configuration
Copy the configuration template and modify it:
cp assets/config-template.yaml my-config.yaml
Word Template File
Place the .docx template into the assets/templates/ directory, or use --template to specify it.
Word Template vs Configuration File:
- Word Template: Controls visual elements (header, footer, Logo)
- Configuration File: Controls formatting parameters (font size, line spacing, page margins)
Reference Documents
- Configuration Reference: references/config-reference.md
- Style Mapping: references/style-mappings.md
- Usage Examples: references/examples.md
Error Handling
- File Encoding: Automatically detects UTF-8 and GBK
- Template Not Found: Creates a new document using the default format
- Mermaid Failure: Degrades to a text description
- Image Too Large: Automatically compresses and resizes
Directory Structure
md2word/
├── SKILL.md # 本文档
├── CHANGELOG.md # 版本记录
├── references/ # 参考文档
│ ├── config-reference.md
│ ├── style-mappings.md
│ └── examples.md
├── scripts/ # 转换脚本
│ ├── md2word.py # 主脚本
│ ├── config.py # 配置模块(含 --list 查看预设)
│ ├── extract_template_config.py # 从 Word 模板提取配置
│ ├── formatter.py # 文本格式化模块
│ ├── table_handler.py # 表格处理模块
│ └── chart_handler.py # 图表渲染模块
└── assets/ # 资源文件
├── presets/ # YAML 预设配置
├── theme-notes/ # 预设设计说明文档
├── templates/ # Word 模板文件
└── config-template.yaml