SuperAPI AI Directory

docx-export

General & other

View repository

Updated 10-16 09:45

About this skill

Official-document docx export

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 parses meta.toml according to font_profile/layout_profile。
  • or specify manually:--font-preset、--title-font、--body-font and other slots.
  • Before export, use --show-font-plan / --show-layout-plan to 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.py of MARGIN_*_TWIPS, exported via src/scripts/generate_docx.py ).
  • Line spacing, space after each paragraph, first-line indent: determined by the prompts/layout-profiles/*.toml bound 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 *.toml master 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 first bash src/scripts/install_fonts.sh, and export to PDF when locking the visual appearance.
  • Image does not appear: only local png/jpg/jpegis supported; use ![图1 标题](./本地路径.png) as 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 *.toml master source, run python3 src/adapters/skill/build.py --check to confirm the artifacts are in sync.