Generate professional .docx documents from Markdown, or fill data into .docx templates.
[待填写]) or ask the user.{{variable_name}} patterns are matched at the w:t XML node level inside the .docx. Values are sanitized to escape & < > " ' and remove control characters./tmp/...) and path traversal ( ..) are rejected.--strict mode on fill_template.py returns exit code 1 when any placeholder remains unreplaced, enabling CI/CD gate usage.CommandWhat it doespython3 <skill-path>/scripts/generate.py <input.md> <output.docx>Convert Markdown to .docxpython3 <skill-path>/scripts/generate.py --style <style> <input.md> <output.docx>Convert with a specific style`python3 /scripts/fill_template.py --data <data.jsonfrontmatter.md> --output <out.docx> <template.docx>`python3 <skill-path>/scripts/fill_template.py --strict --data <data.json> --output <out.docx> <template.docx>Fill template, fail if placeholders remainpython3 <skill-path>/scripts/validate.py <file.docx>Validate .docx file structure
bash
python3 <skill-path>/scripts/generate.py input.md output.docx
python3 <skill-path>/scripts/generate.py --style report input.md output.docx
When no --style is specified, recommend a style based on topic keywords:
Topic keywordsRecommended styleUse case合同、协议、条款、contract, agreementcontractContracts & legal documents报告、分析、数据、KPI、report, analysis, dashboardreportBusiness reports (blue headers)会议纪要、meeting minutes, 讨论meetingMeeting minutes (compact layout)红头文件、通知、通报、dispatch, official noticedispatchOfficial dispatchs (red header)技术、API、架构、代码、spec, architecturetech_specTechnical specs (monospace body)公函、商务信、letterbusiness_letterBusiness letters公告、公告通知、notice, announcementnoticeOfficial notices (large bold text)其他 / generalstandardGeneral documents
When routing, announce: "推荐使用 [style] 样式 ([description]),可用 --style 覆盖。"
If the user does not specify an output filename, derive it from the input file:
<input>.md → <input>.docx (same basename, replace extension)doc-<YYYY-MM-DD>-<slug>.docxFeatureSyntaxHeadings (H1-H3)#, ##, ###ParagraphsText blocksBold / Italic**bold**, *italic*Bullet / Numbered lists-, 1.TablesStandard GFM tablesCode blocksTriple backticks, with optional languageBlockquotes (callout)> text → info boxImagesPage break<!-- pagebreak -->Horizontal rule---YAML front matter---\ntitle: ...\n---
StyleUse casestandard (default)General documentscontractContracts & agreements (formal, 12pt)reportBusiness reports (blue headers, 10.5pt)meetingMeeting minutes (compact, 10.5pt)business_letterBusiness letters (traditional format)tech_specTechnical specifications (monospace, dark theme)dispatchOfficial dispatchs / 红头文件 (red header)noticeOfficial notices (bold, 14pt)
yaml
---
title: Document Title # 写入 docx core_properties.title
author: Author Name # 写入 docx core_properties.author
date: 2026-04-10 # 写入 docx core_properties.created
lang: zh # 可选: zh | en, 影响默认文本
header:
text: CONFIDENTIAL # 页眉文字
alignment: center # left | center | right
footer:
page_number: true # 显示页码
toc:
max_level: 3 # TOC 包含的最大标题级别 (1-3)
---
All fields are optional. title, author, and date are written to the .docx core properties (visible in Word → File → Info).
bash
# With JSON data
python3 <skill-path>/scripts/fill_template.py --data data.json --output output.docx template.docx
# With Markdown front matter as data
python3 <skill-path>/scripts/fill_template.py --data frontmatter.md --output output.docx template.docx
# Strict mode: fail if any placeholder remains unreplaced
python3 <skill-path>/scripts/fill_template.py --strict --data data.json --output output.docx template.docx
Data format (JSON):
json
{
"company_name": "Acme Corp",
"amount": "¥1,000,000",
"date": "2026-04-10"
}
Template placeholders are {{variable_name}} patterns in the .docx text (matched at w:t XML node level). Values are automatically sanitized to escape XML special characters and remove control characters. Long values are truncated to prevent layout breakage.
When --strict is passed, the script exits with code 1 if any {{placeholder}} remains unreplaced after filling. This enables CI/CD gating: all placeholders must have corresponding data keys.
Exceeding limits triggers automatic truncation with no error.
After generating a .docx, run these checks:
Automated checks (run validate.py on the output):
word/document.xml, [Content_Types].xml, word/_rels/document.xml.rels){{placeholders}} detectedVisual checks (open in Word/WPS):
5. Style conformance — headings use the correct style preset colors and fonts (see references/style-presets.md for exact values)
6. Spacing — callouts have proper spacing from surrounding elements
7. Tables — column widths are reasonable, no emoji overlap
8. Code blocks — monospace font + gray background rendering
9. TOC — if requested, TOC field code is present (requires Word to update fields)
10. Images — embedded images render at correct size, no broken links
Template filling checks:
11. All {{placeholders}} with matching data keys are replaced
12. No XML corruption — the output opens without error
13. Long values are truncated appropriately (no layout breakage)
Use --validate flag with generate.py to run automated checks automatically after generation.
{{placeholder}} variables