dsh-cn-doc-formatter: Generating Official Documents and Performing Output Self-Checks per GB/T 9704-2012

Preface

When using DeepSeek Harness (DSH) to let agents draft Chinese materials, the common practice is to apply Word templates or manually adjust margins and font sizes. Templates often “look the same,” but it is difficult to verify them item-by-item against the Format of Official Documents of Party and Government Organs. Conversely, handing them directly to a model for export often leaves issues such as watermarks, annotations, or hierarchical structures being treated as body text. Below is an introduction to the community plugin dsh-cn-doc-formatter (npm package name @deepwhale-cn/dsh-cn-doc-formatter): it encodes typography rules into scripts and runs a self-check after generating .docx / .pdf / .txt files. It reports errors for non-compliance, facilitating interception at delivery or CI gates.

What is this

dsh-cn-doc-formatter is a client-side skill plugin for DeepSeek Harness, maintained by feely0208. The source code is available on GitHub. The current package version is 0.1.2, licensed under MIT. The plugin itself does not contain any font files; it is only responsible for typesetting according to GB/T 9704-2012. Commercial fonts such as FangSong (仿宋) must be obtained and configured by the user separately.

Core Features

Layout Rules

The main layout items listed in the plugin README include:

Item Specification Value
Title FangSong (仿宋), Size 2 (22pt) Bold, Centered, Line spacing 33–36 pt
Level 1/2/3/4 Headings FangSong, Size 3 (16pt) Bold, Left indent 2 characters
Body Text FangSong, Size 4 (14pt), Fixed line spacing 28 pt, First line indent strictly 2 characters
Header Block (Optional) Serial number / Classification level / Urgency / Document number, FangSong Size 3
Signature & Date Spaced 3 lines below body text, Date in Arabic numerals with 4-character right indent
Page Number ”- 1 -“, Odd pages right-aligned with 1-char space, Even pages left-aligned with 1-char space
Margins Top 3.7 / Bottom 3.5 / Left 2.8 / Right 2.6 cm
Document Grid 22 lines per page, 28 characters per line

The output is designed to contain no AI traces: no watermarks, no generation markers, no author information, no version notes, and no annotations.

Output Self-Check

After generation, verify_output.py can be called to open the output file and verify margins, font sizes, line spacing, fonts, and page dimensions item-by-item. Exit code 0 indicates a pass, and 1 indicates non-compliance. The README states this can be used directly for CI or delivery gates.

Markdown Input Adaptation

md_adapter.py maps common Markdown structures to official document hierarchies (e.g., ## 一、Section → Level 1 Heading, ### 1.1 → Level 2 Heading, etc.). It also merges soft line breaks within the same paragraph to prevent orphaned punctuation caused by manual line wrapping in the source draft.

Font and Cross-Platform Detection

The plugin does not distribute fonts. You can specify font files or directories via environment variables:

# Method 1: Directly specify font files (Recommended)
export DSH_CN_FANGSONG=/path/to/FangSong.ttf
export DSH_CN_FANGSONG_BOLD=/path/to/FangSong_Bold.ttf   # Optional

# Method 2: Specify a directory, search by filename
export DSH_CN_FONT_DIR=~/my-fonts

You can also install fonts to system font directories (macOS ~/Library/Fonts/, Windows C:\Windows\Fonts\, Linux ~/.fonts/ or ~/.local/share/fonts/). If a font is not found, the PDF generation will fall back to the system Song font (SimSun) and print instructions to stderr. If only a regular FangSong is available without a bold version, titles will still use the FangSong family (possibly without bold), rather than switching to Song.

Font detection uses fontTools to read the font name table, avoiding reliance on fc-list, which may not exist on macOS.

Other Design Trade-offs

Typesetting, detection, and self-checking are all performed locally without network access. The document type (Notice, Report, etc.) does not influence typesetting branches; the specification is consistent, distinguished only by the body content.

Installation and Activation

The official installation command (from the README):

dsh plugin --profile web add @deepwhale-cn/dsh-cn-doc-formatter

If using other profiles, replace web with your <profile>:

dsh plugin --profile <profile> add @deepwhale-cn/dsh-cn-doc-formatter

Restart dsh after installation; the skill will become automatically available when the agent needs it. The package.json requires dsh version >=0.1.0-rc.6.

The typesetting scripts are written in Python; dependencies must be installed manually:

pip install python-docx reportlab fontTools pypdf
Library Purpose
python-docx Generate Word
reportlab Generate PDF
fontTools Detect local fonts
pypdf Self-check if PDF embeds target fonts

Typical Usage

Complete instructions are provided in the skill body; the core commands provided in the README are as follows. Replace <plugin_directory> with the local installation path and <directory> with the output directory.

Generate Word / PDF:

python "<plugin_directory>/scripts/docx_formatter.py" --output <directory> \
  --title "Title" --body "Body..." --sender "Issuing Authority" --date "September 25, 2026"
python "<plugin_directory>/scripts/pdf_formatter.py"  --output <directory> \
  --title "Title" --body "Body..." --sender "Issuing Authority" --date "September 25, 2026"

Output Self-Check (README suggests not skipping this):

python "<plugin_directory>/scripts/verify_output.py" --dir <output_directory>

Note: The --type notice parameter found in early documentation does not exist in the current scripts; adding it will result in an unrecognized arguments error. The document type is determined by the content; the script does not differentiate.

Use Cases and Notes

Suitable for developers or teams who need to produce Party and Government style official documents (Word / PDF / Plain Text) repeatably and verifiably within the DSH workflow, especially those wishing to use exit codes for automated checks.

Please note before use:

  1. Font Compliance: The MIT license applies to the typesetting software only and does not include fonts. You must ensure you have the rights to use fonts like FangSong in your documents.
  2. Python Environment: The above pip packages must be available on the local machine, consistent with the environment where the DSH process resides.
  3. Plugin Permissions: DSH plugins run with the permissions of the current dsh process. It is recommended to read the source code and license before installation to ensure compliance with your security and compliance requirements.
  4. Ecosystem Positioning: The DSH community plugin directory (such as the SkillHub entry) is an independent site with no official affiliation with DeepSeek / High-Flyer. This plugin follows the ecosystem initiative emphasizing combination priority, clear declaration, and compatibility priority; it does not override the internal implementation of other plugins.

Conclusion

dsh-cn-doc-formatter encapsulates the layout parameters of GB/T 9704-2012, Markdown adaptation, and output self-checking into a single DSH client plugin. It deliberately does not distribute fonts or perform online typesetting. If you want to generate official documents in the Harness that “can be verified against the standard,” you can install dependencies and the plugin according to the commands above, configure FangSong, and then follow the generation and verify_output.py workflow.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye