mcpField
D
document-format-skills

document-format-skills

github.com/kagurananaga文档处理235165 次安装9 周前更新
代码仓库

关于 document-format-skills

用于在命令行清理、诊断和排版中文 Word 文档的技能,也可从文本或 Markdown 生成 DOCX,并在 Windows 上转换 DOC/WPS 文件。

主要功能

  1. 01智能文档处理
  2. 02标点与空格清理
  3. 03预设和自定义排版
  4. 04文档诊断
  5. 05文本或 Markdown 转 DOCX

适用场景

  1. 01应用公文或学术排版
  2. 02清理标点并保留格式
  3. 03编辑前检查文档问题
  4. 04从 Markdown 创建排版后的 DOCX

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/kagurananaga/document-format-skills --skill document-format-skills

安装后在 Claude Code 中输入/document-format-skills确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
README.md
requirements-dev.txt
.gitignore
requirements.txt
README_CN.md
pytest.ini
scripts/
__init__.py
analyzer.py
converter.py
fix_spacing.py
from_text.py
process.py
fix_spacing_simple.py
punctuation.py
formatter.py
tests/
test_punctuation_and_text.py
test_formatter_regression.py

详细介绍

文档格式处理技能

使用这些脚本从命令行清理和格式化中文 Word 文档。常规操作优先使用 scripts/process.py,因为它无需图形界面即可运行,且其核心流程与桌面应用一致。

快速工作流

当用户希望一次性清理整个文档时,运行一次智能处理:

uv run --with python-docx python scripts/process.py smart input.docx output.docx --preset official

仅运行诊断:

uv run --with python-docx python scripts/process.py analyze input.docx
uv run --with python-docx python scripts/process.py analyze input.docx --json

仅运行标点和空格清理:

uv run --with python-docx python scripts/process.py punctuation input.docx output.docx --space-mode keep_en_boundary

仅运行格式设置:

uv run --with python-docx python scripts/process.py format input.docx output.docx --preset official

在 Windows 上,可通过 WPS 或 Microsoft Word COM 自动化处理 .doc 和 .wps 输入/输出文件:

uv run --with python-docx --with pywin32 python scripts/process.py smart input.wps output.wps

脚本

脚本用途
scripts/process.py一次性命令行工具,支持 smart、analyze、punctuation 和 format;可在 Windows 上处理 .doc/.wps 转换。
scripts/formatter.py应用格式预设、自定义 JSON 设置、页码、表格清理、修订标记和 macOS 字体回退。
scripts/punctuation.py在保留文本片段格式的同时修正标点;支持空格处理策略。
scripts/from_text.py根据 .txt 或 Markdown 创建 DOCX,然后可选择运行智能格式处理。
scripts/analyzer.py底层诊断脚本。
scripts/converter.py仅限 Windows 的 .doc/.wps 转换辅助工具。

格式选项

内置预设:

  • official:GB/T 9704-2012 公文格式。
  • academic:学术论文格式。
  • legal:法律文书格式。
  • custom:在可用时读取当前桌面端自定义预设。

常用标志:

--custom-settings path.json
--revision
--deep-clean
--smart-table-align
--no-page-number
--page-number-style dash|plain|page_text|page_total
--page-number-position outside|left|center|right
--page-number-offset-mm 7
--no-bold-serial

--custom-settings 接受桌面端 schema v2 配置文件、结构为 {"preset": {...}} 的导出预设文件,或普通预设/覆盖项 JSON。对于非 custom 预设,JSON 内容会与所选预设合并。

标点和空格

标点清理会保护 URL、电子邮件地址、Windows 路径、9:30 这样的时间值,以及 ISO 9001:2015 这样的标准编号。它会修正常见括号、冒号、分号、问号/感叹号、中文逗号/句号上下文、省略号、破折号和成对引号。

空格模式:

  • remove_all:删除半角和全角空格。
  • keep_en_boundary:删除中文与中文之间的空格,但保留中文与英文/数字之间恰好一个空格。
  • keep_all:保留空格不变。

将文本或 Markdown 转换为 DOCX

根据文本生成并格式化文档:

uv run --with python-docx python scripts/from_text.py input.md output.docx --title "工作方案"

Markdown 模式可识别标题、粗体文本、有序/无序列表、引用和围栏代码块。# 会转换为主标题,## 会转换为“一、”,### 会转换为“(一)”,更深层级的标题会转换为编号的下级标题。

使用 --no-process 仅创建原始 DOCX。

实现说明

  • 处理 .docx 仅需 python-docx。
  • 转换 .doc/.wps 需要 Windows、WPS Office 或 Microsoft Word,以及 pywin32。
  • 页码处理会避免覆盖非页码页脚内容,并可按需替换现有的页码页脚。
  • 默认表格格式会保留原始对齐方式;使用 --smart-table-align 可让数字/右对齐内容和短文本/居中内容采用相应对齐方式。
  • macOS 字体处理会保留已安装的官方字体;只有在检测确认原字体缺失时,才会回退到兼容的系统字体。

评论

支持 Markdown