Render a finished Chinese official-document Markdown into a .docxconforming to government layout. This is a "layout rendering" capability,not content drafting—for drafting use the "公文写作" skill in the root directory; this skill only performs export and layout adjustment after the Markdown structure is correct.
Shares the same prompts/ master source (font scheme, layout scheme, document-type binding) with "公文写作", without duplicating rules.
File index
src/scripts/generate_docx.py # 导出器主入口(CLI)
src/scripts/install_fonts.sh # 安装 assets/fonts/ 下字体到系统
src/scripts/download_fonts.sh # 拉取开源替代字体
prompts/font-profiles/*.toml # 字体方案(标题/正文/层级字体字号)
prompts/layout-profiles/*.toml # 版式方案(固定行距、各段后距、首行缩进)
prompts/doc-types/<id>-<文种>/meta.toml # 文种 → font_profile / layout_profile 绑定
assets/fonts/catalog.toml # 字体族 → assets/fonts/ 具体文件映射
docs/references/font-usage.md # 字体速查、导出已知坑、自检命令(面向读者)
docs/references/layout-rules.md # 版式规范、已自动化/未自动化清单、页边距
How to invoke
- First confirm the Markdown structure is correct (title, recipient unit, body, signature, notes, attachments, etc. are delimited with
##blocks). - Fonts and layout are applied automatically by document type:
--doc-type <文种>(Chinese alias or English ID both work); the script parsesmeta.tomlaccording tofont_profile/layout_profile。 - or specify manually:
--font-preset、--title-font、--body-fontand other slots. - Before export, use
--show-font-plan/--show-layout-planto preview the actual fonts, font sizes, and layout parameters applied.
python3 src/scripts/generate_docx.py 成稿.md -o 成稿.docx --doc-type 通知
python3 src/scripts/generate_docx.py --doc-type 报告 --show-font-plan # 预览不导出
Default layout (master source)
- Page margins: per GB/T 9704-2012, top 37mm, bottom 35mm, left 28mm, right 26mm (text area 156mm×225mm; the constant's true source is in
src/docgen/constants.pyofMARGIN_*_TWIPS, exported viasrc/scripts/generate_docx.py). - Line spacing, space after each paragraph, first-line indent: determined by the
prompts/layout-profiles/*.tomlbound to the document type, without repeatedly hard-coding values in the document. - Title/body/hierarchy fonts and sizes: determined by
prompts/font-profiles/*.toml+assets/fonts/catalog.toml. - To adjust layout, prefer modifying the corresponding
*.tomlmaster source; use CLI overrides only for one-off needs.
Known pitfalls (symptom / cause / remedy)
- Fonts look different on another machine: the script only writes font names and does not embed
.ttf; on the target machine firstbash src/scripts/install_fonts.sh, and export to PDF when locking the visual appearance. - Image does not appear: only local
png/jpg/jpegis supported; useas a standalone block, preferably placed in附件/附图/附录。 - No footer page number on the first page: expected behavior (displayed from the second page onward); to have no page numbers at all add
--hide-page-number。 - Gray background on the footer: this is the editor's "field shading" display, not document shading.
For a more complete font quick reference and commands, see docs/references/font-usage.md, and for layout specifications see docs/references/layout-rules.md。
Boundaries
- Outside the automation scope: agency red-header plate setting, seal over the document date, complete red line setting—these still require final verification using your unit's Word template.
- If changing fonts/layout involves the
*.tomlmaster source, runpython3 src/adapters/skill/build.py --checkto confirm the artifacts are in sync.