yjh051108/mmkit/docx-template-map
Claude Code and agent skill by yjh051108/mmkit
- community
Checking that the SKILL.md file is still in the repository.
分析用户上传的 .docx/.dotx 模板,识别占位段位置,生成 _template_map.json,并通过「试填→自检→修复」循环验证映射正确性。Use when user says \"分析 word 模板\", \"识别模板占位\", \"docx-template-map\".
Install
npx vskill@latest install yjh051108/mmkit/docx-template-mapSKILL.md
DOCX 模板占位映射器(带试填自检循环)
把用户上传的 .docx / .dotx 模板转换成 docx_template_fill.py 能用的「占位映射 JSON」,并通过「生成→试填→分析→修复」循环确保映射正确,让 docx-format-check 用上的 map 是已验证的。
输入
- TEMPLATE_PATH:从
$ARGUMENTS传入,或自动检测user_data/下首个.docx/.dotx模板 - WORKSPACE:当前工作区(含
paper/main.md或COURSE_PAPER.md等已生成的 markdown)
输出
_template_map.json(必须,工作区根目录)— 已验证可用_template_structure.txt(中间产物,模板段落清单)_template_test_filled.docx(中间产物,试填验证用,最后会保留以便检查)_template_check_report.md(中间产物,记录每轮自检发现的问题)
核心原则
- 不要凭推理就交付 — 必须真实跑过
fill_template,并验证结果 docx 是否含残留占位/示例/说明文字 - idx 是硬约束 — 一旦 anchor idx 错位,整个填充失败,所以每轮都要打印实际段落对照
- 删除冲突要避免 —
delete_paragraph_indices不能包含任何*_anchor_para_idx的值,否则 anchor 段被删,对应 section 整段消失 - 最多 3 轮自检 — 第 3 轮还失败就如实记录,让后续 docx-format-check 退到正则启发式
⛔⛔⛔ 完成铁律(最高优先级)
本步骤必须产出 `_template_map.json`(合法 JSON,含 anchor_para_idx 字段)+ `_template_check_report.md`(自检报告)。
⛔ 结束前必跑产出验证:
工作流程
Step 1:定位模板 + 源 markdown
Step 2:dump 模板结构
⛔ 工具文件:复制到 _utils/ 目录(docx_template_analyze.py / docx_template_fill.py / docx_export.py)。统一用 python3 _utils/<tool>.py 调用。
_template_structure.txt 形如:
Step 3:用 Read 工具读 _template_structure.txt,按语义判断占位
按以下顺序识别每个 anchor:
| anchor | 识别特征 | |
|---|---|---|
title_anchor_para_idx | 含「标题」/「题目」/「Title」+「此处」/「填」/「换成」/「__」 | |
abstract_anchor_para_idx | 段是「摘要」/「Abstract」/「[摘 要]」/「摘 要」 | |
body_anchor_para_idx | 段是「正文内容(...)」/「正文」/「绪论」/「Body」 | |
references_anchor_para_idx | 段是「参考文献」/「References」/「Bibliography」 | |
appendix_anchor_para_idx | 段是「附录」/「Appendix」/「Annex」(可选) |
收集 delete_paragraph_indices:
- 起头
(注:(说明:(示例:的提示段 - 含「请删除」/「看完后删除」/「示例段落」
- 含「[编号] 作者」/「书籍的表述方式」/「参考文献著录格式」
- 模板示例正文(如果模板含完整示例论文):示例的章节标题、示例的代码、示例的图表
- 格式说明区(如「装订格式」「撰写格式要求」等独立章节及其下属段落)
- 多余空段:摘要 anchor 之后到正文 anchor 之间的空段(fill 会替换)
⛔ 关键约束(必须自检):
delete_paragraph_indices不能含任何 anchor idx- 例如
body_anchor_para_idx=36,那 36 不能在delete_paragraph_indices里
Step 4:写出 _template_map.json(v1)
写完后立即用 Bash 自检 anchor 与 delete 列表无冲突:
Step 5:试填一次
重点关注 log 中的:
Title replaced via template_map: '...'→ 标题命中Abstract (N paras) + keywords inserted→ 摘要命中Body (N elements) inserted (anchor_mode=delete)→ 正文命中References (N items) inserted→ 参考文献命中Appendix (N elements) inserted→ 附录命中(可选)
如果某条 log 缺失,说明对应 anchor 错位 / 已被删除。需要修 map:
- 缺
Body→body_anchor_para_idx不对,重新核对实际正文起点段 - 缺
Abstract→abstract_anchor_para_idx不对 - log 含
body_p anchor: ... has_parent=False→ anchor 被某个delete_paragraph_indices误删
Step 6:分析试填后的 docx,定量检查残留
读 _template_filled_structure.txt,逐项检查:
| 检查项 | 命中(fail)即为 bug | |
|---|---|---|
| 占位符未替换 | 含「(此处换成」「请输入」「____」「[摘 要]」「<TITLE>」 | |
| 模板示例正文残留 | 含模板原本的示例标题("职场不败玫瑰" / "1.1文献综述" / "2.1创建文档" 等) | |
| 格式说明残留 | 含「[编号] 作者」「装订格式」「撰写格式要求」「参考文献著录格式说明」 | |
| 应有内容缺失 | 检查源 md 的章节标题在 filled docx 中是否出现 | |
| 封面字段保留 | 检查模板原有的封面字段(学院 / 学号 / 学校 / 参赛编号 等)仍在 |
Step 7:如有问题,调整 _template_map.json 重试
把 Step 6 的发现写到 _template_check_report.md,然后用 Edit 工具修 map。常见修复:
| 现象 | 修复 | |
|---|---|---|
| Body 章节缺失 | 核对 _template_structure.txt 中正文起点段的真实 idx,更新 body_anchor_para_idx | |
| 示例正文残留(如"绪论 / 1.1文献综述") | 把它们的 idx 加到 delete_paragraph_indices | |
| 格式说明残留(如"装订格式" 整章) | 找到该段及其后所有相关段,全部加到 delete_paragraph_indices | |
| 摘要被删("Abstract 0 paras") | abstract_anchor_para_idx 不对,或 anchor 被 delete_paragraph_indices 误删 | |
| 封面字段消失 | delete_paragraph_indices 误把封面段(学院/学号等)也删了,移除 |
修完 map 后回到 Step 4 的合法性自检 → Step 5 重试。最多循环 3 次,第 3 次仍失败也保存当前 map 让 docx-format-check 自己处理(fill_template 内部有 fallback)。
Step 8:清理 + 输出报告
试填验证通过后,写最终报告:
保留 _template_test_filled.docx(用户可下载查看预览),让后续 docx-format-check 步骤跑正式版。
注意事项
- 不要硬编码模板字段名 — 全部按段落内容语义判断
- anchor 找不到的占位 → null — 让 fill 退到正则兜底
- 多语言模板(中英对照) — 取占字符多的那个作为
language - 示例正文要彻底清理 — 用户绝不希望看到模板自带的"职场不败玫瑰"之类示例文字
- 不要扩大删除范围 — 只删确认是说明 / 示例的段,宁可漏删也不要误删用户上传内容
- 最多 3 轮 — 防止陷入死循环;第 3 轮仍失败时保存当前 map,让 fill_template 退到正则
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/docx-template-map/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/yjh051108/mmkit/docx-template-map)