lovstudio-any2docx
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseany2docx — Markdown to Professional DOCX
any2docx — Markdown转专业DOCX
This skill converts any Markdown file into a professionally styled Word document using
Python's python-docx library. It shares the same theme palette as any2pdf and handles
all CJK/Latin edge cases correctly.
本技能借助Python的python-docx库,将任意Markdown文件转换为具有专业样式的Word文档。它与any2pdf使用相同的主题调色板,能正确处理所有CJK/拉丁文本的边缘情况。
When to Use
使用场景
- User wants to convert →
.md(Word).docx - User needs an editable document (not PDF)
- Document contains CJK characters mixed with Latin text
- Document has fenced code blocks, markdown tables, or lists
- User wants a cover page, table of contents, or watermark in their DOCX
- 用户需要将文件转换为
.md(Word)文件.docx - 用户需要可编辑的文档(而非PDF)
- 文档包含CJK与拉丁混合文本
- 文档包含围栏代码块、Markdown表格或列表
- 用户希望在DOCX中添加封面、目录或水印
Quick Start
快速开始
bash
python lovstudio-any2docx/scripts/md2docx.py \
--input report.md \
--output report.docx \
--title "My Report" \
--author "Author Name" \
--theme warm-academicAll parameters except are optional — sensible defaults are applied.
--inputbash
python lovstudio-any2docx/scripts/md2docx.py \
--input report.md \
--output report.docx \
--title "My Report" \
--author "Author Name" \
--theme warm-academic除外,所有参数均为可选——系统会应用合理的默认值。
--inputPre-Conversion Options (MANDATORY)
转换前必选设置
IMPORTANT: You MUST use the tool to ask these questions BEFORE
running the conversion. Do NOT list options as plain text — use the tool so the user
gets a proper interactive prompt. Ask all options in a SINGLE call.
AskUserQuestionAskUserQuestionUse with the following template:
AskUserQuestion开始转 Word!先帮你确认几个选项 👇
━━━ 📐 设计风格 ━━━
a) 暖学术 — 陶土色调,温润典雅,适合人文/社科报告
b) 经典论文 — 棕色调,灵感源自 LaTeX classicthesis,适合学术论文
c) Tufte — 极简留白,深红点缀,适合数据叙事/技术写作
d) 期刊蓝 — 藏蓝严谨,灵感源自 IEEE,适合正式发表风格
e) 精装书 — 咖啡色调,书卷气,适合长篇专著/技术书
f) 中国红 — 朱红配暖纸,适合中文正式报告/白皮书
g) 水墨 — 纯灰黑,素雅克制,适合文学/设计类内容
h) GitHub — 蓝白极简,程序员熟悉的风格
i) Nord 冰霜 — 蓝灰北欧风,清爽现代
j) 海洋 — 青绿色调,清新自然
k) 投资报告 — 楷体+深红,专业严谨,适合投资/尽调报告
━━━ 💧 水印 ━━━
1) 不加
2) 自定义文字(如 "DRAFT"、"内部资料")
示例回复:"a, 水印:仅供内部参考"
直接说人话就行,不用记编号 😄重要提示:运行转换前,你必须使用工具询问以下问题。请勿以纯文本形式列出选项——使用工具为用户提供合适的交互式提示。在单次调用中询问所有选项。
AskUserQuestionAskUserQuestion使用工具并采用以下模板:
AskUserQuestion开始转 Word!先帮你确认几个选项 👇
━━━ 📐 设计风格 ━━━
a) 暖学术 — 陶土色调,温润典雅,适合人文/社科报告
b) 经典论文 — 棕色调,灵感源自 LaTeX classicthesis,适合学术论文
c) Tufte — 极简留白,深红点缀,适合数据叙事/技术写作
d) 期刊蓝 — 藏蓝严谨,灵感源自 IEEE,适合正式发表风格
e) 精装书 — 咖啡色调,书卷气,适合长篇专著/技术书
f) 中国红 — 朱红配暖纸,适合中文正式报告/白皮书
g) 水墨 — 纯灰黑,素雅克制,适合文学/设计类内容
h) GitHub — 蓝白极简,程序员熟悉的风格
i) Nord 冰霜 — 蓝灰北欧风,清爽现代
j) 海洋 — 青绿色调,清新自然
k) 投资报告 — 楷体+深红,专业严谨,适合投资/尽调报告
━━━ 💧 水印 ━━━
1) 不加
2) 自定义文字(如 "DRAFT"、"内部资料")
示例回复:"a, 水印:仅供内部参考"
直接说人话就行,不用记编号 😄Mapping User Choices to CLI Args
用户选择与CLI参数映射
| Choice | CLI arg |
|---|---|
| Design style a-k | |
| Watermark text | |
| 选项 | CLI参数 |
|---|---|
| 设计风格a-k | |
| 水印文字 | |
Theme Name Mapping
主题名称映射
| Choice | |
|---|---|
| a) 暖学术 | |
| b) 经典论文 | |
| c) Tufte | |
| d) 期刊蓝 | |
| e) 精装书 | |
| f) 中国红 | |
| g) 水墨 | |
| h) GitHub | |
| i) Nord | |
| j) 海洋 | |
| k) 投资报告 | |
| 选项 | |
|---|---|
| a) 暖学术 | |
| b) 经典论文 | |
| c) Tufte | |
| d) 期刊蓝 | |
| e) 精装书 | |
| f) 中国红 | |
| g) 水墨 | |
| h) GitHub | |
| i) Nord | |
| j) 海洋 | |
| k) 投资报告 | |
Architecture
架构流程
Markdown → Strip frontmatter → Preprocess (split merged headings) → Parse (code-fence-aware) → python-docx Document → .docxKey components:
- CJK font switching: detects CJK runs and assigns Songti SC / SimSun / Noto CJK
_split_mixed() - Inline markdown: handles bold, italic,
_parse_inline(), linkscode - Images: Local paths (relative to .md) and remote URLs — auto-downloaded and embedded via
add_picture() - Code blocks: Shaded paragraph with monospace font and border
- Tables: Header row with accent background, alternating row shading
- Watermark: VML-based diagonal watermark in header (Word-native)
- TOC: Field code with static fallback entries; triggers auto-refresh on open
updateFields=true - YAML frontmatter: Automatically stripped (won't leak etc. into output)
status: draft - Adaptive cover title: Font size scales down for long titles (36pt → 22pt)
Markdown → 移除前置元数据 → 预处理(拆分合并标题)→ 解析(识别代码块)→ python-docx Document → .docx核心组件:
- CJK字体切换:检测CJK文本段并分配宋体(Songti SC / SimSun / Noto CJK)
_split_mixed() - 行内Markdown:处理粗体、斜体、
_parse_inline()、链接代码 - 图片:支持本地路径(相对于.md文件)和远程URL——通过自动下载并嵌入
add_picture() - 代码块:带阴影的段落,使用等宽字体并添加边框
- 表格:表头行带强调背景色,行底纹交替显示
- 水印:基于VML的对角水印,嵌入页眉(Word原生支持)
- 目录:包含静态备用条目的域代码;会在打开文档时触发自动刷新
updateFields=true - YAML前置元数据:自动移除(不会将等内容泄露到输出文件中)
status: draft - 自适应封面标题:标题过长时自动缩小字号(36pt → 22pt)
Configuration Reference
配置参数参考
| Argument | Default | Description |
|---|---|---|
| (required) | Path to markdown file |
| | Output DOCX path |
| From first H1 | Document title for cover page |
| | Subtitle text |
| | Author name |
| Today | Date string |
| | Version string for cover |
| | Watermark text (empty = none) |
| | Color theme name |
| | Generate cover page |
| | Generate table of contents |
| | Report title in page header |
| author | Brand/author in footer |
| | Stats on cover |
| | Second stats line |
| | Edition line on cover |
| | Max lines per code block |
| 参数 | 默认值 | 描述 |
|---|---|---|
| 必填 | Markdown文件路径 |
| | 输出DOCX文件路径 |
| 首个H1标题 | 封面页的文档标题 |
| | 副标题文本 |
| | 作者姓名 |
| 今日日期 | 日期字符串 |
| | 封面页的版本字符串 |
| | 水印文本(空值表示无水印) |
| | 配色主题名称 |
| | 生成封面页 |
| | 生成目录 |
| | 页面页眉中的报告标题 |
| 作者姓名 | 页脚左侧的品牌/作者信息 |
| | 封面页的统计信息行 |
| | 第二行统计信息 |
| | 封面页的版本说明行 |
| | 单个代码块的最大行数 |
Dependencies
依赖安装
bash
pip install python-docx --break-system-packagesbash
pip install python-docx --break-system-packages