dsh-tool-gbt9704
Model-facing gbt9704_convert tool: reformat a Markdown (.md) or Word (.docx) source into the GB/T 9704-2012 党政机关公文格式 (Party-and-government official document) body layout as a new .docx.
The converter is self-contained: it reads the source with Node's fs, parses it through a shared document model (mdast for Markdown, an OOXML extractor for existing .docx files), renders the model onto a hand-built OOXML document (a minimal .docx container via fflate), and writes the output file. It registers no service and keeps no state; a call is a pure path-in/path-out conversion.
Layout applied (GB/T 9704-2012 body rules)
| Element | Rule |
|---|---|
| Sheet | A4 210 mm × 297 mm |
| Margins | 天头 37, 订口 28, 地脚 35, 翻口 26 mm → 版心 156 mm × 225 mm |
| Body | 三号仿宋_GB2312 (16 pt), justified, first-line indent two characters |
| Grid | 22 lines per page, 28 characters per line, fixed 28.95 pt (579 twips) line spacing |
| Title | 二号小标宋 (22 pt), centered, two blank lines after |
| 层次标题 | 一、黑体 / (一)楷体_GB2312 / 1. and (1)仿宋, first-line indent |
| 主送机关 | 顶格, ends with a full-width colon, one blank line before the body |
| 署名/成文日期 | Right-aligned; the date's first character sits two characters right of the signature's (right indents computed from both lengths, per §7.3.5.2) |
| 页码 | 四号宋体 "—1—", odd pages right-空一字, even pages left-空一字 (evenAndOddHeaders) |
All values are Config fields with the standard's defaults; a deployment may override fonts, sizes, margins, or line pitch from cordis.yml.
Writing conventions (约定位置解析)
The tool needs no metadata block; it reads the document by position:
- The first heading (or the first short paragraph when the source has no heading) is the 标题.
- Lines beginning with
一、/(一)/1./(1)become the four 层次标题 levels, regardless of Markdown heading depth. - The first short paragraph ending in a full-width colon is the 主送机关.
- The last two paragraphs are the 发文机关署名 and 成文日期 when the last one matches a date form (
2024年1月5日or二〇二四年一月五日). - GFM tables, ordered/unordered list items, code lines, blockquotes, and PNG/JPEG images convert to tables, body paragraphs, body paragraphs, body paragraphs, and centered images respectively.
Config
All fields are optional; the standard's defaults apply. z schema in src/index.ts.
| Key | Default | Meaning |
|---|---|---|
bodyFont |
仿宋_GB2312 | 正文/主送机关/三级四级标题 font |
titleFont |
方正小标宋简体 | 标题 font |
heading1Font |
黑体 | 一级标题 font |
heading2Font |
楷体_GB2312 | 二级标题 font |
latinFont |
Times New Roman | Latin/digit font |
pageNumberFont |
宋体 | 页码 font |
bodySizePt / titleSizePt / pageNumberSizePt |
16 / 22 / 14 | sizes in points |
linePitchTwips |
579 | fixed line pitch in twips |
topMarginMm / leftMarginMm / bottomMarginMm / rightMarginMm |
37 / 28 / 35 / 26 | page margins in mm |
Model Experience
Request context and condition
What the model sees
The tool's full description plus the standard's layout summary; the model supplies a source path and optional overrides. The description pins the conversion conventions verbatim so the model knows which Markdown forms map to which 公文 elements.
Token effect
One tool description, fixed; no data-dependent prompt growth. The model-facing result is a short summary (output path, detected title, block counts, warnings).
KV Cache effect
The tool description is a stable prefix; it does not invalidate cache reuse. Results vary per call but are result-turn content, not request context.
Known Limitations and Deferred Work
- Docx→docx fidelity — the reader extracts paragraph/table text and images only; complex Word features (headers/footers, comments, tracked changes, charts, text boxes, per-run fonts) are not carried into the rebuilt document. Use it to normalize plain official documents, not to round-trip arbitrary Word files.
- Images — only PNG and JPEG are embedded; inline (mid-paragraph) images and images inside table cells are dropped. Remote
http(s)image URLs in Markdown are reported as warnings. - Red-header and 版记 — the 版头 (发文机关标志, 发文字号, red separator line, 份号/密级) and 版记 (抄送/印发机关, 分隔线) are out of scope; the converter produces the 主体 body layout plus page numbers.
- Font availability — 仿宋_GB2312, 方正小标宋简体 and 楷体_GB2312 are common on Windows 公文 deployments but may be absent elsewhere; Word substitutes fonts at open time. Override via
Configwhen a deployment standardizes on different names. - No sandbox mediation — the tool performs its own
fsreads and writes and does not go through thectx.fsservice, so its writes are not recorded as agent-observed file state and are not confined by the filesystem sandbox. Model-facing file mutation tools remain the sandboxed path; this tool is a dedicated converter.
No comments yet. Be the first to write one.