SuperAPI AI Directory

doc-format

Office & productivity

View repository

Updated 10-15 20:30

About this skill

doc-format — Official document formatting tool

Use scripts/wfp_cli.py to format documents into standard .docxaccording to official document formatting rules. Original files are not modified in place; Word/WPS-type documents are first copied or converted to temporary copies before formatting is performed.

Core capabilities

  • Supports .docx、.doc、.wps、.txt、.md。
  • Supports single-file, multi-file, repeated -i, positional argument input, and one or more directories; directory input is recursively scanned by default, and the output directory preserves the original structure.
  • Automatically recognizes titles, subtitles, four-level headings, in-paragraph body text under second-level headings, figure/table captions, and attachment markers.
  • Line spacing supports the default point-value mode and Word multiple mode; paragraph indentation supports both centimeter and character units.
  • Optional forced bolding of titles/first-level headings/second-level headings, automatic table content adjustment, separate fonts for numbers and letters, and symbol standardization.
  • TXT/MD supports three blank-line modes: do not change any blank lines; delete single blank lines while reducing multiple blank lines to 1 blank line; keep single blank lines while reducing multiple blank lines to 1 blank line.
  • Handwritten numeric numbering in TXT/MD (such as 1.、1.2.3) is preserved according to the source document and is not automatically incremented or reordered.
  • Supports automatically reading the current directory wfp_config.json, specifying a JSON configuration file, inline JSON,--set key=value and convenience switches to override configuration.

Pre-use checks

  1. Confirm the script path: the script is located in this Skill directory under scripts/wfp_cli.py. If the current working directory is not the Skill directory, use the directory containing SKILL.md to derive the script's absolute path, or first cd to the Skill directory.
  2. Check the input: if the user has not provided a file or directory, first ask for the input path; inform them that .docx/.doc/.wps/.txt/.mdis supported, and directories are processed recursively by default.
  3. Check the configuration: the CLI automatically reads wfp_config.jsonin the current working directory. If the user specifies --config or explicitly provides a configuration file, use the user-specified configuration; otherwise explain that the current directory configuration or built-in default configuration will be used.
  4. Check conversion conditions: on Windows, when processing .doc/.wps , WPS/Word and pywin32 are preferred; on macOS/Kylin/Linux or when COM is unavailable, the CLI will try to call LibreOffice soffice to convert to .docx. If LibreOffice is not installed, legacy-format files will be recorded as skipped, and processing will continue for .docx/.txt/.md; if the user must process legacy formats, then prompt them to install LibreOffice, use --soffice to specify the path, or first save as .docx。

Common commands

# 单文件
python scripts/wfp_cli.py format -i report.docx

# 指定输出文件
python scripts/wfp_cli.py format -i report.docx -o report_final.docx

# 目录批量处理,默认递归并保留目录结构
python scripts/wfp_cli.py format -i ./documents -o ./documents_formatted

# 多文件
python scripts/wfp_cli.py format -i a.docx -i b.txt c.md -o ./formatted_output

# 目录批量处理,只处理当前目录
python scripts/wfp_cli.py format -i ./documents -o ./documents_formatted --no-recursive

# 使用自定义配置
python scripts/wfp_cli.py format -i input.docx --config ./wfp_config.json

# macOS/Kylin/Linux 或 COM 不可用时,可指定 soffice 处理 .doc/.wps 转换
python scripts/wfp_cli.py format -i old.doc --soffice /Applications/LibreOffice.app/Contents/MacOS/soffice

# 临时覆盖配置
python scripts/wfp_cli.py format -i input.docx --set body_size=12 --enable-table-formatting

# 正文行距改为 1.5 倍
python scripts/wfp_cli.py format -i input.docx --set line_spacing_unit=multiple --set line_spacing_multiple=1.5

# 段落缩进改为字符单位
python scripts/wfp_cli.py format -i input.docx --set paragraph_indent_unit=chars --set left_indent_chars=0 --set right_indent_chars=0 --set first_line_indent_chars=2

# 内联 JSON 覆盖配置
python scripts/wfp_cli.py format -i input.docx --config-json "{\"force_a4\": true, \"line_spacing\": 30}"

# TXT/MD 文件转换
python scripts/wfp_cli.py format -i draft.md 

# 查看默认配置
python scripts/wfp_cli.py show-config

# 保存默认配置模板
python scripts/wfp_cli.py save-config

# 显示 LibreOffice 安装提示
python scripts/wfp_cli.py install-help

# 运行内置单元测试
python scripts/wfp_cli.py test

Configuration handling workflow

When the user requests adjustments to configuration such as fonts, font sizes, margins, line spacing, tables, and symbols:

  1. Run show-config to learn the current configuration sources and values.
  2. Map the user's natural language requirements to configuration fields.
  3. Use save-config --set ... or convenience switches to save to the current directory wfp_config.json, or save to a user-specified path.
  4. Then run format to process the document.

When the user only requests a one-time temporary adjustment, you can use --config-json or --set to directly run format。

Line spacing fields use points by default: Body line_spacing, Title title_line_spacing, Subtitle subtitle_line_spacing, Table table_line_spacing. For multiple line spacing, set the corresponding *_line_spacing_unit to multiple, and set the corresponding *_line_spacing_multiple; the multiple defaults to 1.0。

Paragraph indentation uses centimeters by default: whenparagraph_indent_unit=cm , read left_indent_cm/right_indent_cm. For indentation by characters, set it to paragraph_indent_unit=chars, and use left_indent_chars/right_indent_chars/first_line_indent_chars。

Output behavior

  • The absolute path of the successfully generated .docx is written to stdout.
  • Detailed logs are written to stderr only when -v/--verbose is used.
  • Exit code 0 means no failures; on macOS/Kylin/Linux, .doc/.wps skips caused by LibreOffice not being installed are written to stderr, but will not prevent other files from being processed. Not 0 means no processable files were found or at least one file failed.
  • During directory processing, failure of a single file will not prevent subsequent files from continuing to be processed.
  • When processing fails, the final reply should state the failed files and the reason for the error.

Required reading after completion

After completing formatting each time, always remind the user to open the output file to spot-check titles, subtitles, heading levels, attachments, figure/table captions, page numbers, and tables.

If .doc/.wps or Word/WPS-type documents were processed, check automatic numbering especially carefully. When it cannot be confirmed that automatic numbering was converted successfully, the numbering text, paragraph indentation, font, and font size may not have been formatted properly; if the numbering cannot be selected separately, it may still be Word/WPS automatic numbering, and if necessary, convert it to manually written text numbering and then run the tool again.

Automatic table content adjustment and symbol standardization are enhancement items that more easily affect the layout; for important files, it is recommended to check the effect on a copy.

Reference Files

  • When you need the complete command format, parameter descriptions, or more command examples, read references/cli-reference.md。
  • When you need to map user configuration requirements to fields or view the font size comparison, read references/config-reference.md。
  • When you need to explain the default typesetting rules, title recognition, page paragraphs, TXT/MD, table, and attachment rules, read references/formatting-rules.md。

Agent Usage Guidelines

  1. Do not run format。
  2. directly when there is no input. When the user asks about configuration, run show-config, and do not list configurations from memory.
  3. When the user proposes configuration changes, save the configuration first, then use that configuration to process documents.
  4. When the user only requests a one-time temporary adjustment, you may use --config-json or --set to run format。
  5. Directory input is recursive by default; add --no-recursive。
  6. only when the user explicitly requests “process only the current directory”. On macOS/Kylin/Linux or in environments where COM is unavailable, .doc/.wps can be processed only if LibreOffice soffice is available; when LibreOffice is unavailable, old formats will be skipped, and do not promise that automatic numbering can be converted.
  7. After processing ends, you must remind the user to check the conversion effect of headings and paragraphs where automatic numbering is located, and remind the user that if automatic table content adjustment, separate fonts for numbers and letters, and symbol standardization are enabled, they should focus on spot-checking the layout.