md-to-docx-template
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMarkdown to DOCX with Templates
基于模板的Markdown转DOCX
Convert markdown to professionally styled Word documents. Not plain exports — beautiful, branded documents with your fonts, colors, and table styling applied automatically.
将Markdown转换为具有专业样式的Word文档。并非普通导出——而是会自动应用您的字体、颜色和表格样式的精美品牌化文档。
When to Use
适用场景
- User wants to convert markdown to Word/DOCX
- User needs a branded document from markdown source
- User asks about exporting markdown with styling
- User mentions "md to docx", "markdown to word", or similar
- 用户需要将Markdown转换为Word/DOCX格式
- 用户希望从Markdown源文件生成品牌化文档
- 用户询问如何导出带有样式的Markdown
- 用户提及“md转docx”、“markdown转word”或类似需求
Prerequisites
前置条件
- installed (
pandocon macOS)brew install pandoc - Python 3.8+ with packages: ,
python-docx,lxml,clickpyyaml
- 已安装 (macOS系统可通过
pandoc安装)brew install pandoc - Python 3.8及以上版本,并安装以下包:,
python-docx,lxml,clickpyyaml
Installation
安装步骤
Clone this skill's scripts to your preferred location:
bash
git clone https://github.com/jonnyschneider/skills.git
cd skills/skills/md-to-docx-template
pip install python-docx lxml click pyyaml将本技能的脚本克隆到您偏好的位置:
bash
git clone https://github.com/jonnyschneider/skills.git
cd skills/skills/md-to-docx-template
pip install python-docx lxml click pyyamlQuick Conversion
快速转换
bash
./md-to-docx.py input.md -o output.docxbash
./md-to-docx.py input.md -o output.docxWith Custom Template
使用自定义模板
Option A: Generate template with specific fonts/colors
选项A:生成带有指定字体/颜色的模板
bash
./create-reference-template.py template.docx \
--font-body "DM Sans" \
--font-heading "DM Sans" \
--accent-color "0D494D" \
--heading-color "0D494D"
./md-to-docx.py input.md -o output.docx --template template.docxbash
./create-reference-template.py template.docx \
--font-body "DM Sans" \
--font-heading "DM Sans" \
--accent-color "0D494D" \
--heading-color "0D494D"
./md-to-docx.py input.md -o output.docx --template template.docxOption B: Extract styles from existing branded document
选项B:从现有品牌化文档中提取样式
bash
undefinedbash
undefinedFull pipeline for best results:
最佳效果的完整流程:
./extract-styles.py source-branded.docx template.docx
./md-to-docx.py input.md -o output.docx --template template.docx --no-fix-indent
./apply-template-styles.py template.docx output.docx
./fix-table-headers.py output.docx
undefined./extract-styles.py source-branded.docx template.docx
./md-to-docx.py input.md -o output.docx --template template.docx --no-fix-indent
./apply-template-styles.py template.docx output.docx
./fix-table-headers.py output.docx
undefinedMulti-file Documents
多文件文档转换
Create a :
manifest.yamlyaml
template: template.docx
output: final-document.docx
sections:
- 01-intro.md
- 02-content.md
- 03-conclusion.mdThen run:
bash
./md-to-docx.py manifest.yaml --open创建 文件:
manifest.yamlyaml
template: template.docx
output: final-document.docx
sections:
- 01-intro.md
- 02-content.md
- 03-conclusion.md然后运行:
bash
./md-to-docx.py manifest.yaml --openKey Options
关键选项
| Option | Description |
|---|---|
| Output DOCX path |
| Custom reference template |
| Generate table of contents |
| Open after building |
| Skip list indent fix (use with extract pipeline) |
| 选项 | 描述 |
|---|---|
| 输出DOCX文件路径 |
| 自定义参考模板 |
| 生成目录 |
| 转换完成后自动打开文档 |
| 跳过列表缩进修复(配合样式提取流程使用) |
Template Options
模板选项
| Option | Description |
|---|---|
| Body text font (default: Calibri) |
| Heading font (default: Calibri) |
| Code font (default: Consolas) |
| Table header color (hex, default: 4472C4) |
| Heading text color (hex, default: 000000) |
| 选项 | 描述 |
|---|---|
| 正文字体(默认:Calibri) |
| 标题字体(默认:Calibri) |
| 代码字体(默认:Consolas) |
| 表格标题颜色(十六进制值,默认:4472C4) |
| 标题文字颜色(十六进制值,默认:000000) |
Limitations
限制说明
- Custom fonts must be installed on target machines
- Complex tables may not render perfectly
- SVG images require
rsvg-convert - Some pandoc quirks require post-processing scripts
- 自定义字体必须已安装在目标机器上
- 复杂表格可能无法完美渲染
- SVG图片需要依赖 工具
rsvg-convert - Pandoc的一些特性需要通过后处理脚本修复