{"id":"9428207d-29be-427d-88e7-aab6e5cb0ca5","entityType":"agent","slug":"clawhub-edwardwason-gongwen-formatter","name":"Gongwen Formatter 公文格式转换","canonicalUrl":"https://www.xpersona.co/agent/clawhub-edwardwason-gongwen-formatter","canonicalPath":"/agent/clawhub-edwardwason-gongwen-formatter","generatedAt":"2026-10-10T02:30:32.162Z","source":"CLAWHUB","claimStatus":"UNCLAIMED","verificationTier":"NONE","summary":{"evidence":{"source":"editorial-content","verified":true,"confidence":"high","updatedAt":"2026-10-09T17:54:34.903Z","emptyReason":null},"description":"公文格式转换 — 将 Markdown 转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文件。可选能力：远程图片下载（仅 http/https/data:image，可通过 download_images=False 关闭）。Do NOT：不做文体识别、不添加红头/版记/落款、不做内容审核。 Skill: Gongwen Formatter 公文格式转换 Owner: edwardwason Summary: 公文格式转换 — 将 Markdown 转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文件。可选能力：远程图片下载（仅 http/https/data:image，可通过 download_images=False 关闭）。Do NOT：不做文体识别、不添加红头/版记/落款、不做内容审核。 Tags: chinese:1.1.4, document:1.1.4, formatting:1.1.4, gb9704:1.1.4, latest:1.1.9, markdown:1.1.4, security:1.1.4, word:1.1.4 Version history: v1.1.9 | 2026-09-22T09:33:58.779Z | user v1.1.9 displayNam","descriptionLabel":"Technical summary","evidenceSummary":"Capability contract not published. No trust telemetry is available yet. 2.2K downloads reported by the source. Last updated 10/9/2026.","installCommand":"clawhub skill install s177q4wcvafq6fzfkhk2g3cwth83y01d:gongwen-formatter","sourceUrl":"https://clawhub.ai/edwardwason/gongwen-formatter","homepage":"https://clawhub.ai/edwardwason/skills/gongwen-formatter","primaryLinks":[{"label":"View on ClawHub","url":"https://clawhub.ai/edwardwason/gongwen-formatter","kind":"source"},{"label":"Homepage","url":"https://clawhub.ai/edwardwason/skills/gongwen-formatter","kind":"homepage"}],"safetyScore":84,"overallRank":62,"popularityScore":67,"trustScore":null,"claimedByName":null,"isOwner":false,"seoDescription":"公文格式转换 — 将 Markdown 转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文件。可选能力：远程图片下载（仅 http/https/data:image，可通过 download_images=False 关闭）。Do NOT：不做文体识别、不添加红头/版记/落款、不做内容审核。 S"},"coverage":{"evidence":{"source":"public-profile","verified":false,"confidence":"medium","updatedAt":"2026-10-09T17:54:34.903Z","emptyReason":null},"protocols":[{"protocol":"OPENCLEW","label":"OpenClaw","status":"self-declared","notes":"Declared in the public agent profile."}],"capabilities":[],"verifiedCount":0,"selfDeclaredCount":1,"capabilityMatrix":{"rows":[{"key":"OPENCLEW","type":"protocol","support":"unknown","confidenceSource":"profile","notes":"Listed on profile"}],"flattenedTokens":"protocol:OPENCLEW|unknown|profile"}},"adoption":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"medium","updatedAt":"2026-10-09T17:54:34.903Z","emptyReason":null},"stars":null,"forks":null,"downloads":2172,"packageName":null,"latestVersion":"1.1.9","tractionLabel":"2.2K downloads"},"release":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"medium","updatedAt":"2026-10-09T17:54:34.902Z","emptyReason":null},"lastUpdatedAt":"2026-10-09T17:54:34.903Z","lastCrawledAt":"2026-10-09T17:54:34.902Z","lastIndexedAt":null,"nextCrawlAt":"2026-10-10T17:54:34.902Z","lastVerifiedAt":null,"highlights":[{"version":"1.1.9","createdAt":"2026-09-22T09:33:58.779Z","changelog":"v1.1.9 displayName 双语化：Gongwen Formatter 公文格式转换","fileCount":11,"zipByteSize":29176},{"version":"1.1.4","createdAt":"2026-08-23T09:48:58.369Z","changelog":"v1.1.4 format fix: bold sentences and h3 headings render as KaiTi_GB2312 bold, aligning with GB/T 9704 gongwen standard","fileCount":11,"zipByteSize":25453},{"version":"1.1.3","createdAt":"2026-07-15T00:43:12.652Z","changelog":"v1.1.3 fix residual >= to ~= in README/skill.md/skill.json, add allowed-tools frontmatter for MCP Least Privilege declaration","fileCount":11,"zipByteSize":24711},{"version":"1.1.2","createdAt":"2026-07-14T12:12:58.185Z","changelog":"v1.1.2 security upgrade responding to SkillSpector audit: URL scheme whitelist to prevent SSRF, download_images parameter to disable network, permission declaration table, README user warnings, ~= compatible version pinning","fileCount":11,"zipByteSize":21704},{"version":"1.1.1","createdAt":"2026-07-13T13:29:57.188Z","changelog":"v1.1.1: add trigger words (公文格式转换/转换公文格式), markdown-it-py parser, smart # title, table/image/link/nested-list support","fileCount":10,"zipByteSize":19462},{"version":"1.1.0","createdAt":"2026-06-08T12:54:19.780Z","changelog":"v1.1.0: markdown-it-py parser, smart # title, table/image/link/nested-list support","fileCount":10,"zipByteSize":19534}]},"execution":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No published capability contract is available yet."},"installCommand":"clawhub skill install s177q4wcvafq6fzfkhk2g3cwth83y01d:gongwen-formatter","setupComplexity":"low","setupSteps":["Setup complexity is classified as HIGH. You must provision dedicated cloud infrastructure or an isolated VM. Do not run this directly on your local workstation.","Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data."],"contract":{"contractStatus":"missing","authModes":[],"requires":[],"forbidden":[],"supportsMcp":false,"supportsA2a":false,"supportsStreaming":false,"inputSchemaRef":null,"outputSchemaRef":null,"dataRegion":null,"contractUpdatedAt":null,"sourceUpdatedAt":null,"freshnessSeconds":null},"invocationGuide":{"preferredApi":{"snapshotUrl":"https://www.xpersona.co/api/v1/agents/clawhub-edwardwason-gongwen-formatter/snapshot","contractUrl":"https://www.xpersona.co/api/v1/agents/clawhub-edwardwason-gongwen-formatter/contract","trustUrl":"https://www.xpersona.co/api/v1/agents/clawhub-edwardwason-gongwen-formatter/trust"},"curlExamples":["curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-edwardwason-gongwen-formatter/snapshot\"","curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-edwardwason-gongwen-formatter/contract\"","curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-edwardwason-gongwen-formatter/trust\""],"jsonRequestTemplate":{"query":"summarize this repo","constraints":{"maxLatencyMs":2000,"protocolPreference":["OPENCLEW"]}},"jsonResponseTemplate":{"ok":true,"result":{"summary":"...","confidence":0.9},"meta":{"source":"CLAWHUB","generatedAt":"2026-10-10T02:30:32.160Z"}},"retryPolicy":{"maxAttempts":3,"backoffMs":[500,1500,3500],"retryableConditions":["HTTP_429","HTTP_503","NETWORK_TIMEOUT"]}},"endpoints":{"dossierUrl":"https://www.xpersona.co/api/v1/agents/clawhub-edwardwason-gongwen-formatter/dossier","snapshotUrl":"https://www.xpersona.co/api/v1/agents/clawhub-edwardwason-gongwen-formatter/snapshot","contractUrl":"https://www.xpersona.co/api/v1/agents/clawhub-edwardwason-gongwen-formatter/contract","trustUrl":"https://www.xpersona.co/api/v1/agents/clawhub-edwardwason-gongwen-formatter/trust"}},"reliability":{"evidence":{"source":"runtime-metrics","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No trust, reliability, or runtime telemetry is available."},"trust":{"status":"unavailable","handshakeStatus":"UNKNOWN","verificationFreshnessHours":null,"reputationScore":null,"p95LatencyMs":null,"successRate30d":null,"fallbackRate":null,"attempts30d":null,"trustUpdatedAt":null,"trustConfidence":"unknown","sourceUpdatedAt":null,"freshnessSeconds":null},"decisionGuardrails":{"doNotUseIf":["Contract metadata is missing or unavailable for deterministic execution."],"safeUseWhen":[],"riskFlags":["missing_or_unavailable_contract","trust_data_unavailable","schema_references_missing"],"operationalConfidence":"low"},"executionMetrics":{"observedLatencyMsP50":null,"observedLatencyMsP95":null,"estimatedCostUsd":null,"uptime30d":null,"rateLimitRpm":null,"rateLimitBurst":null,"lastVerifiedAt":null,"verificationSource":null},"runtimeMetrics":{"successRate":null,"avgLatencyMs":null,"avgCostUsd":null,"hallucinationRate":null,"retryRate":null,"disputeRate":null,"p50Latency":null,"p95Latency":null,"lastUpdated":null}},"benchmarks":{"evidence":{"source":"no-benchmark-data","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No benchmark suites or observed failure patterns are available."},"suites":[],"failurePatterns":[]},"artifacts":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"high","updatedAt":"2026-10-09T17:54:34.903Z","emptyReason":null},"readme":"Skill: Gongwen Formatter 公文格式转换\n\nOwner: edwardwason\n\nSummary: 公文格式转换 — 将 Markdown 转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文件。可选能力：远程图片下载（仅 http/https/data:image，可通过 download_images=False 关闭）。Do NOT：不做文体识别、不添加红头/版记/落款、不做内容审核。\n\nTags: chinese:1.1.4, document:1.1.4, formatting:1.1.4, gb9704:1.1.4, latest:1.1.9, markdown:1.1.4, security:1.1.4, word:1.1.4\n\nVersion history:\n\nv1.1.9 | 2026-09-22T09:33:58.779Z | user\n\nv1.1.9 displayName 双语化：Gongwen Formatter 公文格式转换\n\nv1.1.4 | 2026-08-23T09:48:58.369Z | user\n\nv1.1.4 format fix: bold sentences and h3 headings render as KaiTi_GB2312 bold, aligning with GB/T 9704 gongwen standard\n\nv1.1.3 | 2026-07-15T00:43:12.652Z | user\n\nv1.1.3 fix residual >= to ~= in README/skill.md/skill.json, add allowed-tools frontmatter for MCP Least Privilege declaration\n\nv1.1.2 | 2026-07-14T12:12:58.185Z | user\n\nv1.1.2 security upgrade responding to SkillSpector audit: URL scheme whitelist to prevent SSRF, download_images parameter to disable network, permission declaration table, README user warnings, ~= compatible version pinning\n\nv1.1.1 | 2026-07-13T13:29:57.188Z | user\n\nv1.1.1: add trigger words (公文格式转换/转换公文格式), markdown-it-py parser, smart # title, table/image/link/nested-list support\n\nv1.1.0 | 2026-06-08T12:54:19.780Z | user\n\nv1.1.0: markdown-it-py parser, smart # title, table/image/link/nested-list support\n\nArchive index:\n\nArchive v1.1.9: 11 files, 29176 bytes\n\nFiles: CHANGELOG.md (7943b), README_CN.md (8512b), README.md (7895b), requirements.txt (41b), setup.py (1117b), skill-card.md (2086b), skill.json (3982b), skill.md (11073b), src/__init__.py (324b), src/md2docx.py (31878b), _meta.json (136b)\n\nFile v1.1.9:skill.md\n\n---\nslug: gongwen-formatter\nname: gongwen-formatter\ndisplayName: Gongwen Formatter 公文格式转换\nname_cn: 公文格式转换\nversion: 1.1.9\nauthor: EdwardWason\nlicense: MIT\nhomepage: https://github.com/EdwardWason/official-doc\ndescription: 公文格式转换 — 将 Markdown 转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文件。可选能力：远程图片下载（仅 http/https/data:image，可通过 download_images=False 关闭）。Do NOT：不做文体识别、不添加红头/版记/落款、不做内容审核。\nsummary: 将 Markdown 转换为符合 GB/T 9704-2012 标准的党政机关公文格式 Word 文件。\nallowed-tools:\n  - filesystem (write .docx output)\n  - net.http (GET image download, http/https only, toggleable via download_images=False)\ntriggers:\n  - 公文格式转换\n  - 转换公文格式\n---\n\n# 📄 official-doc - 公文格式转换\n\n## 技能信息\n\n### 基本信息\n| 属性 | 说明 |\n|------|------|\n| **名称** | official-doc |\n| **中文名称** | 公文格式转换 |\n| **版本** | 1.1.9 |\n| **作者** | EdwardWason |\n| **许可证** | MIT |\n| **主页** | https://github.com/EdwardWason/official-doc |\n\n### 触发词\n- **公文格式转换**\n- **转换公文格式**\n\n### 功能描述\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\n\n### 适用场景\n- AI Agent 生成公文格式报告\n- 定时任务自动生成工作简报、周报、月报\n- Markdown 文档批量转换为标准公文格式\n- 行业研报格式标准化输出\n\n### Do NOT（超出范围）\n- ❌ **不做文体识别**：不区分通知/通报/报告/请示等公文文种，统一按 Markdown 结构转换\n- ❌ **不添加公文装饰要素**：不生成红头、版记、落款、签发人、密级标识等\n- ❌ **不做内容审核**：不审查内容合规性、不校验公文要素完整性\n- ❌ **不做双向转换**：仅支持 Markdown → Word 单向，不支持 Word → Markdown 反向\n- ❌ **不读取本地敏感文件**：不读取 memory/profile/credentials 等任何用户数据\n\n### v1.1.0 新增功能\n- 引入 markdown-it-py 解析器，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- 加粗文本自动转为楷体加粗，斜体文本自动转为楷体\n\n### v1.1.2 安全升级（响应 ClawHub SkillSpector 审计）\n- `download_image()` 增加 URL scheme 白名单（仅 `http://`/`https://`/`data:image`），防止 SSRF\n- `md_to_docx()` 新增 `download_images=True` 参数，受限网络环境可设为 `False` 完全关闭网络请求\n- `_handle_standalone_image()` 关闭图片下载时以 `[图片: alt]` 文字占位替代\n- `requirements.txt` 改用 `~=` 兼容版本锁定（python-docx~=1.1.0、markdown-it-py~=3.0.0）\n- README 中英文版增加 \"图片下载网络请求说明 / Network Access Disclosure\" 用户警告段落\n\n### v1.1.3 修复（响应 v1.1.2 后 SkillSpector 二次审计）\n- 修复 v1.1.2 漏改：README/skill.md/skill.json 中残留的 `>=` 全部改为 `~=`（依赖版本一致性）\n- frontmatter 增加 `allowed-tools` 字段，声明 filesystem（写 .docx）和 net.http（图片下载，可关闭）两项权限\n- 7 项 findings 中：2 项真实漏改（本次修复）、3 项 stale（已修复但被重复扫描，本次通过 allowed-tools 增强声明）、2 项过度修改（保留现有设计，不采纳）\n\n### v1.1.4 格式修复（对齐公文规范）\n- **加粗句（`**text**`）修复**：由\"黑体不加粗\"改为\"楷体_GB2312 加粗\"——符合公文段首\"一是/二是\"句式标准格式\n- **三级标题（`###`）修复**：由\"楷体不加粗\"改为\"楷体_GB2312 加粗\"——符合 GB/T 9704 二级标题（（一））楷体加粗规范\n- 黑体标题（`#`/`##`）、正文仿宋、斜体楷体等保持不变\n\n### v1.1.8 格式增强（间隔号序号规范化为公文标准序号）\n- **「一 · 源头」→「一、源头」**：识别到间隔号体例时自动改写为公文标准序号，\n  `##` →「一、」（阿拉伯数字自动转中文数字），`###` →「（五）」\n- 结构性标题（「结语 ·」「附一 ·」）保持原样不套序号\n\n### v1.1.7 格式修复（序号去重扩展·间隔号体例）\n- **间隔号序号去重**：新增「一 · 源头」「1 · 标题」间隔号体例识别，\n  以及「结语 ·」「附一 ·」结构性标题识别，避免自动编号与原文序号重复\n- 涌现写作交付成稿常用间隔号体例，此前会产生「二、一·源头」这类重复序号\n\n### v1.1.6 格式修复（段落按源码行拆分）\n- **连续非空行不再合并**：连续的非空行（软换行 `softbreak`）还原为独立段落，\n  解决\"甲方：/住所：/法定代表人：\"这类一行一要素文本被挤在同一段的问题\n- 拆分后的每段独立应用两端对齐 + 固定行距 + 首行缩进 2 字（640 twips）\n- 本版一并纳入此前仅写入代码 docstring 的 v1.1.5 标题层级重定义（`#` 大标题 / `##` 一级标题 / `###` 楷体加粗 / `####` 仿宋加粗 + 序号去重）\n\n---\n\n## 权限声明\n\n本技能执行过程中涉及的系统能力（用户须知）：\n\n| 能力类别 | 是否使用 | 说明 |\n|---------|---------|------|\n| **网络访问** | ✅ 仅 http/https 图片下载 | 默认开启；可通过 `download_images=False` 关闭；URL scheme 白名单防止 SSRF |\n| **文件读写** | ✅ 仅写入输出 .docx 和临时图片缓存 | 临时图片下载后立即 `os.unlink` 删除；不读取用户其他文件 |\n| **环境变量** | ❌ 不读取 | 不依赖任何环境变量，无凭证收集 |\n| **subprocess 调用** | ❌ 不调用 | 纯 Python 实现，不执行 shell 命令 |\n| **外部 API 调用** | ❌ 不调用 | 不向任何外部 API 推送数据 |\n\n**最小权限原则**：本技能仅做 Markdown→Word 格式转换，不涉及任何外部数据上传、凭证收集或子进程调用。\n\n---\n\n## 输入参数\n\n| 参数名 | 类型 | 必填 | 说明 |\n|--------|------|------|------|\n| `md_content` | string | ✅ | Markdown 格式的文本内容 |\n| `output_path` | string | ✅ | 输出 Word 文件路径（.docx） |\n| `download_images` | bool | ❌ | 是否下载远程图片并嵌入 Word，默认 `True`；受限网络环境设为 `False` 跳过网络请求 |\n\n---\n\n## 输出结果\n\n| 字段 | 类型 | 说明 |\n|------|------|------|\n| `success` | boolean | 转换是否成功 |\n| `output_path` | string | 输出文件路径 |\n\n---\n\n## 使用示例\n\n### 基本使用\n```python\nfrom official_doc import md_to_docx\n\nmd_content = \"\"\"# 工作简报\n\n## 一、上周工作总结\n\n本周完成了系统升级任务。\n\n### （一）主要工作\n1. 服务器部署\n2. 数据迁移\n3. 测试验证\n\n### （二）下周计划\n继续推进优化工作。\n\"\"\"\n\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\nprint(\"转换成功\" if success else \"转换失败\")\n```\n\n### 含表格和图片\n```python\nfrom official_doc import md_to_docx\n\nmd_content = \"\"\"# 项目进度表\n\n## 工作进展\n\n| 项目名称 | 负责人 | 进度 | 备注 |\n|----------|--------|------|------|\n| A项目 | 张三 | 80% | 正常 |\n| B项目 | 李四 | 60% | 需加速 |\n\n![架构图](https://example.com/arch.png)\n\n详细说明请参考[官方文档](https://example.com)。\n\"\"\"\n\nmd_to_docx(md_content, \"进度表_公文格式.docx\")\n```\n\n### AI Agent 集成\n```python\nfrom official_doc import md_to_docx\n\nclass OfficialDocSkill:\n    name = \"official-doc\"\n    description = \"公文格式转换 - 将 Markdown 转为党政机关公文格式\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output_公文格式.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"公文格式转换完成\" if success else \"转换失败\"\n        }\n```\n\n### 定时任务\n```python\nimport schedule\nimport time\nfrom official_doc import md_to_docx\n\ndef generate_report():\n    content = generate_report_content()\n    today = time.strftime(\"%Y-%m-%d\")\n    md_to_docx(content, f\"工作简报_{today}_公文格式.docx\")\n\nschedule.every().monday.at(\"09:00\").do(generate_report)\n```\n\n---\n\n## 格式规范\n\n### 页面设置\n| 设置项 | 规范值 |\n|--------|--------|\n| 上边距 | 3.7cm |\n| 下边距 | 3.5cm |\n| 左边距 | 2.8cm |\n| 右边距 | 2.6cm |\n| 行间距 | 固定值 26 磅 |\n| 首行缩进 | 2字符（640 twips） |\n\n### 字体设置\n| 元素 | Markdown | 字体 | 字号 |\n|------|----------|------|------|\n| 大标题（单个#） | `#` | 方正小标宋简体 | 二号 |\n| 一级标题（多个#） | `#` | 黑体 | 三号 |\n| 二级标题 | `##` | 黑体 | 三号 |\n| 三级标题 | `###` | 楷体_GB2312 加粗 | 三号 |\n| 四级标题 | `####` | 仿宋_GB2312 | 三号 |\n| 正文 | 普通文本 | 仿宋_GB2312 | 三号 |\n| 加粗文本 | `**text**` | 楷体_GB2312 加粗 | 三号 |\n| 斜体文本 | `*text*` | 楷体_GB2312 | 三号 |\n| 链接 | `[text](url)` | 仿宋_GB2312 蓝色下划线 | 三号 |\n| 表格表头 | `| 表头 |` | 黑体 | 三号 |\n| 表格内容 | `| 内容 |` | 仿宋_GB2312 | 三号 |\n| 代码块 | ` ``` ` | 仿宋_GB2312 | 小四号 |\n| 页码 | - | 宋体 | 四号 |\n\n### 标题编号规则\n| 层级 | 格式示例 | 说明 |\n|------|----------|------|\n| 大标题 | 公文标题 | 单个#标题居中，不加序号 |\n| 一级标题 | 一、章节名称 | 多个#标题自动加序号 |\n| 二级标题 | 一、章节名称 | ## 标题自动加序号 |\n| 三级标题 | （一）小节名称 | ### 标题加中文括号序号 |\n| 四级标题 | 正文格式 | #### 标题不加序号 |\n\n### 支持的 Markdown 元素\n| 元素 | 转换效果 |\n|------|----------|\n| 标题 `# / ## / ### / ####` | 智能层级判断 + 自动编号 |\n| 段落 | 正文仿宋三号，首行缩进2字符 |\n| 有序列表 `1. 2. 3.` | 自动编号，支持嵌套 |\n| 无序列表 `- / *` | 圆点标记，支持嵌套 |\n| 表格 `| ... |` | Word表格，表头黑体 |\n| 图片 `![alt](url)` | 居中图片 + 图注 |\n| 链接 `[text](url)` | 蓝色下划线超链接 |\n| 加粗 `**text**` | 楷体加粗 |\n| 斜体 `*text*` | 楷体 |\n| 代码块 ` ``` ` | 仿宋小四号 |\n| 水平线 `---` | 忽略 |\n\n---\n\n## 依赖要求\n\n| 依赖 | 版本 |\n|------|------|\n| Python | >= 3.8 |\n| python-docx | ~= 1.1.0 |\n| markdown-it-py | ~= 3.0.0 |\n\n---\n\n## 支持平台\n\n- ✅ Windows 10/11\n- ✅ Linux\n- ✅ macOS\n\n---\n\n## 项目链接\n\n- GitHub: https://github.com/EdwardWason/official-doc\n- Release: https://github.com/EdwardWason/official-doc/releases\n- README: https://github.com/EdwardWason/official-doc/blob/main/README.md\n\nFile v1.1.9:README.md\n\n# 📄 Official Doc - Document Format Converter\n\n🇨🇳 [中文文档](README_CN.md) | 🇺🇸 English\n\nConvert Markdown documents to Chinese government official document format (GB/T 9704-2012) Word documents. Focused on formatting conversion only — does not add red header, record mark, signature block, or other decorative elements of official documents.\n\n---\n\n## ⚠️ Important Notes\n\nThis tool only provides formatting functionality and does not review content. Please ensure that the official documents generated using this tool comply with relevant regulations and requirements.\n\n### Network Access Disclosure for Image Download\n\n- When the Markdown contains remote images via `![alt](http/https URL)`, this tool will **automatically issue outbound network requests** to download and embed them into the Word document.\n- Only `http://`, `https://`, and `data:image` schemes are allowed; other schemes (e.g., `file://`, `ftp://`) are silently skipped to prevent SSRF.\n- **Privacy & Compliance Notice**: In restricted network environments (intranet, classified networks, air-gapped systems), disable remote image download by passing `download_images=False`:\n\n```python\nmd_to_docx(md_content, output_path, download_images=False)\n# When disabled, remote images are replaced with a [Image: alt] text placeholder, with no network requests made.\n```\n\n- For untrusted Markdown sources, review image URLs beforehand to avoid leaking network metadata to attacker-controlled endpoints.\n\n---\n\n## ✨ Features\n\n| Feature | Description |\n|---------|-------------|\n| 🚀 **One-click Conversion** | Convert Markdown to Word official document format easily |\n| 📋 **Standard Compliance** | Strictly follows GB/T 9704-2012 standard |\n| 🤖 **Multi-Agent Support** | Works with OpenClaw, Hermes Agent, Claude Code, etc. |\n| 🔄 **Dual Output** | Generate both Markdown (for machines) and Word (for humans) |\n| 📊 **Automation Ready** | Supports scheduled tasks for automatic report generation |\n| 📦 **Easy Integration** | Provides standard Python API for system integration |\n\n---\n\n## 🆕 v1.1.0 New Features\n\n- Introduced **markdown-it-py** parser, supporting multi-line paragraphs and nested lists\n- Smart `#` heading detection: a single `#` is treated as a main title (centered, no numbering); multiple `#` headings are treated as first-level headings (with numbering)\n- First line indent precisely aligned with national standard (640 twips = width of 2 Size-3 Chinese characters)\n- Added support for **tables, images, hyperlinks, code blocks, and nested lists**\n- **Bold text** is automatically converted to KaiTi_GB2312 bold (楷体加粗); *italic text* is automatically converted to KaiTi (楷体)\n\n---\n\n## 🚀 Quick Start\n\n### System Requirements\n\n| Component | Requirement |\n|-----------|-------------|\n| OS | Windows 10/11, Linux, macOS |\n| Python | 3.8+ (3.11 / 3.12 / 3.13 supported) |\n| Dependency | python-docx ~= 1.1.0, markdown-it-py ~= 3.0.0 |\n\n### Installation\n\n**Method 1: Using pip**\n```bash\npip install \"python-docx~=1.1.0\" \"markdown-it-py~=3.0.0\"\n```\n\n**Method 2: Clone repository**\n```bash\ngit clone https://github.com/EdwardWason/official-doc.git\ncd official-doc\npip install -r requirements.txt\n```\n\n### Usage Example\n\n```python\nfrom official_doc import md_to_docx\n\n# Markdown content\nmd_content = \"\"\"# Weekly Report\n\n## 1. Work Summary\n\nCompleted system upgrade tasks including:\n\n### 1.1 Main Tasks\n1. Server deployment\n2. Data migration\n3. Testing and verification\n\n### 1.2 Issues\nSome features need further optimization.\n\n### 1.3 Next Week Plan\nContinue optimization work.\n\"\"\"\n\n# Convert to official document format\nsuccess = md_to_docx(md_content, \"weekly_report.docx\")\nprint(\"Conversion successful\" if success else \"Conversion failed\")\n```\n\n---\n\n## 📋 Format Specifications (GB/T 9704-2012)\n\n### Page Settings\n\n| Setting | Value |\n|---------|-------|\n| Paper Size | A4 (210mm × 297mm) |\n| Top Margin | 3.7cm |\n| Bottom Margin | 3.5cm |\n| Left Margin | 2.8cm |\n| Right Margin | 2.6cm |\n| Line Spacing | 26pt (fixed) |\n| First Line Indent | 2 characters (640 twips) |\n\n### Font Settings\n\n| Element | Markdown | Font | Size |\n|---------|----------|------|------|\n| Title | `#` (single) | Fangzheng Xiaobiao Song | 2nd |\n| Heading 1 | `##` / `#` (multiple) | Hei Ti | 3rd |\n| Heading 2 | `###` | Kai Ti_GB2312 bold | 3rd |\n| Heading 3 | `####` | Fang Song_GB2312 | 3rd |\n| Body | Normal | Fang Song_GB2312 | 3rd |\n| Page Number | - | Song Ti | 4th |\n\n### Heading Numbering Rules\n\n| Level | Condition | Format Example |\n|-------|-----------|---------------|\n| Title | Single `#` in document | Document Title (centered, no numbering) |\n| Heading 1 | `##` or multiple `#` | I. Section Name |\n| Heading 2 | `###` | (I) Subsection Name |\n| Heading 3 | `####` | 1. Item Name |\n\n### Supported Markdown Elements\n\n| Element | Markdown Syntax | Notes |\n|---------|----------------|-------|\n| Heading | `#` `##` `###` `####` | Smart title detection |\n| Paragraph | Plain text | Multi-line paragraph support |\n| Ordered List | `1. 2. 3.` | Nested list support |\n| Unordered List | `- - -` | Nested list support |\n| Table | `\\| col \\| col \\|` | Full table support |\n| Image | `![alt](url)` | Inline image |\n| Link | `[text](url)` | Hyperlink |\n| Bold | `**text**` | Auto-convert to KaiTi_GB2312 bold |\n| Italic | `*text*` | Auto-convert to Kai Ti |\n| Code Block | `` ```code``` `` | Monospace formatting |\n| Horizontal Rule | `---` | Page separator |\n\n---\n\n## 🔧 AI Agent Integration\n\n### OpenClaw Integration\n\n```python\nfrom official_doc import md_to_docx\nfrom openclaw import Skill\n\nclass OfficialDocSkill(Skill):\n    name = \"official-doc\"\n    description = \"Convert Markdown to Chinese government official document format\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"Conversion completed\" if success else \"Conversion failed\"\n        }\n```\n\n### Hermes Agent Integration\n\n```python\nfrom hermes import Agent\n\nagent = Agent()\nresult = agent.run_skill(\n    skill=\"official-doc\",\n    md_content=report_content,\n    output_path=\"weekly_report.docx\"\n)\n```\n\n---\n\n## 📁 Project Structure\n\n```\nofficial-doc/\n├── src/                      # Source code\n│   ├── __init__.py          # Package initialization\n│   └── md2docx.py           # Core conversion module\n├── skill.json               # AI Agent skill configuration\n├── setup.py                 # Installation configuration\n├── requirements.txt         # Dependencies\n├── README.md                # English documentation\n├── README_CN.md             # Chinese documentation\n├── CHANGELOG.md             # Changelog\n├── LICENSE                  # MIT License\n└── .gitignore               # Git ignore rules\n```\n\n---\n\n## 🧪 Testing\n\n```bash\ncat > test_official_doc.py << 'EOF'\nfrom official_doc import md_to_docx\n\ndef test_conversion():\n    md_content = \"\"\"# Test Document\n\n## 1. Test Title\n\nThis is a test paragraph.\n\n### 1.1 Subtitle\n\n**Bold text** test.\n\"\"\"\n    success = md_to_docx(md_content, 'test_output.docx')\n    assert success == True\n    print(\"✓ Test passed\")\n\nif __name__ == \"__main__\":\n    test_conversion()\n    print(\"✅ All tests passed!\")\nEOF\n\npython test_official_doc.py\n```\n\n---\n\n## 📜 License\n\nMIT License\n\n---\n\n## 🤝 Contributing\n\nWelcome to submit Issues and Pull Requests!\n\n1. Fork this repository\n2. Create feature branch (`git checkout -b feature/AmazingFeature`)\n3. Commit changes (`git commit -m 'feat: Add some AmazingFeature'`)\n4. Push to branch (`git push origin feature/AmazingFeature`)\n5. Open Pull Request\n\n---\n\n\n*Built with ❤️ for LLM + AI Agent Ecosystem*\n\nFile v1.1.9:_meta.json\n\n{\n  \"ownerId\": \"kn75zj7vzdyvap84adxa8heyyd82f5eh\",\n  \"slug\": \"gongwen-formatter\",\n  \"version\": \"1.1.9\",\n  \"publishedAt\": 1790069638779\n}\n\nFile v1.1.9:CHANGELOG.md\n\n# Changelog\n\n本文件记录 official-doc（gongwen-formatter）所有版本的变更。\n\n格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.0.0/)，\n版本号遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/)。\n\n## [1.1.9] - 2026-09-22\n\n### 元数据（三平台同步 · SkillHub 标题双语化）\n\n#### Changed\n- `displayName` 改为中英双语 `Gongwen Formatter 公文格式转换`，便于中文用户在 SkillHub 检索（无功能变更）\n- 三平台同步发布（GitHub + ClawHub + SkillHub）\n\n## [1.1.8] - 2026-09-20\n\n### 格式增强（间隔号序号规范化为公文标准序号）\n\n#### Changed\n- **间隔号序号规范化**：识别到「一 · 源头」「2 · 源头」间隔号体例时，\n  不再原样保留，而是改写为公文标准序号：\n  - `##`（一级标题）：「一 · 源头」→「一、源头」，阿拉伯数字自动转中文数字（「2 · 」→「二、」）\n  - `###`（二级标题）：「五 · 天长专章」→「（五）天长专章」\n  - 新增 `normalize_heading_number()`，在 `heading_open` 渲染前原地改写 children 首 token\n- 结构性标题（「结语 ·」「附一 ·」等）保持原样，不套序号\n\n## [1.1.7] - 2026-09-20\n\n### 格式修复（序号去重正则未覆盖间隔号体例，导致自动编号与原文序号重复）\n\n#### Fixed\n- **间隔号序号未被识别**：涌现写作交付成稿常用「一 · 源头」「五 · 天长专章」等间隔号体例，\n  此前 `has_heading_number()` 仅识别「一、」「（一）」「1.」「第X章」四种格式，\n  间隔号写法匹配不上 → 引擎判定\"原文没带序号\" → 自动补号，产生「二、一·源头」「（一）五·天长专章」等重复\n  - 修复：新增 `[一二三四五六七八九十]{1,3}\\s*[·・•.]\\s*` 和 `\\d{1,2}\\s*[·・•]\\s*` 两条正则\n  - 同时增加结构性标题识别：`结语 ·`、`引言 ·`、`附一 ·`、`附录` 等，\n    这些标题本身即序号终结标记，不应再追加公文序号\n\n## [1.1.6] - 2026-09-14\n\n### 格式修复（响应跨任务调用反馈：合同/协议\"一行一要素\"被合并为单段）\n\n#### Fixed\n- **连续非空行被合并为单段**：Markdown 中连续的非空行（行间为软换行 `softbreak`）此前被解析为同一个段落，\n  \"甲方：/住所：/法定代表人：\"这类一行一要素的协议抬头会被挤在同一段内显示\n  - 根因：`render_inline_with_formatting` 对 `softbreak` 直接 `pass`，行边界信息在渲染阶段被丢弃\n  - 修复：新增 `split_inline_on_linebreaks()`，在 `paragraph_open` 处按 `softbreak`/`hardbreak`\n    将 inline children 拆分为多个独立段，每段独立应用两端对齐 + 固定行距 + 首行缩进 640 twips（2 字）\n  - 效果：每个源码行还原为独立段落，各自首行缩进 2 字，消除段内断行造成的左边缘参差\n\n#### Notes\n- 本版一并纳入此前仅写入代码 docstring、未落到 CHANGELOG / 版本号文件的 v1.1.5 标题层级重定义：\n  `#` 大标题（方正小标宋简体二号，居中，一律不加序号）/ `##` 一级标题（黑体三号）/\n  `###` 楷体_GB2312 加粗 / `####` 仿宋_GB2312 加粗；标题原文已带序号时不再自动补序号\n\n## [1.1.4] - 2026-07-15\n\n### 格式修复（对齐公文规范，响应跨任务调用反馈）\n\n#### Fixed\n- **加粗句（`**text**`）修复**：由\"黑体不加粗\"改为\"楷体_GB2312 加粗\"\n  - 原问题：`**一是强化谋划动员**` 这类段首加粗句被渲染为黑体三号且无加粗效果，强调完全丢失\n  - 根因：`render_inline_with_formatting` 的 strong 分支使用 `set_font(run, '黑体', font_size)`，black 默认 False\n  - 修复：strong 分支改为 `set_font(run, '楷体_GB2312', font_size, bold=True)`，符合公文段首\"一是/二是\"句式标准格式\n- **三级标题（`###`）修复**：由\"楷体不加粗\"改为\"楷体_GB2312 加粗\"\n  - 根因：h3 分支的标题文字和前缀均未传 `bold=True`\n  - 修复：h3 分支统一传 `bold=True`，符合 GB/T 9704 二级标题（（一））楷体加粗规范\n- `render_inline_with_formatting` 增加 `bold` 参数，支持标题整体加粗\n\n#### 保持不变的格式\n- 黑体标题（`#`/`##`）不加粗（用户明确要求，黑体本身已足够醒目）\n- 正文仿宋三号不加粗\n- 斜体楷体不加粗\n- 链接蓝色下划线\n\n## [1.1.3] - 2026-07-14\n\n### 修复（响应 v1.1.2 后 SkillSpector 二次审计 7 findings）\n\n#### Fixed\n- 修复 v1.1.2 漏改：README.md / README_CN.md / skill.md / skill.json 中残留的 `>=` 全部改为 `~=`（依赖版本一致性）\n  - 根因：v1.1.2 只改了 requirements.txt 和 setup.py，漏改了 README 安装示例、skill.md 依赖表、skill.json dependencies 字段\n  - SkillSpector 扫描所有文件，因此仍报告 `>=` 为 Unpinned Dependencies\n\n#### Added\n- frontmatter 增加 `allowed-tools` 字段，声明 filesystem（写 .docx）和 net.http（图片下载，可关闭）两项权限\n  - 目的：让 ClawHub SkillSpector 能从 frontmatter 识别权限声明，减少 MCP Least Privilege finding\n\n#### SkillSpector v1.1.2 二次审计 7 findings 评估\n| Finding | 评估 | 处理 |\n|---------|------|------|\n| MCP Least Privilege (Medium) | stale — 权限声明已在 v1.1.2 添加 | 本次通过 allowed-tools 增强声明 |\n| Description-Behavior Mismatch (Medium) | 过度修改 — 图片下载是合理功能 | 不采纳，保留现有设计 |\n| Context-Inappropriate Capability (Medium) | 过度修改 — 已有白名单+开关 | 不采纳，保留现有设计 |\n| Missing User Warnings × 2 (Medium) | stale — README 警告已添加 | 等 ClawHub 缓存刷新 |\n| Unpinned Dependencies × 2 (Low) | 真实漏改 — 残留 `>=` | 本次修复 |\n\n## [1.1.2] - 2026-07-14\n\n### 安全升级（响应 ClawHub SkillSpector 审计）\n\n#### Added\n- `md_to_docx()` 新增 `download_images` 参数（默认 `True`），受限网络环境可设为 `False` 完全关闭网络请求\n- `skill.md` 增加\"权限声明\"段落，按最小权限原则披露网络访问/文件读写/不读取环境变量/不调用 subprocess\n- README 中英文版增加 \"图片下载网络请求说明 / Network Access Disclosure for Image Download\" 用户警告段落\n\n#### Security\n- `download_image()` 增加 URL scheme 白名单（仅 `http://`/`https://`/`data:image`），防止 SSRF\n- 其他 scheme（`file://`、`ftp://` 等）静默跳过，不发起网络请求\n- `requirements.txt` 改用 `~=` 兼容版本锁定（`python-docx~=1.1.0`、`markdown-it-py~=3.0.0`），平衡安全与兼容性\n\n## [1.1.1] - 2026-07-13\n\n#### Changed\n- 添加 ClawHub 触发词：`公文格式转换`、`转换公文格式`\n- ClawHub slug 改为 `gongwen-formatter`（`official-doc` 已被占用，`official-` 前缀受保护）\n- 三平台同步发布（GitHub + ClawHub + SkillHub）\n\n## [1.1.0] - 2026-07-12\n\n#### Added\n- 引入 `markdown-it-py` 解析器替代逐行 `split('\\n')`，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个 `#` 视为大标题（居中不加序号），多个 `#` 视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度，1汉字=16pt=320twips）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- 加粗文本（`**text**`）自动转为黑体\n- 斜体文本（`*text*`）自动转为楷体\n\n#### Fixed\n- 黑体字体不再设置 `bold=True`（用户反馈\"黑体不需要加粗处理\"）\n- 移除所有黑体/楷体的 `bold=True` 设置\n\n## [1.0.0] - 2026-07-10\n\n#### Added\n- 初始版本：基于 GB/T 9704-2012 标准，将 Markdown 转换为党政机关公文格式 Word 文档\n- 实现基础标题层级、段落、列表转换\n- 国标页面设置：A4、上 3.7cm/下 3.5cm/左 2.8cm/右 2.6cm、行距 26pt\n- 字体规范：方正小标宋/黑体/楷体_GB2312/仿宋_GB2312/宋体\n\nFile v1.1.9:README_CN.md\n\n# 📄 Official Doc - 公文格式转换\n\n🇨🇳 中文文档 | 🇺🇸 [English](README.md)\n\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\n\n---\n\n## ⚠️ 重要说明\n\n本工具仅提供格式排版功能，不负责内容审核。请确保使用本工具生成的公文内容符合相关规定和要求。\n\n### 关于图片下载的网络请求说明\n\n- 当 Markdown 中包含 `![alt](http/https URL)` 远程图片时，本工具会**自动发起网络请求**下载并嵌入到 Word 文档中。\n- 仅允许 `http://`、`https://` 和 `data:image` 协议；其他 scheme（如 `file://`、`ftp://`）会被静默跳过，防止 SSRF。\n- **隐私与合规提示**：在受限网络环境（内网、保密网络、隔离环境）中使用时，建议通过 `download_images=False` 参数关闭远程图片下载：\n\n```python\nmd_to_docx(md_content, output_path, download_images=False)\n# 关闭后，远程图片将以 [图片: alt] 文字占位替代，不发起任何网络请求\n```\n\n- 对不可信来源的 Markdown 文档，请先审阅图片 URL，避免向攻击者控制的端点泄露网络元数据。\n\n---\n\n## ✨ 功能特点\n\n| 功能 | 描述 |\n|------|------|\n| 🚀 **一键转换** | Markdown 转 Word 公文格式，简单易用 |\n| 📋 **标准遵循** | 严格按照 GB/T 9704-2012 党政机关公文格式标准 |\n| 🤖 **多智能体兼容** | 支持 OpenClaw、Hermes Agent、Claude Code 等 AI 智能体 |\n| 🔄 **双重输出** | 一份内容，同时生成 Markdown（供机器读）和 Word（供人读） |\n| 📊 **自动化支持** | 支持定时任务自动生成简报、周报、月报 |\n| 📦 **易于集成** | 提供标准 Python API，便于其他系统集成 |\n\n---\n\n## 🆕 v1.1.0 新特性\n\n- 引入 **markdown-it-py** 解析器，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- **加粗文本**自动转为楷体加粗，*斜体文本*自动转为楷体\n\n---\n\n## 🚀 快速开始\n\n### 环境要求\n\n| 组件 | 要求 |\n|------|------|\n| 操作系统 | Windows 10/11、Linux、macOS |\n| Python | 3.8+（支持 3.11 / 3.12 / 3.13） |\n| 依赖 | python-docx ~= 1.1.0, markdown-it-py ~= 3.0.0 |\n\n### 安装方法\n\n**方式一：使用 pip 安装**\n```bash\npip install \"python-docx~=1.1.0\" \"markdown-it-py~=3.0.0\"\n```\n\n**方式二：克隆仓库**\n```bash\ngit clone https://github.com/EdwardWason/official-doc.git\ncd official-doc\npip install -r requirements.txt\n```\n\n### 使用示例\n\n```python\nfrom official_doc import md_to_docx\n\n# Markdown 内容\nmd_content = \"\"\"# 工作简报\n\n## 一、上周工作总结\n\n本周完成了系统升级任务，主要包括：\n\n### （一）主要工作\n1. 完成服务器部署\n2. 完成数据迁移\n3. 完成测试验证\n\n### （二）存在问题\n部分功能需要进一步优化。\n\n### （三）下周计划\n继续推进优化工作。\n\"\"\"\n\n# 转换为公文格式\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\nprint(\"转换成功\" if success else \"转换失败\")\n```\n\n---\n\n## 📋 公文格式规范（GB/T 9704-2012）\n\n### 页面设置\n\n| 设置项 | 规范值 |\n|--------|--------|\n| 纸张尺寸 | A4 (210mm × 297mm) |\n| 上边距 | 3.7cm |\n| 下边距 | 3.5cm |\n| 左边距 | 2.8cm |\n| 右边距 | 2.6cm |\n| 行间距 | 固定值 26 磅 |\n| 首行缩进 | 2字符（640 twips） |\n\n### 字体规范\n\n| 元素 | Markdown 标记 | 字体 | 字号 |\n|------|--------------|------|------|\n| 大标题 | `#`（单个） | 方正小标宋简体 | 二号 |\n| 一级标题 | `##` / `#`（多个） | 黑体 | 三号 |\n| 二级标题 | `###` | 楷体_GB2312 加粗 | 三号 |\n| 三级标题 | `####` | 仿宋_GB2312 | 三号 |\n| 正文 | 普通文本 | 仿宋_GB2312 | 三号 |\n| 页码 | - | 宋体 | 四号 |\n\n### 标题编号规则\n\n| 层级 | 判断条件 | 格式示例 |\n|------|----------|----------|\n| 大标题 | 文档中仅一个 `#` | 公文标题（居中，不加序号） |\n| 一级标题 | `##` 或多个 `#` | 一、章节名称 |\n| 二级标题 | `###` | （一）小节名称 |\n| 三级标题 | `####` | 1. 项目名称 |\n\n### 支持的 Markdown 元素\n\n| 元素 | Markdown 语法 | 说明 |\n|------|--------------|------|\n| 标题 | `#` `##` `###` `####` | 智能标题判断 |\n| 段落 | 普通文本 | 支持多行段落 |\n| 有序列表 | `1. 2. 3.` | 支持嵌套列表 |\n| 无序列表 | `- - -` | 支持嵌套列表 |\n| 表格 | `\\| 列 \\| 列 \\|` | 完整表格支持 |\n| 图片 | `![alt](url)` | 行内图片 |\n| 超链接 | `[文本](url)` | 超链接 |\n| 加粗 | `**文本**` | 自动转为楷体加粗 |\n| 斜体 | `*文本*` | 自动转为楷体 |\n| 代码块 | `` ```代码``` `` | 等宽字体格式 |\n| 分隔线 | `---` | 页面分隔 |\n\n---\n\n## 🔧 AI Agent 集成指南\n\n### OpenClaw 集成\n\n```python\nfrom official_doc import md_to_docx\nfrom openclaw import Skill\n\nclass OfficialDocSkill(Skill):\n    name = \"official-doc\"\n    description = \"公文格式转换 - 将 Markdown 转为党政机关公文格式\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output_公文格式.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"公文格式转换完成\" if success else \"转换失败\"\n        }\n```\n\n### Hermes Agent 集成\n\n```python\n# 调用示例\nfrom hermes import Agent\n\nagent = Agent()\nresult = agent.run_skill(\n    skill=\"official-doc\",\n    md_content=report_content,\n    output_path=\"weekly_report.docx\"\n)\n```\n\n### 定时任务配置\n\n```python\nimport schedule\nimport time\nfrom official_doc import md_to_docx\n\ndef generate_daily_report():\n    content = generate_report_content()\n    today = time.strftime(\"%Y-%m-%d\")\n    md_to_docx(content, f\"工作简报_{today}_公文格式.docx\")\n\n# 每周一至周五 9:00 自动执行\nschedule.every().monday.at(\"09:00\").do(generate_daily_report)\nschedule.every().tuesday.at(\"09:00\").do(generate_daily_report)\nschedule.every().wednesday.at(\"09:00\").do(generate_daily_report)\nschedule.every().thursday.at(\"09:00\").do(generate_daily_report)\nschedule.every().friday.at(\"09:00\").do(generate_daily_report)\n\nwhile True:\n    schedule.run_pending()\n    time.sleep(60)\n```\n\n---\n\n## 📁 项目结构\n\n```\nofficial-doc/\n├── src/                      # 源代码目录\n│   ├── __init__.py          # 包初始化\n│   └── md2docx.py           # 核心转换模块\n├── skill.json               # AI Agent 技能配置\n├── setup.py                 # 安装配置\n├── requirements.txt         # 依赖清单\n├── README.md                # 英文文档\n├── README_CN.md             # 中文文档\n├── CHANGELOG.md             # 更新日志\n├── LICENSE                  # MIT 许可证\n└── .gitignore               # Git 忽略配置\n```\n\n---\n\n## 🧪 测试验证\n\n```bash\n# 创建测试脚本\ncat > test_official_doc.py << 'EOF'\nfrom official_doc import md_to_docx\n\ndef test_basic_conversion():\n    md_content = \"\"\"# 测试文档\n\n## 一、测试标题\n\n这是一个测试段落。\n\n### （一）二级标题\n\n1. 列表项一\n2. 列表项二\n\n**加粗文本** 测试。\n\"\"\"\n    success = md_to_docx(md_content, 'test_output.docx')\n    assert success == True\n    print(\"✓ 基本转换测试通过\")\n\nif __name__ == \"__main__\":\n    test_basic_conversion()\n    print(\"\\n✅ 所有测试通过！\")\nEOF\n\n# 运行测试\npython test_official_doc.py\n```\n\n---\n\n## 📜 许可证\n\nMIT License\n\n---\n\n## 🤝 贡献指南\n\n欢迎提交 Issue 和 Pull Request！\n\n1. Fork 本仓库\n2. 创建功能分支 (`git checkout -b feature/AmazingFeature`)\n3. 提交更改 (`git commit -m 'feat: Add some AmazingFeature'`)\n4. 推送到分支 (`git push origin feature/AmazingFeature`)\n5. 打开 Pull Request\n\n---\n\n## 📞 联系方式\n\n- **GitHub**: [https://github.com/EdwardWason/official-doc](https://github.com/EdwardWason/official-doc)\n- **Issues**: [https://github.com/EdwardWason/official-doc/issues](https://github.com/EdwardWason/official-doc/issues)\n\n---\n\n*Built with ❤️ for LLM + AI Agent 生态*\n\nFile v1.1.9:skill-card.md\n\n## Description:\n\nConverts Markdown into Word documents formatted for Chinese government official document layout under GB/T 9704-2012, with optional remote image embedding that can be disabled.\n\nThis skill is ready for commercial/non-commercial use.\n\n## Publisher:\n\n[edwardwason](https://clawhub.ai/user/edwardwason)\n\n### License/Terms of Use:\n\nMIT-0\n\n## Use Case:\n\nDevelopers and agents use this skill to turn Markdown reports, briefings, and structured documents into GB/T 9704-2012-style Word files. It is focused on formatting conversion and does not validate document content or add official document decorations.\n\n### Deployment Geography for Use:\n\nGlobal\n\n## Known Risks and Mitigations:\n\nRisk: Markdown containing remote image URLs can trigger outbound image fetches and expose network metadata in sensitive environments.\n\nMitigation: For untrusted Markdown or restricted networks, call md_to_docx with download_images=False and review image URLs before conversion.\n\nRisk: The skill formats documents but does not review content, legal sufficiency, or official document completeness.\n\nMitigation: Review generated documents for content accuracy, compliance, and required official-document elements before use.\n\n## Reference(s):\n\n- [ClawHub skill page](https://clawhub.ai/edwardwason/skills/gongwen-formatter)\n- [Project homepage](https://github.com/EdwardWason/official-doc)\n\n## Skill Output:\n\n**Output Type(s):** [Files, Configuration, Guidance]\n\n**Output Format:** [DOCX Word document with a success status and output path]\n\n**Output Parameters:** [1D]\n\n**Other Properties Related to Output:** [Writes a .docx file; remote image downloads are optional and can be disabled with download_images=False.]\n\n## Skill Version(s):\n\n1.1.9 (source: server release evidence, artifact frontmatter, skill.json, CHANGELOG)\n\n## Ethical Considerations:\n\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment.\n\nFile v1.1.9:skill.json\n\n{\n  \"name\": \"gongwen-formatter\",\n  \"name_cn\": \"公文格式转换\",\n  \"displayName\": \"Gongwen Formatter 公文格式转换\",\n  \"version\": \"1.1.9\",\n  \"description\": \"将 Markdown 文档转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文档\",\n  \"description_en\": \"Convert Markdown documents to Chinese government official document format (GB/T 9704-2012)\",\n  \"author\": \"EdwardWason\",\n  \"license\": \"MIT\",\n  \"homepage\": \"https://github.com/EdwardWason/official-doc\",\n  \"tags\": [\"document\", \"formatter\", \"markdown\", \"word\", \"government\", \"chinese\", \"gb9704\"],\n  \"triggers\": [\"公文格式转换\", \"转换公文格式\"],\n  \"platform\": [\"windows\", \"linux\", \"macos\"],\n  \"python_version\": \">=3.8\",\n  \"dependencies\": [\"python-docx~=1.1.0\", \"markdown-it-py~=3.0.0\"],\n\n  \"skills\": {\n    \"name\": \"gongwen-formatter\",\n    \"type\": \"formatter\",\n    \"category\": \"文档处理\"\n  },\n\n  \"input\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"md_content\": {\n        \"type\": \"string\",\n        \"description\": \"Markdown 格式的文本内容\"\n      },\n      \"output_path\": {\n        \"type\": \"string\",\n        \"description\": \"输出 Word 文件路径\"\n      }\n    },\n    \"required\": [\"md_content\", \"output_path\"]\n  },\n\n  \"output\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"success\": {\n        \"type\": \"boolean\",\n        \"description\": \"转换是否成功\"\n      },\n      \"output_path\": {\n        \"type\": \"string\",\n        \"description\": \"输出文件路径\"\n      }\n    }\n  },\n\n  \"examples\": [\n    {\n      \"name\": \"基本转换\",\n      \"code\": \"from official_doc import md_to_docx\\n\\nmd_content = '''# 大标题\\n\\n## 一级标题\\n\\n这是正文内容。\\n'''\\nmd_to_docx(md_content, 'output.docx')\"\n    },\n    {\n      \"name\": \"含表格和图片\",\n      \"code\": \"from official_doc import md_to_docx\\n\\nmd_content = '''# 工作简报\\n\\n## 工作总结\\n\\n| 项目 | 进度 |\\n|------|------|\\n| A项目 | 80% |\\n| B项目 | 60% |\\n\\n![架构图](https://example.com/arch.png)\\n'''\\nmd_to_docx(md_content, '简报_公文格式.docx')\"\n    },\n    {\n      \"name\": \"AI Agent 集成\",\n      \"code\": \"from official_doc import md_to_docx\\n\\ndef generate_report(content):\\n    # 保存 Markdown 版本\\n    with open('report.md', 'w', encoding='utf-8') as f:\\n        f.write(content)\\n    # 生成公文格式\\n    md_to_docx(content, 'report_公文格式.docx')\\n    return '报告已生成'\"\n    }\n  ],\n\n  \"format_standard\": {\n    \"name\": \"GB/T 9704-2012\",\n    \"description\": \"党政机关公文格式\",\n    \"page_settings\": {\n      \"top_margin\": \"3.7cm\",\n      \"bottom_margin\": \"3.5cm\",\n      \"left_margin\": \"2.8cm\",\n      \"right_margin\": \"2.6cm\",\n      \"line_spacing\": \"26pt\",\n      \"first_line_indent\": \"2字符(640twips)\"\n    },\n    \"font_settings\": {\n      \"title\": {\"font\": \"方正小标宋简体\", \"size\": \"二号\", \"note\": \"单个#标题居中不加序号，多个#标题加序号\"},\n      \"level1\": {\"font\": \"黑体\", \"size\": \"三号\"},\n      \"level2\": {\"font\": \"楷体_GB2312\", \"size\": \"三号\", \"bold\": true},\n      \"level3\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\", \"bold\": true},\n      \"body\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\"},\n      \"table_header\": {\"font\": \"黑体\", \"size\": \"三号\"},\n      \"table_body\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\"},\n      \"link\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\", \"color\": \"蓝色\", \"underline\": true}\n    },\n    \"supported_elements\": {\n      \"headings\": \"# / ## / ### / #### 智能层级判断\",\n      \"paragraphs\": \"正文段落，首行缩进2字符\",\n      \"ordered_list\": \"有序列表，支持嵌套\",\n      \"unordered_list\": \"无序列表，支持嵌套\",\n      \"table\": \"Markdown表格 → Word表格\",\n      \"image\": \"![alt](url) → 居中图片+图注\",\n      \"link\": \"[text](url) → 蓝色下划线超链接\",\n      \"bold\": \"**text** → 黑体\",\n      \"italic\": \"*text* → 楷体加粗\",\n      \"code_block\": \"```代码块 → 仿宋小四号\",\n      \"hr\": \"--- 水平线忽略\"\n    }\n  }\n}\n\nFile v1.1.9:requirements.txt\n\npython-docx~=1.1.0\nmarkdown-it-py~=3.0.0\n\nArchive v1.1.4: 11 files, 25453 bytes\n\nFiles: CHANGELOG.md (4900b), README_CN.md (8512b), README.md (7895b), requirements.txt (41b), setup.py (1117b), skill-card.md (1987b), skill.json (3925b), skill.md (9781b), src/__init__.py (324b), src/md2docx.py (27197b), _meta.json (136b)\n\nFile v1.1.4:skill.md\n\n---\nslug: gongwen-formatter\nname: gongwen-formatter\ndisplayName: Gongwen Formatter\nname_cn: 公文格式转换\nversion: 1.1.4\nauthor: EdwardWason\nlicense: MIT\nhomepage: https://github.com/EdwardWason/official-doc\ndescription: 公文格式转换 — 将 Markdown 转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文件。可选能力：远程图片下载（仅 http/https/data:image，可通过 download_images=False 关闭）。Do NOT：不做文体识别、不添加红头/版记/落款、不做内容审核。\nsummary: 将 Markdown 转换为符合 GB/T 9704-2012 标准的党政机关公文格式 Word 文件。\nallowed-tools:\n  - filesystem (write .docx output)\n  - net.http (GET image download, http/https only, toggleable via download_images=False)\ntriggers:\n  - 公文格式转换\n  - 转换公文格式\n---\n\n# 📄 official-doc - 公文格式转换\n\n## 技能信息\n\n### 基本信息\n| 属性 | 说明 |\n|------|------|\n| **名称** | official-doc |\n| **中文名称** | 公文格式转换 |\n| **版本** | 1.1.4 |\n| **作者** | EdwardWason |\n| **许可证** | MIT |\n| **主页** | https://github.com/EdwardWason/official-doc |\n\n### 触发词\n- **公文格式转换**\n- **转换公文格式**\n\n### 功能描述\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\n\n### 适用场景\n- AI Agent 生成公文格式报告\n- 定时任务自动生成工作简报、周报、月报\n- Markdown 文档批量转换为标准公文格式\n- 行业研报格式标准化输出\n\n### Do NOT（超出范围）\n- ❌ **不做文体识别**：不区分通知/通报/报告/请示等公文文种，统一按 Markdown 结构转换\n- ❌ **不添加公文装饰要素**：不生成红头、版记、落款、签发人、密级标识等\n- ❌ **不做内容审核**：不审查内容合规性、不校验公文要素完整性\n- ❌ **不做双向转换**：仅支持 Markdown → Word 单向，不支持 Word → Markdown 反向\n- ❌ **不读取本地敏感文件**：不读取 memory/profile/credentials 等任何用户数据\n\n### v1.1.0 新增功能\n- 引入 markdown-it-py 解析器，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- 加粗文本自动转为楷体加粗，斜体文本自动转为楷体\n\n### v1.1.2 安全升级（响应 ClawHub SkillSpector 审计）\n- `download_image()` 增加 URL scheme 白名单（仅 `http://`/`https://`/`data:image`），防止 SSRF\n- `md_to_docx()` 新增 `download_images=True` 参数，受限网络环境可设为 `False` 完全关闭网络请求\n- `_handle_standalone_image()` 关闭图片下载时以 `[图片: alt]` 文字占位替代\n- `requirements.txt` 改用 `~=` 兼容版本锁定（python-docx~=1.1.0、markdown-it-py~=3.0.0）\n- README 中英文版增加 \"图片下载网络请求说明 / Network Access Disclosure\" 用户警告段落\n\n### v1.1.3 修复（响应 v1.1.2 后 SkillSpector 二次审计）\n- 修复 v1.1.2 漏改：README/skill.md/skill.json 中残留的 `>=` 全部改为 `~=`（依赖版本一致性）\n- frontmatter 增加 `allowed-tools` 字段，声明 filesystem（写 .docx）和 net.http（图片下载，可关闭）两项权限\n- 7 项 findings 中：2 项真实漏改（本次修复）、3 项 stale（已修复但被重复扫描，本次通过 allowed-tools 增强声明）、2 项过度修改（保留现有设计，不采纳）\n\n### v1.1.4 格式修复（对齐公文规范）\n- **加粗句（`**text**`）修复**：由\"黑体不加粗\"改为\"楷体_GB2312 加粗\"——符合公文段首\"一是/二是\"句式标准格式\n- **三级标题（`###`）修复**：由\"楷体不加粗\"改为\"楷体_GB2312 加粗\"——符合 GB/T 9704 二级标题（（一））楷体加粗规范\n- 黑体标题（`#`/`##`）、正文仿宋、斜体楷体等保持不变\n\n---\n\n## 权限声明\n\n本技能执行过程中涉及的系统能力（用户须知）：\n\n| 能力类别 | 是否使用 | 说明 |\n|---------|---------|------|\n| **网络访问** | ✅ 仅 http/https 图片下载 | 默认开启；可通过 `download_images=False` 关闭；URL scheme 白名单防止 SSRF |\n| **文件读写** | ✅ 仅写入输出 .docx 和临时图片缓存 | 临时图片下载后立即 `os.unlink` 删除；不读取用户其他文件 |\n| **环境变量** | ❌ 不读取 | 不依赖任何环境变量，无凭证收集 |\n| **subprocess 调用** | ❌ 不调用 | 纯 Python 实现，不执行 shell 命令 |\n| **外部 API 调用** | ❌ 不调用 | 不向任何外部 API 推送数据 |\n\n**最小权限原则**：本技能仅做 Markdown→Word 格式转换，不涉及任何外部数据上传、凭证收集或子进程调用。\n\n---\n\n## 输入参数\n\n| 参数名 | 类型 | 必填 | 说明 |\n|--------|------|------|------|\n| `md_content` | string | ✅ | Markdown 格式的文本内容 |\n| `output_path` | string | ✅ | 输出 Word 文件路径（.docx） |\n| `download_images` | bool | ❌ | 是否下载远程图片并嵌入 Word，默认 `True`；受限网络环境设为 `False` 跳过网络请求 |\n\n---\n\n## 输出结果\n\n| 字段 | 类型 | 说明 |\n|------|------|------|\n| `success` | boolean | 转换是否成功 |\n| `output_path` | string | 输出文件路径 |\n\n---\n\n## 使用示例\n\n### 基本使用\n```python\nfrom official_doc import md_to_docx\n\nmd_content = \"\"\"# 工作简报\n\n## 一、上周工作总结\n\n本周完成了系统升级任务。\n\n### （一）主要工作\n1. 服务器部署\n2. 数据迁移\n3. 测试验证\n\n### （二）下周计划\n继续推进优化工作。\n\"\"\"\n\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\nprint(\"转换成功\" if success else \"转换失败\")\n```\n\n### 含表格和图片\n```python\nfrom official_doc import md_to_docx\n\nmd_content = \"\"\"# 项目进度表\n\n## 工作进展\n\n| 项目名称 | 负责人 | 进度 | 备注 |\n|----------|--------|------|------|\n| A项目 | 张三 | 80% | 正常 |\n| B项目 | 李四 | 60% | 需加速 |\n\n![架构图](https://example.com/arch.png)\n\n详细说明请参考[官方文档](https://example.com)。\n\"\"\"\n\nmd_to_docx(md_content, \"进度表_公文格式.docx\")\n```\n\n### AI Agent 集成\n```python\nfrom official_doc import md_to_docx\n\nclass OfficialDocSkill:\n    name = \"official-doc\"\n    description = \"公文格式转换 - 将 Markdown 转为党政机关公文格式\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output_公文格式.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"公文格式转换完成\" if success else \"转换失败\"\n        }\n```\n\n### 定时任务\n```python\nimport schedule\nimport time\nfrom official_doc import md_to_docx\n\ndef generate_report():\n    content = generate_report_content()\n    today = time.strftime(\"%Y-%m-%d\")\n    md_to_docx(content, f\"工作简报_{today}_公文格式.docx\")\n\nschedule.every().monday.at(\"09:00\").do(generate_report)\n```\n\n---\n\n## 格式规范\n\n### 页面设置\n| 设置项 | 规范值 |\n|--------|--------|\n| 上边距 | 3.7cm |\n| 下边距 | 3.5cm |\n| 左边距 | 2.8cm |\n| 右边距 | 2.6cm |\n| 行间距 | 固定值 26 磅 |\n| 首行缩进 | 2字符（640 twips） |\n\n### 字体设置\n| 元素 | Markdown | 字体 | 字号 |\n|------|----------|------|------|\n| 大标题（单个#） | `#` | 方正小标宋简体 | 二号 |\n| 一级标题（多个#） | `#` | 黑体 | 三号 |\n| 二级标题 | `##` | 黑体 | 三号 |\n| 三级标题 | `###` | 楷体_GB2312 加粗 | 三号 |\n| 四级标题 | `####` | 仿宋_GB2312 | 三号 |\n| 正文 | 普通文本 | 仿宋_GB2312 | 三号 |\n| 加粗文本 | `**text**` | 楷体_GB2312 加粗 | 三号 |\n| 斜体文本 | `*text*` | 楷体_GB2312 | 三号 |\n| 链接 | `[text](url)` | 仿宋_GB2312 蓝色下划线 | 三号 |\n| 表格表头 | `| 表头 |` | 黑体 | 三号 |\n| 表格内容 | `| 内容 |` | 仿宋_GB2312 | 三号 |\n| 代码块 | ` ``` ` | 仿宋_GB2312 | 小四号 |\n| 页码 | - | 宋体 | 四号 |\n\n### 标题编号规则\n| 层级 | 格式示例 | 说明 |\n|------|----------|------|\n| 大标题 | 公文标题 | 单个#标题居中，不加序号 |\n| 一级标题 | 一、章节名称 | 多个#标题自动加序号 |\n| 二级标题 | 一、章节名称 | ## 标题自动加序号 |\n| 三级标题 | （一）小节名称 | ### 标题加中文括号序号 |\n| 四级标题 | 正文格式 | #### 标题不加序号 |\n\n### 支持的 Markdown 元素\n| 元素 | 转换效果 |\n|------|----------|\n| 标题 `# / ## / ### / ####` | 智能层级判断 + 自动编号 |\n| 段落 | 正文仿宋三号，首行缩进2字符 |\n| 有序列表 `1. 2. 3.` | 自动编号，支持嵌套 |\n| 无序列表 `- / *` | 圆点标记，支持嵌套 |\n| 表格 `| ... |` | Word表格，表头黑体 |\n| 图片 `![alt](url)` | 居中图片 + 图注 |\n| 链接 `[text](url)` | 蓝色下划线超链接 |\n| 加粗 `**text**` | 楷体加粗 |\n| 斜体 `*text*` | 楷体 |\n| 代码块 ` ``` ` | 仿宋小四号 |\n| 水平线 `---` | 忽略 |\n\n---\n\n## 依赖要求\n\n| 依赖 | 版本 |\n|------|------|\n| Python | >= 3.8 |\n| python-docx | ~= 1.1.0 |\n| markdown-it-py | ~= 3.0.0 |\n\n---\n\n## 支持平台\n\n- ✅ Windows 10/11\n- ✅ Linux\n- ✅ macOS\n\n---\n\n## 项目链接\n\n- GitHub: https://github.com/EdwardWason/official-doc\n- Release: https://github.com/EdwardWason/official-doc/releases\n- README: https://github.com/EdwardWason/official-doc/blob/main/README.md\n\nFile v1.1.4:README.md\n\n# 📄 Official Doc - Document Format Converter\n\n🇨🇳 [中文文档](README_CN.md) | 🇺🇸 English\n\nConvert Markdown documents to Chinese government official document format (GB/T 9704-2012) Word documents. Focused on formatting conversion only — does not add red header, record mark, signature block, or other decorative elements of official documents.\n\n---\n\n## ⚠️ Important Notes\n\nThis tool only provides formatting functionality and does not review content. Please ensure that the official documents generated using this tool comply with relevant regulations and requirements.\n\n### Network Access Disclosure for Image Download\n\n- When the Markdown contains remote images via `![alt](http/https URL)`, this tool will **automatically issue outbound network requests** to download and embed them into the Word document.\n- Only `http://`, `https://`, and `data:image` schemes are allowed; other schemes (e.g., `file://`, `ftp://`) are silently skipped to prevent SSRF.\n- **Privacy & Compliance Notice**: In restricted network environments (intranet, classified networks, air-gapped systems), disable remote image download by passing `download_images=False`:\n\n```python\nmd_to_docx(md_content, output_path, download_images=False)\n# When disabled, remote images are replaced with a [Image: alt] text placeholder, with no network requests made.\n```\n\n- For untrusted Markdown sources, review image URLs beforehand to avoid leaking network metadata to attacker-controlled endpoints.\n\n---\n\n## ✨ Features\n\n| Feature | Description |\n|---------|-------------|\n| 🚀 **One-click Conversion** | Convert Markdown to Word official document format easily |\n| 📋 **Standard Compliance** | Strictly follows GB/T 9704-2012 standard |\n| 🤖 **Multi-Agent Support** | Works with OpenClaw, Hermes Agent, Claude Code, etc. |\n| 🔄 **Dual Output** | Generate both Markdown (for machines) and Word (for humans) |\n| 📊 **Automation Ready** | Supports scheduled tasks for automatic report generation |\n| 📦 **Easy Integration** | Provides standard Python API for system integration |\n\n---\n\n## 🆕 v1.1.0 New Features\n\n- Introduced **markdown-it-py** parser, supporting multi-line paragraphs and nested lists\n- Smart `#` heading detection: a single `#` is treated as a main title (centered, no numbering); multiple `#` headings are treated as first-level headings (with numbering)\n- First line indent precisely aligned with national standard (640 twips = width of 2 Size-3 Chinese characters)\n- Added support for **tables, images, hyperlinks, code blocks, and nested lists**\n- **Bold text** is automatically converted to KaiTi_GB2312 bold (楷体加粗); *italic text* is automatically converted to KaiTi (楷体)\n\n---\n\n## 🚀 Quick Start\n\n### System Requirements\n\n| Component | Requirement |\n|-----------|-------------|\n| OS | Windows 10/11, Linux, macOS |\n| Python | 3.8+ (3.11 / 3.12 / 3.13 supported) |\n| Dependency | python-docx ~= 1.1.0, markdown-it-py ~= 3.0.0 |\n\n### Installation\n\n**Method 1: Using pip**\n```bash\npip install \"python-docx~=1.1.0\" \"markdown-it-py~=3.0.0\"\n```\n\n**Method 2: Clone repository**\n```bash\ngit clone https://github.com/EdwardWason/official-doc.git\ncd official-doc\npip install -r requirements.txt\n```\n\n### Usage Example\n\n```python\nfrom official_doc import md_to_docx\n\n# Markdown content\nmd_content = \"\"\"# Weekly Report\n\n## 1. Work Summary\n\nCompleted system upgrade tasks including:\n\n### 1.1 Main Tasks\n1. Server deployment\n2. Data migration\n3. Testing and verification\n\n### 1.2 Issues\nSome features need further optimization.\n\n### 1.3 Next Week Plan\nContinue optimization work.\n\"\"\"\n\n# Convert to official document format\nsuccess = md_to_docx(md_content, \"weekly_report.docx\")\nprint(\"Conversion successful\" if success else \"Conversion failed\")\n```\n\n---\n\n## 📋 Format Specifications (GB/T 9704-2012)\n\n### Page Settings\n\n| Setting | Value |\n|---------|-------|\n| Paper Size | A4 (210mm × 297mm) |\n| Top Margin | 3.7cm |\n| Bottom Margin | 3.5cm |\n| Left Margin | 2.8cm |\n| Right Margin | 2.6cm |\n| Line Spacing | 26pt (fixed) |\n| First Line Indent | 2 characters (640 twips) |\n\n### Font Settings\n\n| Element | Markdown | Font | Size |\n|---------|----------|------|------|\n| Title | `#` (single) | Fangzheng Xiaobiao Song | 2nd |\n| Heading 1 | `##` / `#` (multiple) | Hei Ti | 3rd |\n| Heading 2 | `###` | Kai Ti_GB2312 bold | 3rd |\n| Heading 3 | `####` | Fang Song_GB2312 | 3rd |\n| Body | Normal | Fang Song_GB2312 | 3rd |\n| Page Number | - | Song Ti | 4th |\n\n### Heading Numbering Rules\n\n| Level | Condition | Format Example |\n|-------|-----------|---------------|\n| Title | Single `#` in document | Document Title (centered, no numbering) |\n| Heading 1 | `##` or multiple `#` | I. Section Name |\n| Heading 2 | `###` | (I) Subsection Name |\n| Heading 3 | `####` | 1. Item Name |\n\n### Supported Markdown Elements\n\n| Element | Markdown Syntax | Notes |\n|---------|----------------|-------|\n| Heading | `#` `##` `###` `####` | Smart title detection |\n| Paragraph | Plain text | Multi-line paragraph support |\n| Ordered List | `1. 2. 3.` | Nested list support |\n| Unordered List | `- - -` | Nested list support |\n| Table | `\\| col \\| col \\|` | Full table support |\n| Image | `![alt](url)` | Inline image |\n| Link | `[text](url)` | Hyperlink |\n| Bold | `**text**` | Auto-convert to KaiTi_GB2312 bold |\n| Italic | `*text*` | Auto-convert to Kai Ti |\n| Code Block | `` ```code``` `` | Monospace formatting |\n| Horizontal Rule | `---` | Page separator |\n\n---\n\n## 🔧 AI Agent Integration\n\n### OpenClaw Integration\n\n```python\nfrom official_doc import md_to_docx\nfrom openclaw import Skill\n\nclass OfficialDocSkill(Skill):\n    name = \"official-doc\"\n    description = \"Convert Markdown to Chinese government official document format\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"Conversion completed\" if success else \"Conversion failed\"\n        }\n```\n\n### Hermes Agent Integration\n\n```python\nfrom hermes import Agent\n\nagent = Agent()\nresult = agent.run_skill(\n    skill=\"official-doc\",\n    md_content=report_content,\n    output_path=\"weekly_report.docx\"\n)\n```\n\n---\n\n## 📁 Project Structure\n\n```\nofficial-doc/\n├── src/                      # Source code\n│   ├── __init__.py          # Package initialization\n│   └── md2docx.py           # Core conversion module\n├── skill.json               # AI Agent skill configuration\n├── setup.py                 # Installation configuration\n├── requirements.txt         # Dependencies\n├── README.md                # English documentation\n├── README_CN.md             # Chinese documentation\n├── CHANGELOG.md             # Changelog\n├── LICENSE                  # MIT License\n└── .gitignore               # Git ignore rules\n```\n\n---\n\n## 🧪 Testing\n\n```bash\ncat > test_official_doc.py << 'EOF'\nfrom official_doc import md_to_docx\n\ndef test_conversion():\n    md_content = \"\"\"# Test Document\n\n## 1. Test Title\n\nThis is a test paragraph.\n\n### 1.1 Subtitle\n\n**Bold text** test.\n\"\"\"\n    success = md_to_docx(md_content, 'test_output.docx')\n    assert success == True\n    print(\"✓ Test passed\")\n\nif __name__ == \"__main__\":\n    test_conversion()\n    print(\"✅ All tests passed!\")\nEOF\n\npython test_official_doc.py\n```\n\n---\n\n## 📜 License\n\nMIT License\n\n---\n\n## 🤝 Contributing\n\nWelcome to submit Issues and Pull Requests!\n\n1. Fork this repository\n2. Create feature branch (`git checkout -b feature/AmazingFeature`)\n3. Commit changes (`git commit -m 'feat: Add some AmazingFeature'`)\n4. Push to branch (`git push origin feature/AmazingFeature`)\n5. Open Pull Request\n\n---\n\n\n*Built with ❤️ for LLM + AI Agent Ecosystem*\n\nFile v1.1.4:_meta.json\n\n{\n  \"ownerId\": \"kn75zj7vzdyvap84adxa8heyyd82f5eh\",\n  \"slug\": \"gongwen-formatter\",\n  \"version\": \"1.1.4\",\n  \"publishedAt\": 1787478538369\n}\n\nFile v1.1.4:CHANGELOG.md\n\n# Changelog\n\n本文件记录 official-doc（gongwen-formatter）所有版本的变更。\n\n格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.0.0/)，\n版本号遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/)。\n\n## [1.1.4] - 2026-07-15\n\n### 格式修复（对齐公文规范，响应跨任务调用反馈）\n\n#### Fixed\n- **加粗句（`**text**`）修复**：由\"黑体不加粗\"改为\"楷体_GB2312 加粗\"\n  - 原问题：`**一是强化谋划动员**` 这类段首加粗句被渲染为黑体三号且无加粗效果，强调完全丢失\n  - 根因：`render_inline_with_formatting` 的 strong 分支使用 `set_font(run, '黑体', font_size)`，black 默认 False\n  - 修复：strong 分支改为 `set_font(run, '楷体_GB2312', font_size, bold=True)`，符合公文段首\"一是/二是\"句式标准格式\n- **三级标题（`###`）修复**：由\"楷体不加粗\"改为\"楷体_GB2312 加粗\"\n  - 根因：h3 分支的标题文字和前缀均未传 `bold=True`\n  - 修复：h3 分支统一传 `bold=True`，符合 GB/T 9704 二级标题（（一））楷体加粗规范\n- `render_inline_with_formatting` 增加 `bold` 参数，支持标题整体加粗\n\n#### 保持不变的格式\n- 黑体标题（`#`/`##`）不加粗（用户明确要求，黑体本身已足够醒目）\n- 正文仿宋三号不加粗\n- 斜体楷体不加粗\n- 链接蓝色下划线\n\n## [1.1.3] - 2026-07-14\n\n### 修复（响应 v1.1.2 后 SkillSpector 二次审计 7 findings）\n\n#### Fixed\n- 修复 v1.1.2 漏改：README.md / README_CN.md / skill.md / skill.json 中残留的 `>=` 全部改为 `~=`（依赖版本一致性）\n  - 根因：v1.1.2 只改了 requirements.txt 和 setup.py，漏改了 README 安装示例、skill.md 依赖表、skill.json dependencies 字段\n  - SkillSpector 扫描所有文件，因此仍报告 `>=` 为 Unpinned Dependencies\n\n#### Added\n- frontmatter 增加 `allowed-tools` 字段，声明 filesystem（写 .docx）和 net.http（图片下载，可关闭）两项权限\n  - 目的：让 ClawHub SkillSpector 能从 frontmatter 识别权限声明，减少 MCP Least Privilege finding\n\n#### SkillSpector v1.1.2 二次审计 7 findings 评估\n| Finding | 评估 | 处理 |\n|---------|------|------|\n| MCP Least Privilege (Medium) | stale — 权限声明已在 v1.1.2 添加 | 本次通过 allowed-tools 增强声明 |\n| Description-Behavior Mismatch (Medium) | 过度修改 — 图片下载是合理功能 | 不采纳，保留现有设计 |\n| Context-Inappropriate Capability (Medium) | 过度修改 — 已有白名单+开关 | 不采纳，保留现有设计 |\n| Missing User Warnings × 2 (Medium) | stale — README 警告已添加 | 等 ClawHub 缓存刷新 |\n| Unpinned Dependencies × 2 (Low) | 真实漏改 — 残留 `>=` | 本次修复 |\n\n## [1.1.2] - 2026-07-14\n\n### 安全升级（响应 ClawHub SkillSpector 审计）\n\n#### Added\n- `md_to_docx()` 新增 `download_images` 参数（默认 `True`），受限网络环境可设为 `False` 完全关闭网络请求\n- `skill.md` 增加\"权限声明\"段落，按最小权限原则披露网络访问/文件读写/不读取环境变量/不调用 subprocess\n- README 中英文版增加 \"图片下载网络请求说明 / Network Access Disclosure for Image Download\" 用户警告段落\n\n#### Security\n- `download_image()` 增加 URL scheme 白名单（仅 `http://`/`https://`/`data:image`），防止 SSRF\n- 其他 scheme（`file://`、`ftp://` 等）静默跳过，不发起网络请求\n- `requirements.txt` 改用 `~=` 兼容版本锁定（`python-docx~=1.1.0`、`markdown-it-py~=3.0.0`），平衡安全与兼容性\n\n## [1.1.1] - 2026-07-13\n\n#### Changed\n- 添加 ClawHub 触发词：`公文格式转换`、`转换公文格式`\n- ClawHub slug 改为 `gongwen-formatter`（`official-doc` 已被占用，`official-` 前缀受保护）\n- 三平台同步发布（GitHub + ClawHub + SkillHub）\n\n## [1.1.0] - 2026-07-12\n\n#### Added\n- 引入 `markdown-it-py` 解析器替代逐行 `split('\\n')`，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个 `#` 视为大标题（居中不加序号），多个 `#` 视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度，1汉字=16pt=320twips）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- 加粗文本（`**text**`）自动转为黑体\n- 斜体文本（`*text*`）自动转为楷体\n\n#### Fixed\n- 黑体字体不再设置 `bold=True`（用户反馈\"黑体不需要加粗处理\"）\n- 移除所有黑体/楷体的 `bold=True` 设置\n\n## [1.0.0] - 2026-07-10\n\n#### Added\n- 初始版本：基于 GB/T 9704-2012 标准，将 Markdown 转换为党政机关公文格式 Word 文档\n- 实现基础标题层级、段落、列表转换\n- 国标页面设置：A4、上 3.7cm/下 3.5cm/左 2.8cm/右 2.6cm、行距 26pt\n- 字体规范：方正小标宋/黑体/楷体_GB2312/仿宋_GB2312/宋体\n\nFile v1.1.4:README_CN.md\n\n# 📄 Official Doc - 公文格式转换\n\n🇨🇳 中文文档 | 🇺🇸 [English](README.md)\n\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\n\n---\n\n## ⚠️ 重要说明\n\n本工具仅提供格式排版功能，不负责内容审核。请确保使用本工具生成的公文内容符合相关规定和要求。\n\n### 关于图片下载的网络请求说明\n\n- 当 Markdown 中包含 `![alt](http/https URL)` 远程图片时，本工具会**自动发起网络请求**下载并嵌入到 Word 文档中。\n- 仅允许 `http://`、`https://` 和 `data:image` 协议；其他 scheme（如 `file://`、`ftp://`）会被静默跳过，防止 SSRF。\n- **隐私与合规提示**：在受限网络环境（内网、保密网络、隔离环境）中使用时，建议通过 `download_images=False` 参数关闭远程图片下载：\n\n```python\nmd_to_docx(md_content, output_path, download_images=False)\n# 关闭后，远程图片将以 [图片: alt] 文字占位替代，不发起任何网络请求\n```\n\n- 对不可信来源的 Markdown 文档，请先审阅图片 URL，避免向攻击者控制的端点泄露网络元数据。\n\n---\n\n## ✨ 功能特点\n\n| 功能 | 描述 |\n|------|------|\n| 🚀 **一键转换** | Markdown 转 Word 公文格式，简单易用 |\n| 📋 **标准遵循** | 严格按照 GB/T 9704-2012 党政机关公文格式标准 |\n| 🤖 **多智能体兼容** | 支持 OpenClaw、Hermes Agent、Claude Code 等 AI 智能体 |\n| 🔄 **双重输出** | 一份内容，同时生成 Markdown（供机器读）和 Word（供人读） |\n| 📊 **自动化支持** | 支持定时任务自动生成简报、周报、月报 |\n| 📦 **易于集成** | 提供标准 Python API，便于其他系统集成 |\n\n---\n\n## 🆕 v1.1.0 新特性\n\n- 引入 **markdown-it-py** 解析器，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- **加粗文本**自动转为楷体加粗，*斜体文本*自动转为楷体\n\n---\n\n## 🚀 快速开始\n\n### 环境要求\n\n| 组件 | 要求 |\n|------|------|\n| 操作系统 | Windows 10/11、Linux、macOS |\n| Python | 3.8+（支持 3.11 / 3.12 / 3.13） |\n| 依赖 | python-docx ~= 1.1.0, markdown-it-py ~= 3.0.0 |\n\n### 安装方法\n\n**方式一：使用 pip 安装**\n```bash\npip install \"python-docx~=1.1.0\" \"markdown-it-py~=3.0.0\"\n```\n\n**方式二：克隆仓库**\n```bash\ngit clone https://github.com/EdwardWason/official-doc.git\ncd official-doc\npip install -r requirements.txt\n```\n\n### 使用示例\n\n```python\nfrom official_doc import md_to_docx\n\n# Markdown 内容\nmd_content = \"\"\"# 工作简报\n\n## 一、上周工作总结\n\n本周完成了系统升级任务，主要包括：\n\n### （一）主要工作\n1. 完成服务器部署\n2. 完成数据迁移\n3. 完成测试验证\n\n### （二）存在问题\n部分功能需要进一步优化。\n\n### （三）下周计划\n继续推进优化工作。\n\"\"\"\n\n# 转换为公文格式\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\nprint(\"转换成功\" if success else \"转换失败\")\n```\n\n---\n\n## 📋 公文格式规范（GB/T 9704-2012）\n\n### 页面设置\n\n| 设置项 | 规范值 |\n|--------|--------|\n| 纸张尺寸 | A4 (210mm × 297mm) |\n| 上边距 | 3.7cm |\n| 下边距 | 3.5cm |\n| 左边距 | 2.8cm |\n| 右边距 | 2.6cm |\n| 行间距 | 固定值 26 磅 |\n| 首行缩进 | 2字符（640 twips） |\n\n### 字体规范\n\n| 元素 | Markdown 标记 | 字体 | 字号 |\n|------|--------------|------|------|\n| 大标题 | `#`（单个） | 方正小标宋简体 | 二号 |\n| 一级标题 | `##` / `#`（多个） | 黑体 | 三号 |\n| 二级标题 | `###` | 楷体_GB2312 加粗 | 三号 |\n| 三级标题 | `####` | 仿宋_GB2312 | 三号 |\n| 正文 | 普通文本 | 仿宋_GB2312 | 三号 |\n| 页码 | - | 宋体 | 四号 |\n\n### 标题编号规则\n\n| 层级 | 判断条件 | 格式示例 |\n|------|----------|----------|\n| 大标题 | 文档中仅一个 `#` | 公文标题（居中，不加序号） |\n| 一级标题 | `##` 或多个 `#` | 一、章节名称 |\n| 二级标题 | `###` | （一）小节名称 |\n| 三级标题 | `####` | 1. 项目名称 |\n\n### 支持的 Markdown 元素\n\n| 元素 | Markdown 语法 | 说明 |\n|------|--------------|------|\n| 标题 | `#` `##` `###` `####` | 智能标题判断 |\n| 段落 | 普通文本 | 支持多行段落 |\n| 有序列表 | `1. 2. 3.` | 支持嵌套列表 |\n| 无序列表 | `- - -` | 支持嵌套列表 |\n| 表格 | `\\| 列 \\| 列 \\|` | 完整表格支持 |\n| 图片 | `![alt](url)` | 行内图片 |\n| 超链接 | `[文本](url)` | 超链接 |\n| 加粗 | `**文本**` | 自动转为楷体加粗 |\n| 斜体 | `*文本*` | 自动转为楷体 |\n| 代码块 | `` ```代码``` `` | 等宽字体格式 |\n| 分隔线 | `---` | 页面分隔 |\n\n---\n\n## 🔧 AI Agent 集成指南\n\n### OpenClaw 集成\n\n```python\nfrom official_doc import md_to_docx\nfrom openclaw import Skill\n\nclass OfficialDocSkill(Skill):\n    name = \"official-doc\"\n    description = \"公文格式转换 - 将 Markdown 转为党政机关公文格式\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output_公文格式.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"公文格式转换完成\" if success else \"转换失败\"\n        }\n```\n\n### Hermes Agent 集成\n\n```python\n# 调用示例\nfrom hermes import Agent\n\nagent = Agent()\nresult = agent.run_skill(\n    skill=\"official-doc\",\n    md_content=report_content,\n    output_path=\"weekly_report.docx\"\n)\n```\n\n### 定时任务配置\n\n```python\nimport schedule\nimport time\nfrom official_doc import md_to_docx\n\ndef generate_daily_report():\n    content = generate_report_content()\n    today = time.strftime(\"%Y-%m-%d\")\n    md_to_docx(content, f\"工作简报_{today}_公文格式.docx\")\n\n# 每周一至周五 9:00 自动执行\nschedule.every().monday.at(\"09:00\").do(generate_daily_report)\nschedule.every().tuesday.at(\"09:00\").do(generate_daily_report)\nschedule.every().wednesday.at(\"09:00\").do(generate_daily_report)\nschedule.every().thursday.at(\"09:00\").do(generate_daily_report)\nschedule.every().friday.at(\"09:00\").do(generate_daily_report)\n\nwhile True:\n    schedule.run_pending()\n    time.sleep(60)\n```\n\n---\n\n## 📁 项目结构\n\n```\nofficial-doc/\n├── src/                      # 源代码目录\n│   ├── __init__.py          # 包初始化\n│   └── md2docx.py           # 核心转换模块\n├── skill.json               # AI Agent 技能配置\n├── setup.py                 # 安装配置\n├── requirements.txt         # 依赖清单\n├── README.md                # 英文文档\n├── README_CN.md             # 中文文档\n├── CHANGELOG.md             # 更新日志\n├── LICENSE                  # MIT 许可证\n└── .gitignore               # Git 忽略配置\n```\n\n---\n\n## 🧪 测试验证\n\n```bash\n# 创建测试脚本\ncat > test_official_doc.py << 'EOF'\nfrom official_doc import md_to_docx\n\ndef test_basic_conversion():\n    md_content = \"\"\"# 测试文档\n\n## 一、测试标题\n\n这是一个测试段落。\n\n### （一）二级标题\n\n1. 列表项一\n2. 列表项二\n\n**加粗文本** 测试。\n\"\"\"\n    success = md_to_docx(md_content, 'test_output.docx')\n    assert success == True\n    print(\"✓ 基本转换测试通过\")\n\nif __name__ == \"__main__\":\n    test_basic_conversion()\n    print(\"\\n✅ 所有测试通过！\")\nEOF\n\n# 运行测试\npython test_official_doc.py\n```\n\n---\n\n## 📜 许可证\n\nMIT License\n\n---\n\n## 🤝 贡献指南\n\n欢迎提交 Issue 和 Pull Request！\n\n1. Fork 本仓库\n2. 创建功能分支 (`git checkout -b feature/AmazingFeature`)\n3. 提交更改 (`git commit -m 'feat: Add some AmazingFeature'`)\n4. 推送到分支 (`git push origin feature/AmazingFeature`)\n5. 打开 Pull Request\n\n---\n\n## 📞 联系方式\n\n- **GitHub**: [https://github.com/EdwardWason/official-doc](https://github.com/EdwardWason/official-doc)\n- **Issues**: [https://github.com/EdwardWason/official-doc/issues](https://github.com/EdwardWason/official-doc/issues)\n\n---\n\n*Built with ❤️ for LLM + AI Agent 生态*\n\nFile v1.1.4:skill-card.md\n\n## Description:\n\nOfficial Doc converts Markdown into Word .docx files formatted for the GB/T 9704-2012 Chinese government document standard, with optional remote image embedding.\n\nThis skill is ready for commercial/non-commercial use.\n\n## Publisher:\n\n[edwardwason](https://clawhub.ai/user/edwardwason)\n\n### License/Terms of Use:\n\nMIT-0\n\n## Use Case:\n\nDevelopers and agents use this skill to turn generated or supplied Markdown reports, briefs, and similar documents into GB/T 9704-2012 styled Word files. It handles formatting conversion only and does not review content or add official-document decorations.\n\n### Deployment Geography for Use:\n\nGlobal\n\n## Known Risks and Mitigations:\n\nRisk: Processing untrusted Markdown with remote images can trigger outbound network requests and expose host or network metadata.\n\nMitigation: Use trusted Markdown, run the skill in a sandbox with restricted outbound network access, or disable image downloads with download_images=False.\n\n## Reference(s):\n\n- [ClawHub skill page](https://clawhub.ai/edwardwason/skills/gongwen-formatter)\n- [Project homepage](https://github.com/EdwardWason/official-doc)\n- [Project README](https://github.com/EdwardWason/official-doc/blob/main/README.md)\n- [Project releases](https://github.com/EdwardWason/official-doc/releases)\n\n## Skill Output:\n\n**Output Type(s):** [Files, Text]\n\n**Output Format:** [Word .docx file with a success flag and output path]\n\n**Output Parameters:** [1D]\n\n**Other Properties Related to Output:** [Remote image URLs may be embedded by default; callers can set download_images=False to replace remote images with text placeholders.]\n\n## Skill Version(s):\n\n1.1.4 (source: release evidence, frontmatter, changelog, setup.py)\n\n## Ethical Considerations:\n\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment.\n\nFile v1.1.4:skill.json\n\n{\n  \"name\": \"gongwen-formatter\",\n  \"name_cn\": \"公文格式转换\",\n  \"version\": \"1.1.4\",\n  \"description\": \"将 Markdown 文档转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文档\",\n  \"description_en\": \"Convert Markdown documents to Chinese government official document format (GB/T 9704-2012)\",\n  \"author\": \"EdwardWason\",\n  \"license\": \"MIT\",\n  \"homepage\": \"https://github.com/EdwardWason/official-doc\",\n  \"tags\": [\"document\", \"formatter\", \"markdown\", \"word\", \"government\", \"chinese\", \"gb9704\"],\n  \"triggers\": [\"公文格式转换\", \"转换公文格式\"],\n  \"platform\": [\"windows\", \"linux\", \"macos\"],\n  \"python_version\": \">=3.8\",\n  \"dependencies\": [\"python-docx~=1.1.0\", \"markdown-it-py~=3.0.0\"],\n\n  \"skills\": {\n    \"name\": \"gongwen-formatter\",\n    \"type\": \"formatter\",\n    \"category\": \"文档处理\"\n  },\n\n  \"input\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"md_content\": {\n        \"type\": \"string\",\n        \"description\": \"Markdown 格式的文本内容\"\n      },\n      \"output_path\": {\n        \"type\": \"string\",\n        \"description\": \"输出 Word 文件路径\"\n      }\n    },\n    \"required\": [\"md_content\", \"output_path\"]\n  },\n\n  \"output\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"success\": {\n        \"type\": \"boolean\",\n        \"description\": \"转换是否成功\"\n      },\n      \"output_path\": {\n        \"type\": \"string\",\n        \"description\": \"输出文件路径\"\n      }\n    }\n  },\n\n  \"examples\": [\n    {\n      \"name\": \"基本转换\",\n      \"code\": \"from official_doc import md_to_docx\\n\\nmd_content = '''# 大标题\\n\\n## 一级标题\\n\\n这是正文内容。\\n'''\\nmd_to_docx(md_content, 'output.docx')\"\n    },\n    {\n      \"name\": \"含表格和图片\",\n      \"code\": \"from official_doc import md_to_docx\\n\\nmd_content = '''# 工作简报\\n\\n## 工作总结\\n\\n| 项目 | 进度 |\\n|------|------|\\n| A项目 | 80% |\\n| B项目 | 60% |\\n\\n![架构图](https://example.com/arch.png)\\n'''\\nmd_to_docx(md_content, '简报_公文格式.docx')\"\n    },\n    {\n      \"name\": \"AI Agent 集成\",\n      \"code\": \"from official_doc import md_to_docx\\n\\ndef generate_report(content):\\n    # 保存 Markdown 版本\\n    with open('report.md', 'w', encoding='utf-8') as f:\\n        f.write(content)\\n    # 生成公文格式\\n    md_to_docx(content, 'report_公文格式.docx')\\n    return '报告已生成'\"\n    }\n  ],\n\n  \"format_standard\": {\n    \"name\": \"GB/T 9704-2012\",\n    \"description\": \"党政机关公文格式\",\n    \"page_settings\": {\n      \"top_margin\": \"3.7cm\",\n      \"bottom_margin\": \"3.5cm\",\n      \"left_margin\": \"2.8cm\",\n      \"right_margin\": \"2.6cm\",\n      \"line_spacing\": \"26pt\",\n      \"first_line_indent\": \"2字符(640twips)\"\n    },\n    \"font_settings\": {\n      \"title\": {\"font\": \"方正小标宋简体\", \"size\": \"二号\", \"note\": \"单个#标题居中不加序号，多个#标题加序号\"},\n      \"level1\": {\"font\": \"黑体\", \"size\": \"三号\"},\n      \"level2\": {\"font\": \"楷体_GB2312\", \"size\": \"三号\", \"bold\": true},\n      \"level3\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\", \"bold\": true},\n      \"body\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\"},\n      \"table_header\": {\"font\": \"黑体\", \"size\": \"三号\"},\n      \"table_body\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\"},\n      \"link\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\", \"color\": \"蓝色\", \"underline\": true}\n    },\n    \"supported_elements\": {\n      \"headings\": \"# / ## / ### / #### 智能层级判断\",\n      \"paragraphs\": \"正文段落，首行缩进2字符\",\n      \"ordered_list\": \"有序列表，支持嵌套\",\n      \"unordered_list\": \"无序列表，支持嵌套\",\n      \"table\": \"Markdown表格 → Word表格\",\n      \"image\": \"![alt](url) → 居中图片+图注\",\n      \"link\": \"[text](url) → 蓝色下划线超链接\",\n      \"bold\": \"**text** → 黑体\",\n      \"italic\": \"*text* → 楷体加粗\",\n      \"code_block\": \"```代码块 → 仿宋小四号\",\n      \"hr\": \"--- 水平线忽略\"\n    }\n  }\n}\n\nFile v1.1.4:requirements.txt\n\npython-docx~=1.1.0\nmarkdown-it-py~=3.0.0\n\nArchive v1.1.3: 11 files, 24711 bytes\n\nFiles: CHANGELOG.md (3757b), README_CN.md (8493b), README.md (7862b), requirements.txt (41b), setup.py (1117b), skill-card.md (2216b), skill.json (3925b), skill.md (9324b), src/__init__.py (324b), src/md2docx.py (26822b), _meta.json (136b)\n\nFile v1.1.3:skill.md\n\n---\nslug: gongwen-formatter\nname: gongwen-formatter\ndisplayName: Gongwen Formatter\nname_cn: 公文格式转换\nversion: 1.1.3\nauthor: EdwardWason\nlicense: MIT\nhomepage: https://github.com/EdwardWason/official-doc\ndescription: 公文格式转换 — 将 Markdown 转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文件。可选能力：远程图片下载（仅 http/https/data:image，可通过 download_images=False 关闭）。Do NOT：不做文体识别、不添加红头/版记/落款、不做内容审核。\nsummary: 将 Markdown 转换为符合 GB/T 9704-2012 标准的党政机关公文格式 Word 文件。\nallowed-tools:\n  - filesystem (write .docx output)\n  - net.http (GET image download, http/https only, toggleable via download_images=False)\ntriggers:\n  - 公文格式转换\n  - 转换公文格式\n---\n\n# 📄 official-doc - 公文格式转换\n\n## 技能信息\n\n### 基本信息\n| 属性 | 说明 |\n|------|------|\n| **名称** | official-doc |\n| **中文名称** | 公文格式转换 |\n| **版本** | 1.1.3 |\n| **作者** | EdwardWason |\n| **许可证** | MIT |\n| **主页** | https://github.com/EdwardWason/official-doc |\n\n### 触发词\n- **公文格式转换**\n- **转换公文格式**\n\n### 功能描述\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\n\n### 适用场景\n- AI Agent 生成公文格式报告\n- 定时任务自动生成工作简报、周报、月报\n- Markdown 文档批量转换为标准公文格式\n- 行业研报格式标准化输出\n\n### Do NOT（超出范围）\n- ❌ **不做文体识别**：不区分通知/通报/报告/请示等公文文种，统一按 Markdown 结构转换\n- ❌ **不添加公文装饰要素**：不生成红头、版记、落款、签发人、密级标识等\n- ❌ **不做内容审核**：不审查内容合规性、不校验公文要素完整性\n- ❌ **不做双向转换**：仅支持 Markdown → Word 单向，不支持 Word → Markdown 反向\n- ❌ **不读取本地敏感文件**：不读取 memory/profile/credentials 等任何用户数据\n\n### v1.1.0 新增功能\n- 引入 markdown-it-py 解析器，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- 加粗文本自动转为黑体，斜体文本自动转为楷体\n\n### v1.1.2 安全升级（响应 ClawHub SkillSpector 审计）\n- `download_image()` 增加 URL scheme 白名单（仅 `http://`/`https://`/`data:image`），防止 SSRF\n- `md_to_docx()` 新增 `download_images=True` 参数，受限网络环境可设为 `False` 完全关闭网络请求\n- `_handle_standalone_image()` 关闭图片下载时以 `[图片: alt]` 文字占位替代\n- `requirements.txt` 改用 `~=` 兼容版本锁定（python-docx~=1.1.0、markdown-it-py~=3.0.0）\n- README 中英文版增加 \"图片下载网络请求说明 / Network Access Disclosure\" 用户警告段落\n\n### v1.1.3 修复（响应 v1.1.2 后 SkillSpector 二次审计）\n- 修复 v1.1.2 漏改：README/skill.md/skill.json 中残留的 `>=` 全部改为 `~=`（依赖版本一致性）\n- frontmatter 增加 `allowed-tools` 字段，声明 filesystem（写 .docx）和 net.http（图片下载，可关闭）两项权限\n- 7 项 findings 中：2 项真实漏改（本次修复）、3 项 stale（已修复但被重复扫描，本次通过 allowed-tools 增强声明）、2 项过度修改（保留现有设计，不采纳）\n\n---\n\n## 权限声明\n\n本技能执行过程中涉及的系统能力（用户须知）：\n\n| 能力类别 | 是否使用 | 说明 |\n|---------|---------|------|\n| **网络访问** | ✅ 仅 http/https 图片下载 | 默认开启；可通过 `download_images=False` 关闭；URL scheme 白名单防止 SSRF |\n| **文件读写** | ✅ 仅写入输出 .docx 和临时图片缓存 | 临时图片下载后立即 `os.unlink` 删除；不读取用户其他文件 |\n| **环境变量** | ❌ 不读取 | 不依赖任何环境变量，无凭证收集 |\n| **subprocess 调用** | ❌ 不调用 | 纯 Python 实现，不执行 shell 命令 |\n| **外部 API 调用** | ❌ 不调用 | 不向任何外部 API 推送数据 |\n\n**最小权限原则**：本技能仅做 Markdown→Word 格式转换，不涉及任何外部数据上传、凭证收集或子进程调用。\n\n---\n\n## 输入参数\n\n| 参数名 | 类型 | 必填 | 说明 |\n|--------|------|------|------|\n| `md_content` | string | ✅ | Markdown 格式的文本内容 |\n| `output_path` | string | ✅ | 输出 Word 文件路径（.docx） |\n| `download_images` | bool | ❌ | 是否下载远程图片并嵌入 Word，默认 `True`；受限网络环境设为 `False` 跳过网络请求 |\n\n---\n\n## 输出结果\n\n| 字段 | 类型 | 说明 |\n|------|------|------|\n| `success` | boolean | 转换是否成功 |\n| `output_path` | string | 输出文件路径 |\n\n---\n\n## 使用示例\n\n### 基本使用\n```python\nfrom official_doc import md_to_docx\n\nmd_content = \"\"\"# 工作简报\n\n## 一、上周工作总结\n\n本周完成了系统升级任务。\n\n### （一）主要工作\n1. 服务器部署\n2. 数据迁移\n3. 测试验证\n\n### （二）下周计划\n继续推进优化工作。\n\"\"\"\n\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\nprint(\"转换成功\" if success else \"转换失败\")\n```\n\n### 含表格和图片\n```python\nfrom official_doc import md_to_docx\n\nmd_content = \"\"\"# 项目进度表\n\n## 工作进展\n\n| 项目名称 | 负责人 | 进度 | 备注 |\n|----------|--------|------|------|\n| A项目 | 张三 | 80% | 正常 |\n| B项目 | 李四 | 60% | 需加速 |\n\n![架构图](https://example.com/arch.png)\n\n详细说明请参考[官方文档](https://example.com)。\n\"\"\"\n\nmd_to_docx(md_content, \"进度表_公文格式.docx\")\n```\n\n### AI Agent 集成\n```python\nfrom official_doc import md_to_docx\n\nclass OfficialDocSkill:\n    name = \"official-doc\"\n    description = \"公文格式转换 - 将 Markdown 转为党政机关公文格式\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output_公文格式.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"公文格式转换完成\" if success else \"转换失败\"\n        }\n```\n\n### 定时任务\n```python\nimport schedule\nimport time\nfrom official_doc import md_to_docx\n\ndef generate_report():\n    content = generate_report_content()\n    today = time.strftime(\"%Y-%m-%d\")\n    md_to_docx(content, f\"工作简报_{today}_公文格式.docx\")\n\nschedule.every().monday.at(\"09:00\").do(generate_report)\n```\n\n---\n\n## 格式规范\n\n### 页面设置\n| 设置项 | 规范值 |\n|--------|--------|\n| 上边距 | 3.7cm |\n| 下边距 | 3.5cm |\n| 左边距 | 2.8cm |\n| 右边距 | 2.6cm |\n| 行间距 | 固定值 26 磅 |\n| 首行缩进 | 2字符（640 twips） |\n\n### 字体设置\n| 元素 | Markdown | 字体 | 字号 |\n|------|----------|------|------|\n| 大标题（单个#） | `#` | 方正小标宋简体 | 二号 |\n| 一级标题（多个#） | `#` | 黑体 | 三号 |\n| 二级标题 | `##` | 黑体 | 三号 |\n| 三级标题 | `###` | 楷体_GB2312 | 三号 |\n| 四级标题 | `####` | 仿宋_GB2312 | 三号 |\n| 正文 | 普通文本 | 仿宋_GB2312 | 三号 |\n| 加粗文本 | `**text**` | 黑体 | 三号 |\n| 斜体文本 | `*text*` | 楷体_GB2312 | 三号 |\n| 链接 | `[text](url)` | 仿宋_GB2312 蓝色下划线 | 三号 |\n| 表格表头 | `| 表头 |` | 黑体 | 三号 |\n| 表格内容 | `| 内容 |` | 仿宋_GB2312 | 三号 |\n| 代码块 | ` ``` ` | 仿宋_GB2312 | 小四号 |\n| 页码 | - | 宋体 | 四号 |\n\n### 标题编号规则\n| 层级 | 格式示例 | 说明 |\n|------|----------|------|\n| 大标题 | 公文标题 | 单个#标题居中，不加序号 |\n| 一级标题 | 一、章节名称 | 多个#标题自动加序号 |\n| 二级标题 | 一、章节名称 | ## 标题自动加序号 |\n| 三级标题 | （一）小节名称 | ### 标题加中文括号序号 |\n| 四级标题 | 正文格式 | #### 标题不加序号 |\n\n### 支持的 Markdown 元素\n| 元素 | 转换效果 |\n|------|----------|\n| 标题 `# / ## / ### / ####` | 智能层级判断 + 自动编号 |\n| 段落 | 正文仿宋三号，首行缩进2字符 |\n| 有序列表 `1. 2. 3.` | 自动编号，支持嵌套 |\n| 无序列表 `- / *` | 圆点标记，支持嵌套 |\n| 表格 `| ... |` | Word表格，表头黑体 |\n| 图片 `![alt](url)` | 居中图片 + 图注 |\n| 链接 `[text](url)` | 蓝色下划线超链接 |\n| 加粗 `**text**` | 黑体 |\n| 斜体 `*text*` | 楷体 |\n| 代码块 ` ``` ` | 仿宋小四号 |\n| 水平线 `---` | 忽略 |\n\n---\n\n## 依赖要求\n\n| 依赖 | 版本 |\n|------|------|\n| Python | >= 3.8 |\n| python-docx | ~= 1.1.0 |\n| markdown-it-py | ~= 3.0.0 |\n\n---\n\n## 支持平台\n\n- ✅ Windows 10/11\n- ✅ Linux\n- ✅ macOS\n\n---\n\n## 项目链接\n\n- GitHub: https://github.com/EdwardWason/official-doc\n- Release: https://github.com/EdwardWason/official-doc/releases\n- README: https://github.com/EdwardWason/official-doc/blob/main/README.md\n\nFile v1.1.3:README.md\n\n# 📄 Official Doc - Document Format Converter\n\n🇨🇳 [中文文档](README_CN.md) | 🇺🇸 English\n\nConvert Markdown documents to Chinese government official document format (GB/T 9704-2012) Word documents. Focused on formatting conversion only — does not add red header, record mark, signature block, or other decorative elements of official documents.\n\n---\n\n## ⚠️ Important Notes\n\nThis tool only provides formatting functionality and does not review content. Please ensure that the official documents generated using this tool comply with relevant regulations and requirements.\n\n### Network Access Disclosure for Image Download\n\n- When the Markdown contains remote images via `![alt](http/https URL)`, this tool will **automatically issue outbound network requests** to download and embed them into the Word document.\n- Only `http://`, `https://`, and `data:image` schemes are allowed; other schemes (e.g., `file://`, `ftp://`) are silently skipped to prevent SSRF.\n- **Privacy & Compliance Notice**: In restricted network environments (intranet, classified networks, air-gapped systems), disable remote image download by passing `download_images=False`:\n\n```python\nmd_to_docx(md_content, output_path, download_images=False)\n# When disabled, remote images are replaced with a [Image: alt] text placeholder, with no network requests made.\n```\n\n- For untrusted Markdown sources, review image URLs beforehand to avoid leaking network metadata to attacker-controlled endpoints.\n\n---\n\n## ✨ Features\n\n| Feature | Description |\n|---------|-------------|\n| 🚀 **One-click Conversion** | Convert Markdown to Word official document format easily |\n| 📋 **Standard Compliance** | Strictly follows GB/T 9704-2012 standard |\n| 🤖 **Multi-Agent Support** | Works with OpenClaw, Hermes Agent, Claude Code, etc. |\n| 🔄 **Dual Output** | Generate both Markdown (for machines) and Word (for humans) |\n| 📊 **Automation Ready** | Supports scheduled tasks for automatic report generation |\n| 📦 **Easy Integration** | Provides standard Python API for system integration |\n\n---\n\n## 🆕 v1.1.0 New Features\n\n- Introduced **markdown-it-py** parser, supporting multi-line paragraphs and nested lists\n- Smart `#` heading detection: a single `#` is treated as a main title (centered, no numbering); multiple `#` headings are treated as first-level headings (with numbering)\n- First line indent precisely aligned with national standard (640 twips = width of 2 Size-3 Chinese characters)\n- Added support for **tables, images, hyperlinks, code blocks, and nested lists**\n- **Bold text** is automatically converted to SimHei (黑体); *italic text* is automatically converted to KaiTi (楷体)\n\n---\n\n## 🚀 Quick Start\n\n### System Requirements\n\n| Component | Requirement |\n|-----------|-------------|\n| OS | Windows 10/11, Linux, macOS |\n| Python | 3.8+ (3.11 / 3.12 / 3.13 supported) |\n| Dependency | python-docx ~= 1.1.0, markdown-it-py ~= 3.0.0 |\n\n### Installation\n\n**Method 1: Using pip**\n```bash\npip install \"python-docx~=1.1.0\" \"markdown-it-py~=3.0.0\"\n```\n\n**Method 2: Clone repository**\n```bash\ngit clone https://github.com/EdwardWason/official-doc.git\ncd official-doc\npip install -r requirements.txt\n```\n\n### Usage Example\n\n```python\nfrom official_doc import md_to_docx\n\n# Markdown content\nmd_content = \"\"\"# Weekly Report\n\n## 1. Work Summary\n\nCompleted system upgrade tasks including:\n\n### 1.1 Main Tasks\n1. Server deployment\n2. Data migration\n3. Testing and verification\n\n### 1.2 Issues\nSome features need further optimization.\n\n### 1.3 Next Week Plan\nContinue optimization work.\n\"\"\"\n\n# Convert to official document format\nsuccess = md_to_docx(md_content, \"weekly_report.docx\")\nprint(\"Conversion successful\" if success else \"Conversion failed\")\n```\n\n---\n\n## 📋 Format Specifications (GB/T 9704-2012)\n\n### Page Settings\n\n| Setting | Value |\n|---------|-------|\n| Paper Size | A4 (210mm × 297mm) |\n| Top Margin | 3.7cm |\n| Bottom Margin | 3.5cm |\n| Left Margin | 2.8cm |\n| Right Margin | 2.6cm |\n| Line Spacing | 26pt (fixed) |\n| First Line Indent | 2 characters (640 twips) |\n\n### Font Settings\n\n| Element | Markdown | Font | Size |\n|---------|----------|------|------|\n| Title | `#` (single) | Fangzheng Xiaobiao Song | 2nd |\n| Heading 1 | `##` / `#` (multiple) | Hei Ti | 3rd |\n| Heading 2 | `###` | Kai Ti_GB2312 | 3rd |\n| Heading 3 | `####` | Fang Song_GB2312 | 3rd |\n| Body | Normal | Fang Song_GB2312 | 3rd |\n| Page Number | - | Song Ti | 4th |\n\n### Heading Numbering Rules\n\n| Level | Condition | Format Example |\n|-------|-----------|---------------|\n| Title | Single `#` in document | Document Title (centered, no numbering) |\n| Heading 1 | `##` or multiple `#` | I. Section Name |\n| Heading 2 | `###` | (I) Subsection Name |\n| Heading 3 | `####` | 1. Item Name |\n\n### Supported Markdown Elements\n\n| Element | Markdown Syntax | Notes |\n|---------|----------------|-------|\n| Heading | `#` `##` `###` `####` | Smart title detection |\n| Paragraph | Plain text | Multi-line paragraph support |\n| Ordered List | `1. 2. 3.` | Nested list support |\n| Unordered List | `- - -` | Nested list support |\n| Table | `\\| col \\| col \\|` | Full table support |\n| Image | `![alt](url)` | Inline image |\n| Link | `[text](url)` | Hyperlink |\n| Bold | `**text**` | Auto-convert to Hei Ti |\n| Italic | `*text*` | Auto-convert to Kai Ti |\n| Code Block | `` ```code``` `` | Monospace formatting |\n| Horizontal Rule | `---` | Page separator |\n\n---\n\n## 🔧 AI Agent Integration\n\n### OpenClaw Integration\n\n```python\nfrom official_doc import md_to_docx\nfrom openclaw import Skill\n\nclass OfficialDocSkill(Skill):\n    name = \"official-doc\"\n    description = \"Convert Markdown to Chinese government official document format\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"Conversion completed\" if success else \"Conversion failed\"\n        }\n```\n\n### Hermes Agent Integration\n\n```python\nfrom hermes import Agent\n\nagent = Agent()\nresult = agent.run_skill(\n    skill=\"official-doc\",\n    md_content=report_content,\n    output_path=\"weekly_report.docx\"\n)\n```\n\n---\n\n## 📁 Project Structure\n\n```\nofficial-doc/\n├── src/                      # Source code\n│   ├── __init__.py          # Package initialization\n│   └── md2docx.py           # Core conversion module\n├── skill.json               # AI Agent skill configuration\n├── setup.py                 # Installation configuration\n├── requirements.txt         # Dependencies\n├── README.md                # English documentation\n├── README_CN.md             # Chinese documentation\n├── CHANGELOG.md             # Changelog\n├── LICENSE                  # MIT License\n└── .gitignore               # Git ignore rules\n```\n\n---\n\n## 🧪 Testing\n\n```bash\ncat > test_official_doc.py << 'EOF'\nfrom official_doc import md_to_docx\n\ndef test_conversion():\n    md_content = \"\"\"# Test Document\n\n## 1. Test Title\n\nThis is a test paragraph.\n\n### 1.1 Subtitle\n\n**Bold text** test.\n\"\"\"\n    success = md_to_docx(md_content, 'test_output.docx')\n    assert success == True\n    print(\"✓ Test passed\")\n\nif __name__ == \"__main__\":\n    test_conversion()\n    print(\"✅ All tests passed!\")\nEOF\n\npython test_official_doc.py\n```\n\n---\n\n## 📜 License\n\nMIT License\n\n---\n\n## 🤝 Contributing\n\nWelcome to submit Issues and Pull Requests!\n\n1. Fork this repository\n2. Create feature branch (`git checkout -b feature/AmazingFeature`)\n3. Commit changes (`git commit -m 'feat: Add some AmazingFeature'`)\n4. Push to branch (`git push origin feature/AmazingFeature`)\n5. Open Pull Request\n\n---\n\n\n*Built with ❤️ for LLM + AI Agent Ecosystem*\n\nFile v1.1.3:_meta.json\n\n{\n  \"ownerId\": \"kn75zj7vzdyvap84adxa8heyyd82f5eh\",\n  \"slug\": \"gongwen-formatter\",\n  \"version\": \"1.1.3\",\n  \"publishedAt\": 1784076192652\n}\n\nFile v1.1.3:CHANGELOG.md\n\n# Changelog\n\n本文件记录 official-doc（gongwen-formatter）所有版本的变更。\n\n格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.0.0/)，\n版本号遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/)。\n\n## [1.1.3] - 2026-07-14\n\n### 修复（响应 v1.1.2 后 SkillSpector 二次审计 7 findings）\n\n#### Fixed\n- 修复 v1.1.2 漏改：README.md / README_CN.md / skill.md / skill.json 中残留的 `>=` 全部改为 `~=`（依赖版本一致性）\n  - 根因：v1.1.2 只改了 requirements.txt 和 setup.py，漏改了 README 安装示例、skill.md 依赖表、skill.json dependencies 字段\n  - SkillSpector 扫描所有文件，因此仍报告 `>=` 为 Unpinned Dependencies\n\n#### Added\n- frontmatter 增加 `allowed-tools` 字段，声明 filesystem（写 .docx）和 net.http（图片下载，可关闭）两项权限\n  - 目的：让 ClawHub SkillSpector 能从 frontmatter 识别权限声明，减少 MCP Least Privilege finding\n\n#### SkillSpector v1.1.2 二次审计 7 findings 评估\n| Finding | 评估 | 处理 |\n|---------|------|------|\n| MCP Least Privilege (Medium) | stale — 权限声明已在 v1.1.2 添加 | 本次通过 allowed-tools 增强声明 |\n| Description-Behavior Mismatch (Medium) | 过度修改 — 图片下载是合理功能 | 不采纳，保留现有设计 |\n| Context-Inappropriate Capability (Medium) | 过度修改 — 已有白名单+开关 | 不采纳，保留现有设计 |\n| Missing User Warnings × 2 (Medium) | stale — README 警告已添加 | 等 ClawHub 缓存刷新 |\n| Unpinned Dependencies × 2 (Low) | 真实漏改 — 残留 `>=` | 本次修复 |\n\n## [1.1.2] - 2026-07-14\n\n### 安全升级（响应 ClawHub SkillSpector 审计）\n\n#### Added\n- `md_to_docx()` 新增 `download_images` 参数（默认 `True`），受限网络环境可设为 `False` 完全关闭网络请求\n- `skill.md` 增加\"权限声明\"段落，按最小权限原则披露网络访问/文件读写/不读取环境变量/不调用 subprocess\n- README 中英文版增加 \"图片下载网络请求说明 / Network Access Disclosure for Image Download\" 用户警告段落\n\n#### Security\n- `download_image()` 增加 URL scheme 白名单（仅 `http://`/`https://`/`data:image`），防止 SSRF\n- 其他 scheme（`file://`、`ftp://` 等）静默跳过，不发起网络请求\n- `requirements.txt` 改用 `~=` 兼容版本锁定（`python-docx~=1.1.0`、`markdown-it-py~=3.0.0`），平衡安全与兼容性\n\n## [1.1.1] - 2026-07-13\n\n#### Changed\n- 添加 ClawHub 触发词：`公文格式转换`、`转换公文格式`\n- ClawHub slug 改为 `gongwen-formatter`（`official-doc` 已被占用，`official-` 前缀受保护）\n- 三平台同步发布（GitHub + ClawHub + SkillHub）\n\n## [1.1.0] - 2026-07-12\n\n#### Added\n- 引入 `markdown-it-py` 解析器替代逐行 `split('\\n')`，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个 `#` 视为大标题（居中不加序号），多个 `#` 视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度，1汉字=16pt=320twips）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- 加粗文本（`**text**`）自动转为黑体\n- 斜体文本（`*text*`）自动转为楷体\n\n#### Fixed\n- 黑体字体不再设置 `bold=True`（用户反馈\"黑体不需要加粗处理\"）\n- 移除所有黑体/楷体的 `bold=True` 设置\n\n## [1.0.0] - 2026-07-10\n\n#### Added\n- 初始版本：基于 GB/T 9704-2012 标准，将 Markdown 转换为党政机关公文格式 Word 文档\n- 实现基础标题层级、段落、列表转换\n- 国标页面设置：A4、上 3.7cm/下 3.5cm/左 2.8cm/右 2.6cm、行距 26pt\n- 字体规范：方正小标宋/黑体/楷体_GB2312/仿宋_GB2312/宋体\n\nFile v1.1.3:README_CN.md\n\n# 📄 Official Doc - 公文格式转换\n\n🇨🇳 中文文档 | 🇺🇸 [English](README.md)\n\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\n\n---\n\n## ⚠️ 重要说明\n\n本工具仅提供格式排版功能，不负责内容审核。请确保使用本工具生成的公文内容符合相关规定和要求。\n\n### 关于图片下载的网络请求说明\n\n- 当 Markdown 中包含 `![alt](http/https URL)` 远程图片时，本工具会**自动发起网络请求**下载并嵌入到 Word 文档中。\n- 仅允许 `http://`、`https://` 和 `data:image` 协议；其他 scheme（如 `file://`、`ftp://`）会被静默跳过，防止 SSRF。\n- **隐私与合规提示**：在受限网络环境（内网、保密网络、隔离环境）中使用时，建议通过 `download_images=False` 参数关闭远程图片下载：\n\n```python\nmd_to_docx(md_content, output_path, download_images=False)\n# 关闭后，远程图片将以 [图片: alt] 文字占位替代，不发起任何网络请求\n```\n\n- 对不可信来源的 Markdown 文档，请先审阅图片 URL，避免向攻击者控制的端点泄露网络元数据。\n\n---\n\n## ✨ 功能特点\n\n| 功能 | 描述 |\n|------|------|\n| 🚀 **一键转换** | Markdown 转 Word 公文格式，简单易用 |\n| 📋 **标准遵循** | 严格按照 GB/T 9704-2012 党政机关公文格式标准 |\n| 🤖 **多智能体兼容** | 支持 OpenClaw、Hermes Agent、Claude Code 等 AI 智能体 |\n| 🔄 **双重输出** | 一份内容，同时生成 Markdown（供机器读）和 Word（供人读） |\n| 📊 **自动化支持** | 支持定时任务自动生成简报、周报、月报 |\n| 📦 **易于集成** | 提供标准 Python API，便于其他系统集成 |\n\n---\n\n## 🆕 v1.1.0 新特性\n\n- 引入 **markdown-it-py** 解析器，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- **加粗文本**自动转为黑体，*斜体文本*自动转为楷体\n\n---\n\n## 🚀 快速开始\n\n### 环境要求\n\n| 组件 | 要求 |\n|------|------|\n| 操作系统 | Windows 10/11、Linux、macOS |\n| Python | 3.8+（支持 3.11 / 3.12 / 3.13） |\n| 依赖 | python-docx ~= 1.1.0, markdown-it-py ~= 3.0.0 |\n\n### 安装方法\n\n**方式一：使用 pip 安装**\n```bash\npip install \"python-docx~=1.1.0\" \"markdown-it-py~=3.0.0\"\n```\n\n**方式二：克隆仓库**\n```bash\ngit clone https://github.com/EdwardWason/official-doc.git\ncd official-doc\npip install -r requirements.txt\n```\n\n### 使用示例\n\n```python\nfrom official_doc import md_to_docx\n\n# Markdown 内容\nmd_content = \"\"\"# 工作简报\n\n## 一、上周工作总结\n\n本周完成了系统升级任务，主要包括：\n\n### （一）主要工作\n1. 完成服务器部署\n2. 完成数据迁移\n3. 完成测试验证\n\n### （二）存在问题\n部分功能需要进一步优化。\n\n### （三）下周计划\n继续推进优化工作。\n\"\"\"\n\n# 转换为公文格式\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\nprint(\"转换成功\" if success else \"转换失败\")\n```\n\n---\n\n## 📋 公文格式规范（GB/T 9704-2012）\n\n### 页面设置\n\n| 设置项 | 规范值 |\n|--------|--------|\n| 纸张尺寸 | A4 (210mm × 297mm) |\n| 上边距 | 3.7cm |\n| 下边距 | 3.5cm |\n| 左边距 | 2.8cm |\n| 右边距 | 2.6cm |\n| 行间距 | 固定值 26 磅 |\n| 首行缩进 | 2字符（640 twips） |\n\n### 字体规范\n\n| 元素 | Markdown 标记 | 字体 | 字号 |\n|------|--------------|------|------|\n| 大标题 | `#`（单个） | 方正小标宋简体 | 二号 |\n| 一级标题 | `##` / `#`（多个） | 黑体 | 三号 |\n| 二级标题 | `###` | 楷体_GB2312 | 三号 |\n| 三级标题 | `####` | 仿宋_GB2312 | 三号 |\n| 正文 | 普通文本 | 仿宋_GB2312 | 三号 |\n| 页码 | - | 宋体 | 四号 |\n\n### 标题编号规则\n\n| 层级 | 判断条件 | 格式示例 |\n|------|----------|----------|\n| 大标题 | 文档中仅一个 `#` | 公文标题（居中，不加序号） |\n| 一级标题 | `##` 或多个 `#` | 一、章节名称 |\n| 二级标题 | `###` | （一）小节名称 |\n| 三级标题 | `####` | 1. 项目名称 |\n\n### 支持的 Markdown 元素\n\n| 元素 | Markdown 语法 | 说明 |\n|------|--------------|------|\n| 标题 | `#` `##` `###` `####` | 智能标题判断 |\n| 段落 | 普通文本 | 支持多行段落 |\n| 有序列表 | `1. 2. 3.` | 支持嵌套列表 |\n| 无序列表 | `- - -` | 支持嵌套列表 |\n| 表格 | `\\| 列 \\| 列 \\|` | 完整表格支持 |\n| 图片 | `![alt](url)` | 行内图片 |\n| 超链接 | `[文本](url)` | 超链接 |\n| 加粗 | `**文本**` | 自动转为黑体 |\n| 斜体 | `*文本*` | 自动转为楷体 |\n| 代码块 | `` ```代码``` `` | 等宽字体格式 |\n| 分隔线 | `---` | 页面分隔 |\n\n---\n\n## 🔧 AI Agent 集成指南\n\n### OpenClaw 集成\n\n```python\nfrom official_doc import md_to_docx\nfrom openclaw import Skill\n\nclass OfficialDocSkill(Skill):\n    name = \"official-doc\"\n    description = \"公文格式转换 - 将 Markdown 转为党政机关公文格式\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output_公文格式.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"公文格式转换完成\" if success else \"转换失败\"\n        }\n```\n\n### Hermes Agent 集成\n\n```python\n# 调用示例\nfrom hermes import Agent\n\nagent = Agent()\nresult = agent.run_skill(\n    skill=\"official-doc\",\n    md_content=report_content,\n    output_path=\"weekly_report.docx\"\n)\n```\n\n### 定时任务配置\n\n```python\nimport schedule\nimport time\nfrom official_doc import md_to_docx\n\ndef generate_daily_report():\n    content = generate_report_content()\n    today = time.strftime(\"%Y-%m-%d\")\n    md_to_docx(content, f\"工作简报_{today}_公文格式.docx\")\n\n# 每周一至周五 9:00 自动执行\nschedule.every().monday.at(\"09:00\").do(generate_daily_report)\nschedule.every().tuesday.at(\"09:00\").do(generate_daily_report)\nschedule.every().wednesday.at(\"09:00\").do(generate_daily_report)\nschedule.every().thursday.at(\"09:00\").do(generate_daily_report)\nschedule.every().friday.at(\"09:00\").do(generate_daily_report)\n\nwhile True:\n    schedule.run_pending()\n    time.sleep(60)\n```\n\n---\n\n## 📁 项目结构\n\n```\nofficial-doc/\n├── src/                      # 源代码目录\n│   ├── __init__.py          # 包初始化\n│   └── md2docx.py           # 核心转换模块\n├── skill.json               # AI Agent 技能配置\n├── setup.py                 # 安装配置\n├── requirements.txt         # 依赖清单\n├── README.md                # 英文文档\n├── README_CN.md             # 中文文档\n├── CHANGELOG.md             # 更新日志\n├── LICENSE                  # MIT 许可证\n└── .gitignore               # Git 忽略配置\n```\n\n---\n\n## 🧪 测试验证\n\n```bash\n# 创建测试脚本\ncat > test_official_doc.py << 'EOF'\nfrom official_doc import md_to_docx\n\ndef test_basic_conversion():\n    md_content = \"\"\"# 测试文档\n\n## 一、测试标题\n\n这是一个测试段落。\n\n### （一）二级标题\n\n1. 列表项一\n2. 列表项二\n\n**加粗文本** 测试。\n\"\"\"\n    success = md_to_docx(md_content, 'test_output.docx')\n    assert success == True\n    print(\"✓ 基本转换测试通过\")\n\nif __name__ == \"__main__\":\n    test_basic_conversion()\n    print(\"\\n✅ 所有测试通过！\")\nEOF\n\n# 运行测试\npython test_official_doc.py\n```\n\n---\n\n## 📜 许可证\n\nMIT License\n\n---\n\n## 🤝 贡献指南\n\n欢迎提交 Issue 和 Pull Request！\n\n1. Fork 本仓库\n2. 创建功能分支 (`git checkout -b feature/AmazingFeature`)\n3. 提交更改 (`git commit -m 'feat: Add some AmazingFeature'`)\n4. 推送到分支 (`git push origin feature/AmazingFeature`)\n5. 打开 Pull Request\n\n---\n\n## 📞 联系方式\n\n- **GitHub**: [https://github.com/EdwardWason/official-doc](https://github.com/EdwardWason/official-doc)\n- **Issues**: [https://github.com/EdwardWason/official-doc/issues](https://github.com/EdwardWason/official-doc/issues)\n\n---\n\n*Built with ❤️ for LLM + AI Agent 生态*\n\nFile v1.1.3:skill-card.md\n\n## Description: <br>\nConverts Markdown into GB/T 9704-2012 Chinese government official-document Word files, with optional remote image embedding. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[edwardwason](https://clawhub.ai/user/edwardwason) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and agents use this skill to turn Markdown reports, briefs, and other structured text into formatted .docx files that follow GB/T 9704-2012 layout conventions. It focuses on document formatting and does not classify official document types, add official decorations, or review content compliance. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: Markdown with remote images can trigger outbound HTTP or HTTPS requests during conversion. <br>\nMitigation: Review image URLs before processing untrusted Markdown or pass download_images=False in sensitive or restricted network environments. <br>\nRisk: The generated Word file may look like an official document even though the skill does not review content or validate required official-document elements. <br>\nMitigation: Review generated documents for content, regulatory, and organizational requirements before relying on or distributing them. <br>\n\n\n## Reference(s): <br>\n- [ClawHub skill page](https://clawhub.ai/edwardwason/skills/gongwen-formatter) <br>\n- [Project homepage](https://github.com/EdwardWason/official-doc) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [files, text] <br>\n**Output Format:** [.docx file plus success status and output path] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [Writes a Word document to the requested output path; remote image downloads are optional and can be disabled with download_images=False.] <br>\n\n## Skill Version(s): <br>\n1.1.3 (source: server release evidence and artifact metadata) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nFile v1.1.3:skill.json\n\n{\n  \"name\": \"gongwen-formatter\",\n  \"name_cn\": \"公文格式转换\",\n  \"version\": \"1.1.3\",\n  \"description\": \"将 Markdown 文档转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文档\",\n  \"description_en\": \"Convert Markdown documents to Chinese government official document format (GB/T 9704-2012)\",\n  \"author\": \"EdwardWason\",\n  \"license\": \"MIT\",\n  \"homepage\": \"https://github.com/EdwardWason/official-doc\",\n  \"tags\": [\"document\", \"formatter\", \"markdown\", \"word\", \"government\", \"chinese\", \"gb9704\"],\n  \"triggers\": [\"公文格式转换\", \"转换公文格式\"],\n  \"platform\": [\"windows\", \"linux\", \"macos\"],\n  \"python_version\": \">=3.8\",\n  \"dependencies\": [\"python-docx~=1.1.0\", \"markdown-it-py~=3.0.0\"],\n\n  \"skills\": {\n    \"name\": \"gongwen-formatter\",\n    \"type\": \"formatter\",\n    \"category\": \"文档处理\"\n  },\n\n  \"input\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"md_content\": {\n        \"type\": \"string\",\n        \"description\": \"Markdown 格式的文本内容\"\n      },\n      \"output_path\": {\n        \"type\": \"string\",\n        \"description\": \"输出 Word 文件路径\"\n      }\n    },\n    \"required\": [\"md_content\", \"output_path\"]\n  },\n\n  \"output\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"success\": {\n        \"type\": \"boolean\",\n        \"description\": \"转换是否成功\"\n      },\n      \"output_path\": {\n        \"type\": \"string\",\n        \"description\": \"输出文件路径\"\n      }\n    }\n  },\n\n  \"examples\": [\n    {\n      \"name\": \"基本转换\",\n      \"code\": \"from official_doc import md_to_docx\\n\\nmd_content = '''# 大标题\\n\\n## 一级标题\\n\\n这是正文内容。\\n'''\\nmd_to_docx(md_content, 'output.docx')\"\n    },\n    {\n      \"name\": \"含表格和图片\",\n      \"code\": \"from official_doc import md_to_docx\\n\\nmd_content = '''# 工作简报\\n\\n## 工作总结\\n\\n| 项目 | 进度 |\\n|------|------|\\n| A项目 | 80% |\\n| B项目 | 60% |\\n\\n![架构图](https://example.com/arch.png)\\n'''\\nmd_to_docx(md_content, '简报_公文格式.docx')\"\n    },\n    {\n      \"name\": \"AI Agent 集成\",\n      \"code\": \"from official_doc import md_to_docx\\n\\ndef generate_report(content):\\n    # 保存 Markdown 版本\\n    with open('report.md', 'w', encoding='utf-8') as f:\\n        f.write(content)\\n    # 生成公文格式\\n    md_to_docx(content, 'report_公文格式.docx')\\n    return '报告已生成'\"\n    }\n  ],\n\n  \"format_standard\": {\n    \"name\": \"GB/T 9704-2012\",\n    \"description\": \"党政机关公文格式\",\n    \"page_settings\": {\n      \"top_margin\": \"3.7cm\",\n      \"bottom_margin\": \"3.5cm\",\n      \"left_margin\": \"2.8cm\",\n      \"right_margin\": \"2.6cm\",\n      \"line_spacing\": \"26pt\",\n      \"first_line_indent\": \"2字符(640twips)\"\n    },\n    \"font_settings\": {\n      \"title\": {\"font\": \"方正小标宋简体\", \"size\": \"二号\", \"note\": \"单个#标题居中不加序号，多个#标题加序号\"},\n      \"level1\": {\"font\": \"黑体\", \"size\": \"三号\"},\n      \"level2\": {\"font\": \"楷体_GB2312\", \"size\": \"三号\", \"bold\": true},\n      \"level3\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\", \"bold\": true},\n      \"body\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\"},\n      \"table_header\": {\"font\": \"黑体\", \"size\": \"三号\"},\n      \"table_body\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\"},\n      \"link\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\", \"color\": \"蓝色\", \"underline\": true}\n    },\n    \"supported_elements\": {\n      \"headings\": \"# / ## / ### / #### 智能层级判断\",\n      \"paragraphs\": \"正文段落，首行缩进2字符\",\n      \"ordered_list\": \"有序列表，支持嵌套\",\n      \"unordered_list\": \"无序列表，支持嵌套\",\n      \"table\": \"Markdown表格 → Word表格\",\n      \"image\": \"![alt](url) → 居中图片+图注\",\n      \"link\": \"[text](url) → 蓝色下划线超链接\",\n      \"bold\": \"**text** → 黑体\",\n      \"italic\": \"*text* → 楷体加粗\",\n      \"code_block\": \"```代码块 → 仿宋小四号\",\n      \"hr\": \"--- 水平线忽略\"\n    }\n  }\n}\n\nFile v1.1.3:requirements.txt\n\npython-docx~=1.1.0\nmarkdown-it-py~=3.0.0\n\nArchive v1.1.2: 11 files, 21704 bytes\n\nFiles: CHANGELOG.md (2409b), README_CN.md (7973b), README.md (7216b), requirements.txt (43b), setup.py (1148b), skill-card.md (2693b), skill.json (3925b), skill.md (6349b), src/__init__.py (324b), src/md2docx.py (26477b), _meta.json (136b)\n\nFile v1.1.2:skill.md\n\n---\r\nslug: gongwen-formatter\r\nname: gongwen-formatter\r\ndisplayName: Gongwen Formatter\r\nname_cn: 公文格式转换\r\nversion: 1.1.1\r\nauthor: EdwardWason\r\nlicense: MIT\r\nhomepage: https://github.com/EdwardWason/official-doc\r\ntriggers:\r\n  - 公文格式转换\r\n  - 转换公文格式\r\n---\r\n\r\n# 📄 official-doc - 公文格式转换\r\n\r\n## 技能信息\r\n\r\n### 基本信息\r\n| 属性 | 说明 |\r\n|------|------|\r\n| **名称** | official-doc |\r\n| **中文名称** | 公文格式转换 |\r\n| **版本** | 1.1.1 |\r\n| **作者** | EdwardWason |\r\n| **许可证** | MIT |\r\n| **主页** | https://github.com/EdwardWason/official-doc |\r\n\r\n### 触发词\r\n- **公文格式转换**\r\n- **转换公文格式**\r\n\r\n### 功能描述\r\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\r\n\r\n### 适用场景\r\n- AI Agent 生成公文格式报告\r\n- 定时任务自动生成工作简报、周报、月报\r\n- Markdown 文档批量转换为标准公文格式\r\n- 行业研报格式标准化输出\r\n\r\n### v1.1.0 新增功能\r\n- 引入 markdown-it-py 解析器，支持多行段落、嵌套列表\r\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\r\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\r\n- 新增表格、图片、超链接、代码块、嵌套列表支持\r\n- 加粗文本自动转为黑体，斜体文本自动转为楷体\r\n\r\n---\r\n\r\n## 输入参数\r\n\r\n| 参数名 | 类型 | 必填 | 说明 |\r\n|--------|------|------|------|\r\n| `md_content` | string | ✅ | Markdown 格式的文本内容 |\r\n| `output_path` | string | ✅ | 输出 Word 文件路径（.docx） |\r\n\r\n---\r\n\r\n## 输出结果\r\n\r\n| 字段 | 类型 | 说明 |\r\n|------|------|------|\r\n| `success` | boolean | 转换是否成功 |\r\n| `output_path` | string | 输出文件路径 |\r\n\r\n---\r\n\r\n## 使用示例\r\n\r\n### 基本使用\r\n```python\r\nfrom official_doc import md_to_docx\r\n\r\nmd_content = \"\"\"# 工作简报\r\n\r\n## 一、上周工作总结\r\n\r\n本周完成了系统升级任务。\r\n\r\n### （一）主要工作\r\n1. 服务器部署\r\n2. 数据迁移\r\n3. 测试验证\r\n\r\n### （二）下周计划\r\n继续推进优化工作。\r\n\"\"\"\r\n\r\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\r\nprint(\"转换成功\" if success else \"转换失败\")\r\n```\r\n\r\n### 含表格和图片\r\n```python\r\nfrom official_doc import md_to_docx\r\n\r\nmd_content = \"\"\"# 项目进度表\r\n\r\n## 工作进展\r\n\r\n| 项目名称 | 负责人 | 进度 | 备注 |\r\n|----------|--------|------|------|\r\n| A项目 | 张三 | 80% | 正常 |\r\n| B项目 | 李四 | 60% | 需加速 |\r\n\r\n![架构图](https://example.com/arch.png)\r\n\r\n详细说明请参考[官方文档](https://example.com)。\r\n\"\"\"\r\n\r\nmd_to_docx(md_content, \"进度表_公文格式.docx\")\r\n```\r\n\r\n### AI Agent 集成\r\n```python\r\nfrom official_doc import md_to_docx\r\n\r\nclass OfficialDocSkill:\r\n    name = \"official-doc\"\r\n    description = \"公文格式转换 - 将 Markdown 转为党政机关公文格式\"\r\n\r\n    def execute(self, md_content, output_path=None):\r\n        if output_path is None:\r\n            output_path = \"output_公文格式.docx\"\r\n\r\n        success = md_to_docx(md_content, output_path)\r\n\r\n        return {\r\n            \"success\": success,\r\n            \"output_path\": output_path,\r\n            \"message\": \"公文格式转换完成\" if success else \"转换失败\"\r\n        }\r\n```\r\n\r\n### 定时任务\r\n```python\r\nimport schedule\r\nimport time\r\nfrom official_doc import md_to_docx\r\n\r\ndef generate_report():\r\n    content = generate_report_content()\r\n    today = time.strftime(\"%Y-%m-%d\")\r\n    md_to_docx(content, f\"工作简报_{today}_公文格式.docx\")\r\n\r\nschedule.every().monday.at(\"09:00\").do(generate_report)\r\n```\r\n\r\n---\r\n\r\n## 格式规范\r\n\r\n### 页面设置\r\n| 设置项 | 规范值 |\r\n|--------|--------|\r\n| 上边距 | 3.7cm |\r\n| 下边距 | 3.5cm |\r\n| 左边距 | 2.8cm |\r\n| 右边距 | 2.6cm |\r\n| 行间距 | 固定值 26 磅 |\r\n| 首行缩进 | 2字符（640 twips） |\r\n\r\n### 字体设置\r\n| 元素 | Markdown | 字体 | 字号 |\r\n|------|----------|------|------|\r\n| 大标题（单个#） | `#` | 方正小标宋简体 | 二号 |\r\n| 一级标题（多个#） | `#` | 黑体 | 三号 |\r\n| 二级标题 | `##` | 黑体 | 三号 |\r\n| 三级标题 | `###` | 楷体_GB2312 | 三号 |\r\n| 四级标题 | `####` | 仿宋_GB2312 | 三号 |\r\n| 正文 | 普通文本 | 仿宋_GB2312 | 三号 |\r\n| 加粗文本 | `**text**` | 黑体 | 三号 |\r\n| 斜体文本 | `*text*` | 楷体_GB2312 | 三号 |\r\n| 链接 | `[text](url)` | 仿宋_GB2312 蓝色下划线 | 三号 |\r\n| 表格表头 | `| 表头 |` | 黑体 | 三号 |\r\n| 表格内容 | `| 内容 |` | 仿宋_GB2312 | 三号 |\r\n| 代码块 | ` ``` ` | 仿宋_GB2312 | 小四号 |\r\n| 页码 | - | 宋体 | 四号 |\r\n\r\n### 标题编号规则\r\n| 层级 | 格式示例 | 说明 |\r\n|------|----------|------|\r\n| 大标题 | 公文标题 | 单个#标题居中，不加序号 |\r\n| 一级标题 | 一、章节名称 | 多个#标题自动加序号 |\r\n| 二级标题 | 一、章节名称 | ## 标题自动加序号 |\r\n| 三级标题 | （一）小节名称 | ### 标题加中文括号序号 |\r\n| 四级标题 | 正文格式 | #### 标题不加序号 |\r\n\r\n### 支持的 Markdown 元素\r\n| 元素 | 转换效果 |\r\n|------|----------|\r\n| 标题 `# / ## / ### / ####` | 智能层级判断 + 自动编号 |\r\n| 段落 | 正文仿宋三号，首行缩进2字符 |\r\n| 有序列表 `1. 2. 3.` | 自动编号，支持嵌套 |\r\n| 无序列表 `- / *` | 圆点标记，支持嵌套 |\r\n| 表格 `| ... |` | Word表格，表头黑体 |\r\n| 图片 `![alt](url)` | 居中图片 + 图注 |\r\n| 链接 `[text](url)` | 蓝色下划线超链接 |\r\n| 加粗 `**text**` | 黑体 |\r\n| 斜体 `*text*` | 楷体 |\r\n| 代码块 ` ``` ` | 仿宋小四号 |\r\n| 水平线 `---` | 忽略 |\r\n\r\n---\r\n\r\n## 依赖要求\r\n\r\n| 依赖 | 版本 |\r\n|------|------|\r\n| Python | >= 3.8 |\r\n| python-docx | >= 1.1.0 |\r\n| markdown-it-py | >= 3.0.0 |\r\n\r\n---\r\n\r\n## 支持平台\r\n\r\n- ✅ Windows 10/11\r\n- ✅ Linux\r\n- ✅ macOS\r\n\r\n---\r\n\r\n## 项目链接\r\n\r\n- GitHub: https://github.com/EdwardWason/official-doc\r\n- Release: https://github.com/EdwardWason/official-doc/releases\r\n- README: https://github.com/EdwardWason/official-doc/blob/main/README.md\n\nFile v1.1.2:README.md\n\n# 📄 Official Doc - Document Format Converter\r\n\r\n🇨🇳 [中文文档](README_CN.md) | 🇺🇸 English\r\n\r\nConvert Markdown documents to Chinese government official document format (GB/T 9704-2012) Word documents. Focused on formatting conversion only — does not add red header, record mark, signature block, or other decorative elements of official documents.\r\n\r\n---\r\n\r\n## ⚠️ Important Notes\r\n\r\nThis tool only provides formatting functionality and does not review content. Please ensure that the official documents generated using this tool comply with relevant regulations and requirements.\r\n\r\n---\r\n\r\n## ✨ Features\r\n\r\n| Feature | Description |\r\n|---------|-------------|\r\n| 🚀 **One-click Conversion** | Convert Markdown to Word official document format easily |\r\n| 📋 **Standard Compliance** | Strictly follows GB/T 9704-2012 standard |\r\n| 🤖 **Multi-Agent Support** | Works with OpenClaw, Hermes Agent, Claude Code, etc. |\r\n| 🔄 **Dual Output** | Generate both Markdown (for machines) and Word (for humans) |\r\n| 📊 **Automation Ready** | Supports scheduled tasks for automatic report generation |\r\n| 📦 **Easy Integration** | Provides standard Python API for system integration |\r\n\r\n---\r\n\r\n## 🆕 v1.1.0 New Features\r\n\r\n- Introduced **markdown-it-py** parser, supporting multi-line paragraphs and nested lists\r\n- Smart `#` heading detection: a single `#` is treated as a main title (centered, no numbering); multiple `#` headings are treated as first-level headings (with numbering)\r\n- First line indent precisely aligned with national standard (640 twips = width of 2 Size-3 Chinese characters)\r\n- Added support for **tables, images, hyperlinks, code blocks, and nested lists**\r\n- **Bold text** is automatically converted to SimHei (黑体); *italic text* is automatically converted to KaiTi (楷体)\r\n\r\n---\r\n\r\n## 🚀 Quick Start\r\n\r\n### System Requirements\r\n\r\n| Component | Requirement |\r\n|-----------|-------------|\r\n| OS | Windows 10/11, Linux, macOS |\r\n| Python | 3.8+ (3.11 / 3.12 / 3.13 supported) |\r\n| Dependency | python-docx >= 1.1.0, markdown-it-py >= 3.0.0 |\r\n\r\n### Installation\r\n\r\n**Method 1: Using pip**\r\n```bash\r\npip install python-docx>=1.1.0 markdown-it-py>=3.0.0\r\n```\r\n\r\n**Method 2: Clone repository**\r\n```bash\r\ngit clone https://github.com/EdwardWason/official-doc.git\r\ncd official-doc\r\npip install -r requirements.txt\r\n```\r\n\r\n### Usage Example\r\n\r\n```python\r\nfrom official_doc import md_to_docx\r\n\r\n# Markdown content\r\nmd_content = \"\"\"# Weekly Report\r\n\r\n## 1. Work Summary\r\n\r\nCompleted system upgrade tasks including:\r\n\r\n### 1.1 Main Tasks\r\n1. Server deployment\r\n2. Data migration\r\n3. Testing and verification\r\n\r\n### 1.2 Issues\r\nSome features need further optimization.\r\n\r\n### 1.3 Next Week Plan\r\nContinue optimization work.\r\n\"\"\"\r\n\r\n# Convert to official document format\r\nsuccess = md_to_docx(md_content, \"weekly_report.docx\")\r\nprint(\"Conversion successful\" if success else \"Conversion failed\")\r\n```\r\n\r\n---\r\n\r\n## 📋 Format Specifications (GB/T 9704-2012)\r\n\r\n### Page Settings\r\n\r\n| Setting | Value |\r\n|---------|-------|\r\n| Paper Size | A4 (210mm × 297mm) |\r\n| Top Margin | 3.7cm |\r\n| Bottom Margin | 3.5cm |\r\n| Left Margin | 2.8cm |\r\n| Right Margin | 2.6cm |\r\n| Line Spacing | 26pt (fixed) |\r\n| First Line Indent | 2 characters (640 twips) |\r\n\r\n### Font Settings\r\n\r\n| Element | Markdown | Font | Size |\r\n|---------|----------|------|------|\r\n| Title | `#` (single) | Fangzheng Xiaobiao Song | 2nd |\r\n| Heading 1 | `##` / `#` (multiple) | Hei Ti | 3rd |\r\n| Heading 2 | `###` | Kai Ti_GB2312 | 3rd |\r\n| Heading 3 | `####` | Fang Song_GB2312 | 3rd |\r\n| Body | Normal | Fang Song_GB2312 | 3rd |\r\n| Page Number | - | Song Ti | 4th |\r\n\r\n### Heading Numbering Rules\r\n\r\n| Level | Condition | Format Example |\r\n|-------|-----------|---------------|\r\n| Title | Single `#` in document | Document Title (centered, no numbering) |\r\n| Heading 1 | `##` or multiple `#` | I. Section Name |\r\n| Heading 2 | `###` | (I) Subsection Name |\r\n| Heading 3 | `####` | 1. Item Name |\r\n\r\n### Supported Markdown Elements\r\n\r\n| Element | Markdown Syntax | Notes |\r\n|---------|----------------|-------|\r\n| Heading | `#` `##` `###` `####` | Smart title detection |\r\n| Paragraph | Plain text | Multi-line paragraph support |\r\n| Ordered List | `1. 2. 3.` | Nested list support |\r\n| Unordered List | `- - -` | Nested list support |\r\n| Table | `\\| col \\| col \\|` | Full table support |\r\n| Image | `![alt](url)` | Inline image |\r\n| Link | `[text](url)` | Hyperlink |\r\n| Bold | `**text**` | Auto-convert to Hei Ti |\r\n| Italic | `*text*` | Auto-convert to Kai Ti |\r\n| Code Block | `` ```code``` `` | Monospace formatting |\r\n| Horizontal Rule | `---` | Page separator |\r\n\r\n---\r\n\r\n## 🔧 AI Agent Integration\r\n\r\n### OpenClaw Integration\r\n\r\n```python\r\nfrom official_doc import md_to_docx\r\nfrom openclaw import Skill\r\n\r\nclass OfficialDocSkill(Skill):\r\n    name = \"official-doc\"\r\n    description = \"Convert Markdown to Chinese government official document format\"\r\n\r\n    def execute(self, md_content, output_path=None):\r\n        if output_path is None:\r\n            output_path = \"output.docx\"\r\n\r\n        success = md_to_docx(md_content, output_path)\r\n\r\n        return {\r\n            \"success\": success,\r\n            \"output_path\": output_path,\r\n            \"message\": \"Conversion completed\" if success else \"Conversion failed\"\r\n        }\r\n```\r\n\r\n### Hermes Agent Integration\r\n\r\n```python\r\nfrom hermes import Agent\r\n\r\nagent = Agent()\r\nresult = agent.run_skill(\r\n    skill=\"official-doc\",\r\n    md_content=report_content,\r\n    output_path=\"weekly_report.docx\"\r\n)\r\n```\r\n\r\n---\r\n\r\n## 📁 Project Structure\r\n\r\n```\r\nofficial-doc/\r\n├── src/                      # Source code\r\n│   ├── __init__.py          # Package initialization\r\n│   └── md2docx.py           # Core conversion module\r\n├── skill.json               # AI Agent skill configuration\r\n├── setup.py                 # Installation configuration\r\n├── requirements.txt         # Dependencies\r\n├── README.md                # English documentation\r\n├── README_CN.md             # Chinese documentation\r\n├── CHANGELOG.md             # Changelog\r\n├── LICENSE                  # MIT License\r\n└── .gitignore               # Git ignore rules\r\n```\r\n\r\n---\r\n\r\n## 🧪 Testing\r\n\r\n```bash\r\ncat > test_official_doc.py << 'EOF'\r\nfrom official_doc import md_to_docx\r\n\r\ndef test_conversion():\r\n    md_content = \"\"\"# Test Document\r\n\r\n## 1. Test Title\r\n\r\nThis is a test paragraph.\r\n\r\n### 1.1 Subtitle\r\n\r\n**Bold text** test.\r\n\"\"\"\r\n    success = md_to_docx(md_content, 'test_output.docx')\r\n    assert success == True\r\n    print(\"✓ Test passed\")\r\n\r\nif __name__ == \"__main__\":\r\n    test_conversion()\r\n    print(\"✅ All tests passed!\")\r\nEOF\r\n\r\npython test_official_doc.py\r\n```\r\n\r\n---\r\n\r\n## 📜 License\r\n\r\nMIT License\r\n\r\n---\r\n\r\n## 🤝 Contributing\r\n\r\nWelcome to submit Issues and Pull Requests!\r\n\r\n1. Fork this repository\r\n2. Create feature branch (`git checkout -b feature/AmazingFeature`)\r\n3. Commit changes (`git commit -m 'feat: Add some AmazingFeature'`)\r\n4. Push to branch (`git push origin feature/AmazingFeature`)\r\n5. Open Pull Request\r\n\r\n---\r\n\r\n\r\n*Built with ❤️ for LLM + AI Agent Ecosystem*\n\nFile v1.1.2:_meta.json\n\n{\n  \"ownerId\": \"kn75zj7vzdyvap84adxa8heyyd82f5eh\",\n  \"slug\": \"gongwen-formatter\",\n  \"version\": \"1.1.2\",\n  \"publishedAt\": 1784031178185\n}\n\nFile v1.1.2:CHANGELOG.md\n\n# Changelog\r\n\r\n本文件记录 official-doc（gongwen-formatter）所有版本的变更。\r\n\r\n格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.0.0/)，\r\n版本号遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/)。\r\n\r\n## [1.1.2] - 2026-07-14\r\n\r\n### 安全升级（响应 ClawHub SkillSpector 审计）\r\n\r\n#### Added\r\n- `md_to_docx()` 新增 `download_images` 参数（默认 `True`），受限网络环境可设为 `False` 完全关闭网络请求\r\n- `skill.md` 增加\"权限声明\"段落，按最小权限原则披露网络访问/文件读写/不读取环境变量/不调用 subprocess\r\n- README 中英文版增加 \"图片下载网络请求说明 / Network Access Disclosure for Image Download\" 用户警告段落\r\n\r\n#### Security\r\n- `download_image()` 增加 URL scheme 白名单（仅 `http://`/`https://`/`data:image`），防止 SSRF\r\n- 其他 scheme（`file://`、`ftp://` 等）静默跳过，不发起网络请求\r\n- `requirements.txt` 改用 `~=` 兼容版本锁定（`python-docx~=1.1.0`、`markdown-it-py~=3.0.0`），平衡安全与兼容性\r\n\r\n## [1.1.1] - 2026-07-13\r\n\r\n#### Changed\r\n- 添加 ClawHub 触发词：`公文格式转换`、`转换公文格式`\r\n- ClawHub slug 改为 `gongwen-formatter`（`official-doc` 已被占用，`official-` 前缀受保护）\r\n- 三平台同步发布（GitHub + ClawHub + SkillHub）\r\n\r\n## [1.1.0] - 2026-07-12\r\n\r\n#### Added\r\n- 引入 `markdown-it-py` 解析器替代逐行 `split('\\n')`，支持多行段落、嵌套列表\r\n- `#` 标题智能判断：单个 `#` 视为大标题（居中不加序号），多个 `#` 视为一级标题（加序号）\r\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度，1汉字=16pt=320twips）\r\n- 新增表格、图片、超链接、代码块、嵌套列表支持\r\n- 加粗文本（`**text**`）自动转为黑体\r\n- 斜体文本（`*text*`）自动转为楷体\r\n\r\n#### Fixed\r\n- 黑体字体不再设置 `bold=True`（用户反馈\"黑体不需要加粗处理\"）\r\n- 移除所有黑体/楷体的 `bold=True` 设置\r\n\r\n## [1.0.0] - 2026-07-10\r\n\r\n#### Added\r\n- 初始版本：基于 GB/T 9704-2012 标准，将 Markdown 转换为党政机关公文格式 Word 文档\r\n- 实现基础标题层级、段落、列表转换\r\n- 国标页面设置：A4、上 3.7cm/下 3.5cm/左 2.8cm/右 2.6cm、行距 26pt\r\n- 字体规范：方正小标宋/黑体/楷体_GB2312/仿宋_GB2312/宋体\n\nFile v1.1.2:README_CN.md\n\n# 📄 Official Doc - 公文格式转换\r\n\r\n🇨🇳 中文文档 | 🇺🇸 [English](README.md)\r\n\r\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\r\n\r\n---\r\n\r\n## ⚠️ 重要说明\r\n\r\n本工具仅提供格式排版功能，不负责内容审核。请确保使用本工具生成的公文内容符合相关规定和要求。\r\n\r\n---\r\n\r\n## ✨ 功能特点\r\n\r\n| 功能 | 描述 |\r\n|------|------|\r\n| 🚀 **一键转换** | Markdown 转 Word 公文格式，简单易用 |\r\n| 📋 **标准遵循** | 严格按照 GB/T 9704-2012 党政机关公文格式标准 |\r\n| 🤖 **多智能体兼容** | 支持 OpenClaw、Hermes Agent、Claude Code 等 AI 智能体 |\r\n| 🔄 **双重输出** | 一份内容，同时生成 Markdown（供机器读）和 Word（供人读） |\r\n| 📊 **自动化支持** | 支持定时任务自动生成简报、周报、月报 |\r\n| 📦 **易于集成** | 提供标准 Python API，便于其他系统集成 |\r\n\r\n---\r\n\r\n## 🆕 v1.1.0 新特性\r\n\r\n- 引入 **markdown-it-py** 解析器，支持多行段落、嵌套列表\r\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\r\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\r\n- 新增表格、图片、超链接、代码块、嵌套列表支持\r\n- **加粗文本**自动转为黑体，*斜体文本*自动转为楷体\r\n\r\n---\r\n\r\n## 🚀 快速开始\r\n\r\n### 环境要求\r\n\r\n| 组件 | 要求 |\r\n|------|------|\r\n| 操作系统 | Windows 10/11、Linux、macOS |\r\n| Python | 3.8+（支持 3.11 / 3.12 / 3.13） |\r\n| 依赖 | python-docx >= 1.1.0, markdown-it-py >= 3.0.0 |\r\n\r\n### 安装方法\r\n\r\n**方式一：使用 pip 安装**\r\n```bash\r\npip install python-docx>=1.1.0 markdown-it-py>=3.0.0\r\n```\r\n\r\n**方式二：克隆仓库**\r\n```bash\r\ngit clone https://github.com/EdwardWason/official-doc.git\r\ncd official-doc\r\npip install -r requirements.txt\r\n```\r\n\r\n### 使用示例\r\n\r\n```python\r\nfrom official_doc import md_to_docx\r\n\r\n# Markdown 内容\r\nmd_content = \"\"\"# 工作简报\r\n\r\n## 一、上周工作总结\r\n\r\n本周完成了系统升级任务，主要包括：\r\n\r\n### （一）主要工作\r\n1. 完成服务器部署\r\n2. 完成数据迁移\r\n3. 完成测试验证\r\n\r\n### （二）存在问题\r\n部分功能需要进一步优化。\r\n\r\n### （三）下周计划\r\n继续推进优化工作。\r\n\"\"\"\r\n\r\n# 转换为公文格式\r\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\r\nprint(\"转换成功\" if success else \"转换失败\")\r\n```\r\n\r\n---\r\n\r\n## 📋 公文格式规范（GB/T 9704-2012）\r\n\r\n### 页面设置\r\n\r\n| 设置项 | 规范值 |\r\n|--------|--------|\r\n| 纸张尺寸 | A4 (210mm × 297mm) |\r\n| 上边距 | 3.7cm |\r\n| 下边距 | 3.5cm |\r\n| 左边距 | 2.8cm |\r\n| 右边距 | 2.6cm |\r\n| 行间距 | 固定值 26 磅 |\r\n| 首行缩进 | 2字符（640 twips） |\r\n\r\n### 字体规范\r\n\r\n| 元素 | Markdown 标记 | 字体 | 字号 |\r\n|------|--------------|------|------|\r\n| 大标题 | `#`（单个） | 方正小标宋简体 | 二号 |\r\n| 一级标题 | `##` / `#`（多个） | 黑体 | 三号 |\r\n| 二级标题 | `###` | 楷体_GB2312 | 三号 |\r\n| 三级标题 | `####` | 仿宋_GB2312 | 三号 |\r\n| 正文 | 普通文本 | 仿宋_GB2312 | 三号 |\r\n| 页码 | - | 宋体 | 四号 |\r\n\r\n### 标题编号规则\r\n\r\n| 层级 | 判断条件 | 格式示例 |\r\n|------|----------|----------|\r\n| 大标题 | 文档中仅一个 `#` | 公文标题（居中，不加序号） |\r\n| 一级标题 | `##` 或多个 `#` | 一、章节名称 |\r\n| 二级标题 | `###` | （一）小节名称 |\r\n| 三级标题 | `####` | 1. 项目名称 |\r\n\r\n### 支持的 Markdown 元素\r\n\r\n| 元素 | Markdown 语法 | 说明 |\r\n|------|--------------|------|\r\n| 标题 | `#` `##` `###` `####` | 智能标题判断 |\r\n| 段落 | 普通文本 | 支持多行段落 |\r\n| 有序列表 | `1. 2. 3.` | 支持嵌套列表 |\r\n| 无序列表 | `- - -` | 支持嵌套列表 |\r\n| 表格 | `\\| 列 \\| 列 \\|` | 完整表格支持 |\r\n| 图片 | `![alt](url)` | 行内图片 |\r\n| 超链接 | `[文本](url)` | 超链接 |\r\n| 加粗 | `**文本**` | 自动转为黑体 |\r\n| 斜体 | `*文本*` | 自动转为楷体 |\r\n| 代码块 | `` ```代码``` `` | 等宽字体格式 |\r\n| 分隔线 | `---` | 页面分隔 |\r\n\r\n---\r\n\r\n## 🔧 AI Agent 集成指南\r\n\r\n### OpenClaw 集成\r\n\r\n```python\r\nfrom official_doc import md_to_docx\r\nfrom openclaw import Skill\r\n\r\nclass OfficialDocSkill(Skill):\r\n    name = \"official-doc\"\r\n    description = \"公文格式转换 - 将 Markdown 转为党政机关公文格式\"\r\n\r\n    def execute(self, md_content, output_path=None):\r\n        if output_path is None:\r\n            output_path = \"output_公文格式.docx\"\r\n\r\n        success = md_to_docx(md_content, output_path)\r\n\r\n        return {\r\n            \"success\": success,\r\n            \"output_path\": output_path,\r\n            \"message\": \"公文格式转换完成\" if success else \"转换失败\"\r\n        }\r\n```\r\n\r\n### Hermes Agent 集成\r\n\r\n```python\r\n# 调用示例\r\nfrom hermes import Agent\r\n\r\nagent = Agent()\r\nresult = agent.run_skill(\r\n    skill=\"official-doc\",\r\n    md_content=report_content,\r\n    output_path=\"weekly_report.docx\"\r\n)\r\n```\r\n\r\n### 定时任务配置\r\n\r\n```python\r\nimport schedule\r\nimport time\r\nfrom official_doc import md_to_docx\r\n\r\ndef generate_daily_report():\r\n    content = generate_report_content()\r\n    today = time.strftime(\"%Y-%m-%d\")\r\n    md_to_docx(content, f\"工作简报_{today}_公文格式.docx\")\r\n\r\n# 每周一至周五 9:00 自动执行\r\nschedule.every().monday.at(\"09:00\").do(generate_daily_report)\r\nschedule.every().tuesday.at(\"09:00\").do(generate_daily_report)\r\nschedule.every().wednesday.at(\"09:00\").do(generate_daily_report)\r\nschedule.every().thursday.at(\"09:00\").do(generate_daily_report)\r\nschedule.every().friday.at(\"09:00\").do(generate_daily_report)\r\n\r\nwhile True:\r\n    schedule.run_pending()\r\n    time.sleep(60)\r\n```\r\n\r\n---\r\n\r\n## 📁 项目结构\r\n\r\n```\r\nofficial-doc/\r\n├── src/                      # 源代码目录\r\n│   ├── __init__.py          # 包初始化\r\n│   └── md2docx.py           # 核心转换模块\r\n├── skill.json               # AI Agent 技能配置\r\n├── setup.py                 # 安装配置\r\n├── requirements.txt         # 依赖清单\r\n├── README.md                # 英文文档\r\n├── README_CN.md             # 中文文档\r\n├── CHANGELOG.md             # 更新日志\r\n├── LICENSE                  # MIT 许可证\r\n└── .gitignore               # Git 忽略配置\r\n```\r\n\r\n---\r\n\r\n## 🧪 测试验证\r\n\r\n```bash\r\n# 创建测试脚本\r\ncat > test_official_doc.py << 'EOF'\r\nfrom official_doc import md_to_docx\r\n\r\ndef test_basic_conversion():\r\n    md_content = \"\"\"# 测试文档\r\n\r\n## 一、测试标题\r\n\r\n这是一个测试段落。\r\n\r\n### （一）二级标题\r\n\r\n1. 列表项一\r\n2. 列表项二\r\n\r\n**加粗文本** 测试。\r\n\"\"\"\r\n    success = md_to_docx(md_content, 'test_output.docx')\r\n    assert success == True\r\n    print(\"✓ 基本转换测试通过\")\r\n\r\nif __name__ == \"__main__\":\r\n    test_basic_conversion()\r\n    print(\"\\n✅ 所有测试通过！\")\r\nEOF\r\n\r\n# 运行测试\r\npython test_official_doc.py\r\n```\r\n\r\n---\r\n\r\n## 📜 许可证\r\n\r\nMIT License\r\n\r\n---\r\n\r\n## 🤝 贡献指南\r\n\r\n欢迎提交 Issue 和 Pull Request！\r\n\r\n1. Fork 本仓库\r\n2. 创建功能分支 (`git checkout -b feature/AmazingFeature`)\r\n3. 提交更改 (`git commit -m 'feat: Add some AmazingFeature'`)\r\n4. 推送到分支 (`git push origin feature/AmazingFeature`)\r\n5. 打开 Pull Request\r\n\r\n---\r\n\r\n## 📞 联系方式\r\n\r\n- **GitHub**: [https://github.com/EdwardWason/official-doc](https://github.com/EdwardWason/official-doc)\r\n- **Issues**: [https://github.com/EdwardWason/official-doc/issues](https://github.com/EdwardWason/official-doc/issues)\r\n\r\n---\r\n\r\n*Built with ❤️ for LLM + AI Agent 生态*\n\nFile v1.1.2:skill-card.md\n\n## Description: <br>\nConverts Markdown content into GB/T 9704-2012 Chinese official-document style Word documents. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[edwardwason](https://clawhub.ai/user/edwardwason) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and agents use this skill to convert generated or user-provided Markdown reports, briefings, and structured documents into Word .docx files with Chinese official-document formatting. It is intended for formatting only and does not review document content for policy, legal, or regulatory compliance. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: Markdown from untrusted sources can include remote image URLs that cause the runtime to contact arbitrary hosts. <br>\nMitigation: Prefer trusted Markdown and local images, and review or restrict remote image references before conversion. <br>\nRisk: Server security review says the submitted security-fix claims are not reflected in the artifacts. <br>\nMitigation: Review the artifact version before deployment and confirm that any claimed network opt-out and URL restrictions are actually present. <br>\nRisk: The skill formats documents but does not validate whether generated official-document content meets legal, policy, or organizational requirements. <br>\nMitigation: Require human review of document content and applicable compliance requirements before use or distribution. <br>\n\n\n## Reference(s): <br>\n- [ClawHub Skill Page](https://clawhub.ai/edwardwason/skills/gongwen-formatter) <br>\n- [Publisher Profile](https://clawhub.ai/user/edwardwason) <br>\n- [Project Homepage](https://github.com/EdwardWason/official-doc) <br>\n- [README](https://github.com/EdwardWason/official-doc/blob/main/README.md) <br>\n- [Releases](https://github.com/EdwardWason/official-doc/releases) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [Files, Text, Code] <br>\n**Output Format:** [Word .docx file plus structured success and output_path status from the Python API] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [Writes the converted document to the requested output path; image references in Markdown may trigger network requests during conversion.] <br>\n\n## Skill Version(s): <br>\n1.1.2 (source: server release evidence and changelog, released 2026-07-14) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nFile v1.1.2:skill.json\n\n{\n  \"name\": \"gongwen-formatter\",\n  \"name_cn\": \"公文格式转换\",\n  \"version\": \"1.1.1\",\n  \"description\": \"将 Markdown 文档转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文档\",\n  \"description_en\": \"Convert Markdown documents to Chinese government official document format (GB/T 9704-2012)\",\n  \"author\": \"EdwardWason\",\n  \"license\": \"MIT\",\n  \"homepage\": \"https://github.com/EdwardWason/official-doc\",\n  \"tags\": [\"document\", \"formatter\", \"markdown\", \"word\", \"government\", \"chinese\", \"gb9704\"],\n  \"triggers\": [\"公文格式转换\", \"转换公文格式\"],\n  \"platform\": [\"windows\", \"linux\", \"macos\"],\n  \"python_version\": \">=3.8\",\n  \"dependencies\": [\"python-docx>=1.1.0\", \"markdown-it-py>=3.0.0\"],\n\n  \"skills\": {\n    \"name\": \"gongwen-formatter\",\n    \"type\": \"formatter\",\n    \"category\": \"文档处理\"\n  },\n\n  \"input\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"md_content\": {\n        \"type\": \"string\",\n        \"description\": \"Markdown 格式的文本内容\"\n      },\n      \"output_path\": {\n        \"type\": \"string\",\n        \"description\": \"输出 Word 文件路径\"\n      }\n    },\n    \"required\": [\"md_content\", \"output_path\"]\n  },\n\n  \"output\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"success\": {\n        \"type\": \"boolean\",\n        \"description\": \"转换是否成功\"\n      },\n      \"output_path\": {\n        \"type\": \"string\",\n        \"description\": \"输出文件路径\"\n      }\n    }\n  },\n\n  \"examples\": [\n    {\n      \"name\": \"基本转换\",\n      \"code\": \"from official_doc import md_to_docx\\n\\nmd_content = '''# 大标题\\n\\n## 一级标题\\n\\n这是正文内容。\\n'''\\nmd_to_docx(md_content, 'output.docx')\"\n    },\n    {\n      \"name\": \"含表格和图片\",\n      \"code\": \"from official_doc import md_to_docx\\n\\nmd_content = '''# 工作简报\\n\\n## 工作总结\\n\\n| 项目 | 进度 |\\n|------|------|\\n| A项目 | 80% |\\n| B项目 | 60% |\\n\\n![架构图](https://example.com/arch.png)\\n'''\\nmd_to_docx(md_content, '简报_公文格式.docx')\"\n    },\n    {\n      \"name\": \"AI Agent 集成\",\n      \"code\": \"from official_doc import md_to_docx\\n\\ndef generate_report(content):\\n    # 保存 Markdown 版本\\n    with open('report.md', 'w', encoding='utf-8') as f:\\n        f.write(content)\\n    # 生成公文格式\\n    md_to_docx(content, 'report_公文格式.docx')\\n    return '报告已生成'\"\n    }\n  ],\n\n  \"format_standard\": {\n    \"name\": \"GB/T 9704-2012\",\n    \"description\": \"党政机关公文格式\",\n    \"page_settings\": {\n      \"top_margin\": \"3.7cm\",\n      \"bottom_margin\": \"3.5cm\",\n      \"left_margin\": \"2.8cm\",\n      \"right_margin\": \"2.6cm\",\n      \"line_spacing\": \"26pt\",\n      \"first_line_indent\": \"2字符(640twips)\"\n    },\n    \"font_settings\": {\n      \"title\": {\"font\": \"方正小标宋简体\", \"size\": \"二号\", \"note\": \"单个#标题居中不加序号，多个#标题加序号\"},\n      \"level1\": {\"font\": \"黑体\", \"size\": \"三号\"},\n      \"level2\": {\"font\": \"楷体_GB2312\", \"size\": \"三号\", \"bold\": true},\n      \"level3\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\", \"bold\": true},\n      \"body\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\"},\n      \"table_header\": {\"font\": \"黑体\", \"size\": \"三号\"},\n      \"table_body\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\"},\n      \"link\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\", \"color\": \"蓝色\", \"underline\": true}\n    },\n    \"supported_elements\": {\n      \"headings\": \"# / ## / ### / #### 智能层级判断\",\n      \"paragraphs\": \"正文段落，首行缩进2字符\",\n      \"ordered_list\": \"有序列表，支持嵌套\",\n      \"unordered_list\": \"无序列表，支持嵌套\",\n      \"table\": \"Markdown表格 → Word表格\",\n      \"image\": \"![alt](url) → 居中图片+图注\",\n      \"link\": \"[text](url) → 蓝色下划线超链接\",\n      \"bold\": \"**text** → 黑体\",\n      \"italic\": \"*text* → 楷体加粗\",\n      \"code_block\": \"```代码块 → 仿宋小四号\",\n      \"hr\": \"--- 水平线忽略\"\n    }\n  }\n}\n\nFile v1.1.2:requirements.txt\n\npython-docx>=1.1.0\r\nmarkdown-it-py>=3.0.0\n\nArchive v1.1.1: 10 files, 19462 bytes\n\nFiles: README_CN.md (7683b), README.md (6962b), requirements.txt (41b), setup.py (1117b), skill-card.md (1729b), skill.json (3925b), skill.md (5846b), src/__init__.py (324b), src/md2docx.py (25844b), _meta.json (136b)\n\nFile v1.1.1:skill.md\n\n# 📄 official-doc - 公文格式转换\n\n## 技能信息\n\n### 基本信息\n| 属性 | 说明 |\n|------|------|\n| **名称** | official-doc |\n| **中文名称** | 公文格式转换 |\n| **版本** | 1.1.0 |\n| **作者** | EdwardWason |\n| **许可证** | MIT |\n| **主页** | https://github.com/EdwardWason/official-doc |\n\n### 触发词\n- **公文格式转换**\n- **转换公文格式**\n\n### 功能描述\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\n\n### 适用场景\n- AI Agent 生成公文格式报告\n- 定时任务自动生成工作简报、周报、月报\n- Markdown 文档批量转换为标准公文格式\n- 行业研报格式标准化输出\n\n### v1.1.0 新增功能\n- 引入 markdown-it-py 解析器，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- 加粗文本自动转为黑体，斜体文本自动转为楷体\n\n---\n\n## 输入参数\n\n| 参数名 | 类型 | 必填 | 说明 |\n|--------|------|------|------|\n| `md_content` | string | ✅ | Markdown 格式的文本内容 |\n| `output_path` | string | ✅ | 输出 Word 文件路径（.docx） |\n\n---\n\n## 输出结果\n\n| 字段 | 类型 | 说明 |\n|------|------|------|\n| `success` | boolean | 转换是否成功 |\n| `output_path` | string | 输出文件路径 |\n\n---\n\n## 使用示例\n\n### 基本使用\n```python\nfrom official_doc import md_to_docx\n\nmd_content = \"\"\"# 工作简报\n\n## 一、上周工作总结\n\n本周完成了系统升级任务。\n\n### （一）主要工作\n1. 服务器部署\n2. 数据迁移\n3. 测试验证\n\n### （二）下周计划\n继续推进优化工作。\n\"\"\"\n\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\nprint(\"转换成功\" if success else \"转换失败\")\n```\n\n### 含表格和图片\n```python\nfrom official_doc import md_to_docx\n\nmd_content = \"\"\"# 项目进度表\n\n## 工作进展\n\n| 项目名称 | 负责人 | 进度 | 备注 |\n|----------|--------|------|------|\n| A项目 | 张三 | 80% | 正常 |\n| B项目 | 李四 | 60% | 需加速 |\n\n![架构图](https://example.com/arch.png)\n\n详细说明请参考[官方文档](https://example.com)。\n\"\"\"\n\nmd_to_docx(md_content, \"进度表_公文格式.docx\")\n```\n\n### AI Agent 集成\n```python\nfrom official_doc import md_to_docx\n\nclass OfficialDocSkill:\n    name = \"official-doc\"\n    description = \"公文格式转换 - 将 Markdown 转为党政机关公文格式\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output_公文格式.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"公文格式转换完成\" if success else \"转换失败\"\n        }\n```\n\n### 定时任务\n```python\nimport schedule\nimport time\nfrom official_doc import md_to_docx\n\ndef generate_report():\n    content = generate_report_content()\n    today = time.strftime(\"%Y-%m-%d\")\n    md_to_docx(content, f\"工作简报_{today}_公文格式.docx\")\n\nschedule.every().monday.at(\"09:00\").do(generate_report)\n```\n\n---\n\n## 格式规范\n\n### 页面设置\n| 设置项 | 规范值 |\n|--------|--------|\n| 上边距 | 3.7cm |\n| 下边距 | 3.5cm |\n| 左边距 | 2.8cm |\n| 右边距 | 2.6cm |\n| 行间距 | 固定值 26 磅 |\n| 首行缩进 | 2字符（640 twips） |\n\n### 字体设置\n| 元素 | Markdown | 字体 | 字号 |\n|------|----------|------|------|\n| 大标题（单个#） | `#` | 方正小标宋简体 | 二号 |\n| 一级标题（多个#） | `#` | 黑体 | 三号 |\n| 二级标题 | `##` | 黑体 | 三号 |\n| 三级标题 | `###` | 楷体_GB2312 | 三号 |\n| 四级标题 | `####` | 仿宋_GB2312 | 三号 |\n| 正文 | 普通文本 | 仿宋_GB2312 | 三号 |\n| 加粗文本 | `**text**` | 黑体 | 三号 |\n| 斜体文本 | `*text*` | 楷体_GB2312 | 三号 |\n| 链接 | `[text](url)` | 仿宋_GB2312 蓝色下划线 | 三号 |\n| 表格表头 | `| 表头 |` | 黑体 | 三号 |\n| 表格内容 | `| 内容 |` | 仿宋_GB2312 | 三号 |\n| 代码块 | ` ``` ` | 仿宋_GB2312 | 小四号 |\n| 页码 | - | 宋体 | 四号 |\n\n### 标题编号规则\n| 层级 | 格式示例 | 说明 |\n|------|----------|------|\n| 大标题 | 公文标题 | 单个#标题居中，不加序号 |\n| 一级标题 | 一、章节名称 | 多个#标题自动加序号 |\n| 二级标题 | 一、章节名称 | ## 标题自动加序号 |\n| 三级标题 | （一）小节名称 | ### 标题加中文括号序号 |\n| 四级标题 | 正文格式 | #### 标题不加序号 |\n\n### 支持的 Markdown 元素\n| 元素 | 转换效果 |\n|------|----------|\n| 标题 `# / ## / ### / ####` | 智能层级判断 + 自动编号 |\n| 段落 | 正文仿宋三号，首行缩进2字符 |\n| 有序列表 `1. 2. 3.` | 自动编号，支持嵌套 |\n| 无序列表 `- / *` | 圆点标记，支持嵌套 |\n| 表格 `| ... |` | Word表格，表头黑体 |\n| 图片 `![alt](url)` | 居中图片 + 图注 |\n| 链接 `[text](url)` | 蓝色下划线超链接 |\n| 加粗 `**text**` | 黑体 |\n| 斜体 `*text*` | 楷体 |\n| 代码块 ` ``` ` | 仿宋小四号 |\n| 水平线 `---` | 忽略 |\n\n---\n\n## 依赖要求\n\n| 依赖 | 版本 |\n|------|------|\n| Python | >= 3.8 |\n| python-docx | >= 1.1.0 |\n| markdown-it-py | >= 3.0.0 |\n\n---\n\n## 支持平台\n\n- ✅ Windows 10/11\n- ✅ Linux\n- ✅ macOS\n\n---\n\n## 项目链接\n\n- GitHub: https://github.com/EdwardWason/official-doc\n- Release: https://github.com/EdwardWason/official-doc/releases\n- README: https://github.com/EdwardWason/official-doc/blob/main/README.md\n\nFile v1.1.1:README.md\n\n# 📄 Official Doc - Document Format Converter\n\n🇨🇳 [中文文档](README_CN.md) | 🇺🇸 English\n\nConvert Markdown documents to Chinese government official document format (GB/T 9704-2012) Word documents. Focused on formatting conversion only — does not add red header, record mark, signature block, or other decorative elements of official documents.\n\n---\n\n## ⚠️ Important Notes\n\nThis tool only provides formatting functionality and does not review content. Please ensure that the official documents generated using this tool comply with relevant regulations and requirements.\n\n---\n\n## ✨ Features\n\n| Feature | Description |\n|---------|-------------|\n| 🚀 **One-click Conversion** | Convert Markdown to Word official document format easily |\n| 📋 **Standard Compliance** | Strictly follows GB/T 9704-2012 standard |\n| 🤖 **Multi-Agent Support** | Works with OpenClaw, Hermes Agent, Claude Code, etc. |\n| 🔄 **Dual Output** | Generate both Markdown (for machines) and Word (for humans) |\n| 📊 **Automation Ready** | Supports scheduled tasks for automatic report generation |\n| 📦 **Easy Integration** | Provides standard Python API for system integration |\n\n---\n\n## 🆕 v1.1.0 New Features\n\n- Introduced **markdown-it-py** parser, supporting multi-line paragraphs and nested lists\n- Smart `#` heading detection: a single `#` is treated as a main title (centered, no numbering); multiple `#` headings are treated as first-level headings (with numbering)\n- First line indent precisely aligned with national standard (640 twips = width of 2 Size-3 Chinese characters)\n- Added support for **tables, images, hyperlinks, code blocks, and nested lists**\n- **Bold text** is automatically converted to SimHei (黑体); *italic text* is automatically converted to KaiTi (楷体)\n\n---\n\n## 🚀 Quick Start\n\n### System Requirements\n\n| Component | Requirement |\n|-----------|-------------|\n| OS | Windows 10/11, Linux, macOS |\n| Python | 3.8+ (3.11 / 3.12 / 3.13 supported) |\n| Dependency | python-docx >= 1.1.0, markdown-it-py >= 3.0.0 |\n\n### Installation\n\n**Method 1: Using pip**\n```bash\npip install python-docx>=1.1.0 markdown-it-py>=3.0.0\n```\n\n**Method 2: Clone repository**\n```bash\ngit clone https://github.com/EdwardWason/official-doc.git\ncd official-doc\npip install -r requirements.txt\n```\n\n### Usage Example\n\n```python\nfrom official_doc import md_to_docx\n\n# Markdown content\nmd_content = \"\"\"# Weekly Report\n\n## 1. Work Summary\n\nCompleted system upgrade tasks including:\n\n### 1.1 Main Tasks\n1. Server deployment\n2. Data migration\n3. Testing and verification\n\n### 1.2 Issues\nSome features need further optimization.\n\n### 1.3 Next Week Plan\nContinue optimization work.\n\"\"\"\n\n# Convert to official document format\nsuccess = md_to_docx(md_content, \"weekly_report.docx\")\nprint(\"Conversion successful\" if success else \"Conversion failed\")\n```\n\n---\n\n## 📋 Format Specifications (GB/T 9704-2012)\n\n### Page Settings\n\n| Setting | Value |\n|---------|-------|\n| Paper Size | A4 (210mm × 297mm) |\n| Top Margin | 3.7cm |\n| Bottom Margin | 3.5cm |\n| Left Margin | 2.8cm |\n| Right Margin | 2.6cm |\n| Line Spacing | 26pt (fixed) |\n| First Line Indent | 2 characters (640 twips) |\n\n### Font Settings\n\n| Element | Markdown | Font | Size |\n|---------|----------|------|------|\n| Title | `#` (single) | Fangzheng Xiaobiao Song | 2nd |\n| Heading 1 | `##` / `#` (multiple) | Hei Ti | 3rd |\n| Heading 2 | `###` | Kai Ti_GB2312 | 3rd |\n| Heading 3 | `####` | Fang Song_GB2312 | 3rd |\n| Body | Normal | Fang Song_GB2312 | 3rd |\n| Page Number | - | Song Ti | 4th |\n\n### Heading Numbering Rules\n\n| Level | Condition | Format Example |\n|-------|-----------|---------------|\n| Title | Single `#` in document | Document Title (centered, no numbering) |\n| Heading 1 | `##` or multiple `#` | I. Section Name |\n| Heading 2 | `###` | (I) Subsection Name |\n| Heading 3 | `####` | 1. Item Name |\n\n### Supported Markdown Elements\n\n| Element | Markdown Syntax | Notes |\n|---------|----------------|-------|\n| Heading | `#` `##` `###` `####` | Smart title detection |\n| Paragraph | Plain text | Multi-line paragraph support |\n| Ordered List | `1. 2. 3.` | Nested list support |\n| Unordered List | `- - -` | Nested list support |\n| Table | `\\| col \\| col \\|` | Full table support |\n| Image | `![alt](url)` | Inline image |\n| Link | `[text](url)` | Hyperlink |\n| Bold | `**text**` | Auto-convert to Hei Ti |\n| Italic | `*text*` | Auto-convert to Kai Ti |\n| Code Block | `` ```code``` `` | Monospace formatting |\n| Horizontal Rule | `---` | Page separator |\n\n---\n\n## 🔧 AI Agent Integration\n\n### OpenClaw Integration\n\n```python\nfrom official_doc import md_to_docx\nfrom openclaw import Skill\n\nclass OfficialDocSkill(Skill):\n    name = \"official-doc\"\n    description = \"Convert Markdown to Chinese government official document format\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"Conversion completed\" if success else \"Conversion failed\"\n        }\n```\n\n### Hermes Agent Integration\n\n```python\nfrom hermes import Agent\n\nagent = Agent()\nresult = agent.run_skill(\n    skill=\"official-doc\",\n    md_content=report_content,\n    output_path=\"weekly_report.docx\"\n)\n```\n\n---\n\n## 📁 Project Structure\n\n```\nofficial-doc/\n├── src/                      # Source code\n│   ├── __init__.py          # Package initialization\n│   └── md2docx.py           # Core conversion module\n├── skill.json               # AI Agent skill configuration\n├── setup.py                 # Installation configuration\n├── requirements.txt         # Dependencies\n├── README.md                # English documentation\n├── README_CN.md             # Chinese documentation\n├── CHANGELOG.md             # Changelog\n├── LICENSE                  # MIT License\n└── .gitignore               # Git ignore rules\n```\n\n---\n\n## 🧪 Testing\n\n```bash\ncat > test_official_doc.py << 'EOF'\nfrom official_doc import md_to_docx\n\ndef test_conversion():\n    md_content = \"\"\"# Test Document\n\n## 1. Test Title\n\nThis is a test paragraph.\n\n### 1.1 Subtitle\n\n**Bold text** test.\n\"\"\"\n    success = md_to_docx(md_content, 'test_output.docx')\n    assert success == True\n    print(\"✓ Test passed\")\n\nif __name__ == \"__main__\":\n    test_conversion()\n    print(\"✅ All tests passed!\")\nEOF\n\npython test_official_doc.py\n```\n\n---\n\n## 📜 License\n\nMIT License\n\n---\n\n## 🤝 Contributing\n\nWelcome to submit Issues and Pull Requests!\n\n1. Fork this repository\n2. Create feature branch (`git checkout -b feature/AmazingFeature`)\n3. Commit changes (`git commit -m 'feat: Add some AmazingFeature'`)\n4. Push to branch (`git push origin feature/AmazingFeature`)\n5. Open Pull Request\n\n---\n\n\n*Built with ❤️ for LLM + AI Agent Ecosystem*\n\nFile v1.1.1:_meta.json\n\n{\n  \"ownerId\": \"kn75zj7vzdyvap84adxa8heyyd82f5eh\",\n  \"slug\": \"gongwen-formatter\",\n  \"version\": \"1.1.1\",\n  \"publishedAt\": 1783949397188\n}\n\nFile v1.1.1:README_CN.md\n\n# 📄 Official Doc - 公文格式转换\n\n🇨🇳 中文文档 | 🇺🇸 [English](README.md)\n\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\n\n---\n\n## ⚠️ 重要说明\n\n本工具仅提供格式排版功能，不负责内容审核。请确保使用本工具生成的公文内容符合相关规定和要求。\n\n---\n\n## ✨ 功能特点\n\n| 功能 | 描述 |\n|------|------|\n| 🚀 **一键转换** | Markdown 转 Word 公文格式，简单易用 |\n| 📋 **标准遵循** | 严格按照 GB/T 9704-2012 党政机关公文格式标准 |\n| 🤖 **多智能体兼容** | 支持 OpenClaw、Hermes Agent、Claude Code 等 AI 智能体 |\n| 🔄 **双重输出** | 一份内容，同时生成 Markdown（供机器读）和 Word（供人读） |\n| 📊 **自动化支持** | 支持定时任务自动生成简报、周报、月报 |\n| 📦 **易于集成** | 提供标准 Python API，便于其他系统集成 |\n\n---\n\n## 🆕 v1.1.0 新特性\n\n- 引入 **markdown-it-py** 解析器，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- **加粗文本**自动转为黑体，*斜体文本*自动转为楷体\n\n---\n\n## 🚀 快速开始\n\n### 环境要求\n\n| 组件 | 要求 |\n|------|------|\n| 操作系统 | Windows 10/11、Linux、macOS |\n| Python | 3.8+（支持 3.11 / 3.12 / 3.13） |\n| 依赖 | python-docx >= 1.1.0, markdown-it-py >= 3.0.0 |\n\n### 安装方法\n\n**方式一：使用 pip 安装**\n```bash\npip install python-docx>=1.1.0 markdown-it-py>=3.0.0\n```\n\n**方式二：克隆仓库**\n```bash\ngit clone https://github.com/EdwardWason/official-doc.git\ncd official-doc\npip install -r requirements.txt\n```\n\n### 使用示例\n\n```python\nfrom official_doc import md_to_docx\n\n# Markdown 内容\nmd_content = \"\"\"# 工作简报\n\n## 一、上周工作总结\n\n本周完成了系统升级任务，主要包括：\n\n### （一）主要工作\n1. 完成服务器部署\n2. 完成数据迁移\n3. 完成测试验证\n\n### （二）存在问题\n部分功能需要进一步优化。\n\n### （三）下周计划\n继续推进优化工作。\n\"\"\"\n\n# 转换为公文格式\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\nprint(\"转换成功\" if success else \"转换失败\")\n```\n\n---\n\n## 📋 公文格式规范（GB/T 9704-2012）\n\n### 页面设置\n\n| 设置项 | 规范值 |\n|--------|--------|\n| 纸张尺寸 | A4 (210mm × 297mm) |\n| 上边距 | 3.7cm |\n| 下边距 | 3.5cm |\n| 左边距 | 2.8cm |\n| 右边距 | 2.6cm |\n| 行间距 | 固定值 26 磅 |\n| 首行缩进 | 2字符（640 twips） |\n\n### 字体规范\n\n| 元素 | Markdown 标记 | 字体 | 字号 |\n|------|--------------|------|------|\n| 大标题 | `#`（单个） | 方正小标宋简体 | 二号 |\n| 一级标题 | `##` / `#`（多个） | 黑体 | 三号 |\n| 二级标题 | `###` | 楷体_GB2312 | 三号 |\n| 三级标题 | `####` | 仿宋_GB2312 | 三号 |\n| 正文 | 普通文本 | 仿宋_GB2312 | 三号 |\n| 页码 | - | 宋体 | 四号 |\n\n### 标题编号规则\n\n| 层级 | 判断条件 | 格式示例 |\n|------|----------|----------|\n| 大标题 | 文档中仅一个 `#` | 公文标题（居中，不加序号） |\n| 一级标题 | `##` 或多个 `#` | 一、章节名称 |\n| 二级标题 | `###` | （一）小节名称 |\n| 三级标题 | `####` | 1. 项目名称 |\n\n### 支持的 Markdown 元素\n\n| 元素 | Markdown 语法 | 说明 |\n|------|--------------|------|\n| 标题 | `#` `##` `###` `####` | 智能标题判断 |\n| 段落 | 普通文本 | 支持多行段落 |\n| 有序列表 | `1. 2. 3.` | 支持嵌套列表 |\n| 无序列表 | `- - -` | 支持嵌套列表 |\n| 表格 | `\\| 列 \\| 列 \\|` | 完整表格支持 |\n| 图片 | `![alt](url)` | 行内图片 |\n| 超链接 | `[文本](url)` | 超链接 |\n| 加粗 | `**文本**` | 自动转为黑体 |\n| 斜体 | `*文本*` | 自动转为楷体 |\n| 代码块 | `` ```代码``` `` | 等宽字体格式 |\n| 分隔线 | `---` | 页面分隔 |\n\n---\n\n## 🔧 AI Agent 集成指南\n\n### OpenClaw 集成\n\n```python\nfrom official_doc import md_to_docx\nfrom openclaw import Skill\n\nclass OfficialDocSkill(Skill):\n    name = \"official-doc\"\n    description = \"公文格式转换 - 将 Markdown 转为党政机关公文格式\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output_公文格式.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"公文格式转换完成\" if success else \"转换失败\"\n        }\n```\n\n### Hermes Agent 集成\n\n```python\n# 调用示例\nfrom hermes import Agent\n\nagent = Agent()\nresult = agent.run_skill(\n    skill=\"official-doc\",\n    md_content=report_content,\n    output_path=\"weekly_report.docx\"\n)\n```\n\n### 定时任务配置\n\n```python\nimport schedule\nimport time\nfrom official_doc import md_to_docx\n\ndef generate_daily_report():\n    content = generate_report_content()\n    today = time.strftime(\"%Y-%m-%d\")\n    md_to_docx(content, f\"工作简报_{today}_公文格式.docx\")\n\n# 每周一至周五 9:00 自动执行\nschedule.every().monday.at(\"09:00\").do(generate_daily_report)\nschedule.every().tuesday.at(\"09:00\").do(generate_daily_report)\nschedule.every().wednesday.at(\"09:00\").do(generate_daily_report)\nschedule.every().thursday.at(\"09:00\").do(generate_daily_report)\nschedule.every().friday.at(\"09:00\").do(generate_daily_report)\n\nwhile True:\n    schedule.run_pending()\n    time.sleep(60)\n```\n\n---\n\n## 📁 项目结构\n\n```\nofficial-doc/\n├── src/                      # 源代码目录\n│   ├── __init__.py          # 包初始化\n│   └── md2docx.py           # 核心转换模块\n├── skill.json               # AI Agent 技能配置\n├── setup.py                 # 安装配置\n├── requirements.txt         # 依赖清单\n├── README.md                # 英文文档\n├── README_CN.md             # 中文文档\n├── CHANGELOG.md             # 更新日志\n├── LICENSE                  # MIT 许可证\n└── .gitignore               # Git 忽略配置\n```\n\n---\n\n## 🧪 测试验证\n\n```bash\n# 创建测试脚本\ncat > test_official_doc.py << 'EOF'\nfrom official_doc import md_to_docx\n\ndef test_basic_conversion():\n    md_content = \"\"\"# 测试文档\n\n## 一、测试标题\n\n这是一个测试段落。\n\n### （一）二级标题\n\n1. 列表项一\n2. 列表项二\n\n**加粗文本** 测试。\n\"\"\"\n    success = md_to_docx(md_content, 'test_output.docx')\n    assert success == True\n    print(\"✓ 基本转换测试通过\")\n\nif __name__ == \"__main__\":\n    test_basic_conversion()\n    print(\"\\n✅ 所有测试通过！\")\nEOF\n\n# 运行测试\npython test_official_doc.py\n```\n\n---\n\n## 📜 许可证\n\nMIT License\n\n---\n\n## 🤝 贡献指南\n\n欢迎提交 Issue 和 Pull Request！\n\n1. Fork 本仓库\n2. 创建功能分支 (`git checkout -b feature/AmazingFeature`)\n3. 提交更改 (`git commit -m 'feat: Add some AmazingFeature'`)\n4. 推送到分支 (`git push origin feature/AmazingFeature`)\n5. 打开 Pull Request\n\n---\n\n## 📞 联系方式\n\n- **GitHub**: [https://github.com/EdwardWason/official-doc](https://github.com/EdwardWason/official-doc)\n- **Issues**: [https://github.com/EdwardWason/official-doc/issues](https://github.com/EdwardWason/official-doc/issues)\n\n---\n\n*Built with ❤️ for LLM + AI Agent 生态*\n\nFile v1.1.1:skill-card.md\n\n## Description: <br>\nConverts Markdown documents into GB/T 9704-2012 Chinese official-document formatted Word files. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[edwardwason](https://clawhub.ai/user/edwardwason) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers, AI-agent builders, and operations teams use this skill to convert Markdown reports, briefings, and scheduled summaries into standardized GB/T 9704-2012 DOCX files. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: Markdown image links can trigger outbound network requests during conversion. <br>\nMitigation: Process only trusted Markdown or run the converter with network egress blocked or reviewed before allowing remote image fetches. <br>\n\n\n## Reference(s): <br>\n- [ClawHub skill page](https://clawhub.ai/edwardwason/skills/gongwen-formatter) <br>\n- [README.md](README.md) <br>\n- [README_CN.md](README_CN.md) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [Files, Code] <br>\n**Output Format:** [Word .docx file with a boolean success result and output path] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [Takes Markdown content and an output path; supports headings, paragraphs, lists, tables, links, code blocks, and standalone images.] <br>\n\n## Skill Version(s): <br>\n1.1.1 (source: server release metadata and skill.json) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nFile v1.1.1:skill.json\n\n{\n  \"name\": \"gongwen-formatter\",\n  \"name_cn\": \"公文格式转换\",\n  \"version\": \"1.1.1\",\n  \"description\": \"将 Markdown 文档转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文档\",\n  \"description_en\": \"Convert Markdown documents to Chinese government official document format (GB/T 9704-2012)\",\n  \"author\": \"EdwardWason\",\n  \"license\": \"MIT\",\n  \"homepage\": \"https://github.com/EdwardWason/official-doc\",\n  \"tags\": [\"document\", \"formatter\", \"markdown\", \"word\", \"government\", \"chinese\", \"gb9704\"],\n  \"triggers\": [\"公文格式转换\", \"转换公文格式\"],\n  \"platform\": [\"windows\", \"linux\", \"macos\"],\n  \"python_version\": \">=3.8\",\n  \"dependencies\": [\"python-docx>=1.1.0\", \"markdown-it-py>=3.0.0\"],\n\n  \"skills\": {\n    \"name\": \"gongwen-formatter\",\n    \"type\": \"formatter\",\n    \"category\": \"文档处理\"\n  },\n\n  \"input\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"md_content\": {\n        \"type\": \"string\",\n        \"description\": \"Markdown 格式的文本内容\"\n      },\n      \"output_path\": {\n        \"type\": \"string\",\n        \"description\": \"输出 Word 文件路径\"\n      }\n    },\n    \"required\": [\"md_content\", \"output_path\"]\n  },\n\n  \"output\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"success\": {\n        \"type\": \"boolean\",\n        \"description\": \"转换是否成功\"\n      },\n      \"output_path\": {\n        \"type\": \"string\",\n        \"description\": \"输出文件路径\"\n      }\n    }\n  },\n\n  \"examples\": [\n    {\n      \"name\": \"基本转换\",\n      \"code\": \"from official_doc import md_to_docx\\n\\nmd_content = '''# 大标题\\n\\n## 一级标题\\n\\n这是正文内容。\\n'''\\nmd_to_docx(md_content, 'output.docx')\"\n    },\n    {\n      \"name\": \"含表格和图片\",\n      \"code\": \"from official_doc import md_to_docx\\n\\nmd_content = '''# 工作简报\\n\\n## 工作总结\\n\\n| 项目 | 进度 |\\n|------|------|\\n| A项目 | 80% |\\n| B项目 | 60% |\\n\\n![架构图](https://example.com/arch.png)\\n'''\\nmd_to_docx(md_content, '简报_公文格式.docx')\"\n    },\n    {\n      \"name\": \"AI Agent 集成\",\n      \"code\": \"from official_doc import md_to_docx\\n\\ndef generate_report(content):\\n    # 保存 Markdown 版本\\n    with open('report.md', 'w', encoding='utf-8') as f:\\n        f.write(content)\\n    # 生成公文格式\\n    md_to_docx(content, 'report_公文格式.docx')\\n    return '报告已生成'\"\n    }\n  ],\n\n  \"format_standard\": {\n    \"name\": \"GB/T 9704-2012\",\n    \"description\": \"党政机关公文格式\",\n    \"page_settings\": {\n      \"top_margin\": \"3.7cm\",\n      \"bottom_margin\": \"3.5cm\",\n      \"left_margin\": \"2.8cm\",\n      \"right_margin\": \"2.6cm\",\n      \"line_spacing\": \"26pt\",\n      \"first_line_indent\": \"2字符(640twips)\"\n    },\n    \"font_settings\": {\n      \"title\": {\"font\": \"方正小标宋简体\", \"size\": \"二号\", \"note\": \"单个#标题居中不加序号，多个#标题加序号\"},\n      \"level1\": {\"font\": \"黑体\", \"size\": \"三号\"},\n      \"level2\": {\"font\": \"楷体_GB2312\", \"size\": \"三号\", \"bold\": true},\n      \"level3\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\", \"bold\": true},\n      \"body\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\"},\n      \"table_header\": {\"font\": \"黑体\", \"size\": \"三号\"},\n      \"table_body\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\"},\n      \"link\": {\"font\": \"仿宋_GB2312\", \"size\": \"三号\", \"color\": \"蓝色\", \"underline\": true}\n    },\n    \"supported_elements\": {\n      \"headings\": \"# / ## / ### / #### 智能层级判断\",\n      \"paragraphs\": \"正文段落，首行缩进2字符\",\n      \"ordered_list\": \"有序列表，支持嵌套\",\n      \"unordered_list\": \"无序列表，支持嵌套\",\n      \"table\": \"Markdown表格 → Word表格\",\n      \"image\": \"![alt](url) → 居中图片+图注\",\n      \"link\": \"[text](url) → 蓝色下划线超链接\",\n      \"bold\": \"**text** → 黑体\",\n      \"italic\": \"*text* → 楷体加粗\",\n      \"code_block\": \"```代码块 → 仿宋小四号\",\n      \"hr\": \"--- 水平线忽略\"\n    }\n  }\n}\n\nFile v1.1.1:requirements.txt\n\npython-docx>=1.1.0\nmarkdown-it-py>=3.0.0\n\nArchive v1.1.0: 10 files, 19534 bytes\n\nFiles: README_CN.md (7683b), README.md (6962b), requirements.txt (41b), setup.py (1117b), skill-card.md (2008b), skill.json (3875b), skill.md (5781b), src/__init__.py (324b), src/md2docx.py (25844b), _meta.json (136b)\n\nFile v1.1.0:skill.md\n\n# 📄 official-doc - 公文格式转换\n\n## 技能信息\n\n### 基本信息\n| 属性 | 说明 |\n|------|------|\n| **名称** | official-doc |\n| **中文名称** | 公文格式转换 |\n| **版本** | 1.1.0 |\n| **作者** | EdwardWason |\n| **许可证** | MIT |\n| **主页** | https://github.com/EdwardWason/official-doc |\n\n### 功能描述\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\n\n### 适用场景\n- AI Agent 生成公文格式报告\n- 定时任务自动生成工作简报、周报、月报\n- Markdown 文档批量转换为标准公文格式\n- 行业研报格式标准化输出\n\n### v1.1.0 新增功能\n- 引入 markdown-it-py 解析器，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- 加粗文本自动转为黑体，斜体文本自动转为楷体\n\n---\n\n## 输入参数\n\n| 参数名 | 类型 | 必填 | 说明 |\n|--------|------|------|------|\n| `md_content` | string | ✅ | Markdown 格式的文本内容 |\n| `output_path` | string | ✅ | 输出 Word 文件路径（.docx） |\n\n---\n\n## 输出结果\n\n| 字段 | 类型 | 说明 |\n|------|------|------|\n| `success` | boolean | 转换是否成功 |\n| `output_path` | string | 输出文件路径 |\n\n---\n\n## 使用示例\n\n### 基本使用\n```python\nfrom official_doc import md_to_docx\n\nmd_content = \"\"\"# 工作简报\n\n## 一、上周工作总结\n\n本周完成了系统升级任务。\n\n### （一）主要工作\n1. 服务器部署\n2. 数据迁移\n3. 测试验证\n\n### （二）下周计划\n继续推进优化工作。\n\"\"\"\n\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\nprint(\"转换成功\" if success else \"转换失败\")\n```\n\n### 含表格和图片\n```python\nfrom official_doc import md_to_docx\n\nmd_content = \"\"\"# 项目进度表\n\n## 工作进展\n\n| 项目名称 | 负责人 | 进度 | 备注 |\n|----------|--------|------|------|\n| A项目 | 张三 | 80% | 正常 |\n| B项目 | 李四 | 60% | 需加速 |\n\n![架构图](https://example.com/arch.png)\n\n详细说明请参考[官方文档](https://example.com)。\n\"\"\"\n\nmd_to_docx(md_content, \"进度表_公文格式.docx\")\n```\n\n### AI Agent 集成\n```python\nfrom official_doc import md_to_docx\n\nclass OfficialDocSkill:\n    name = \"official-doc\"\n    description = \"公文格式转换 - 将 Markdown 转为党政机关公文格式\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output_公文格式.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"公文格式转换完成\" if success else \"转换失败\"\n        }\n```\n\n### 定时任务\n```python\nimport schedule\nimport time\nfrom official_doc import md_to_docx\n\ndef generate_report():\n    content = generate_report_content()\n    today = time.strftime(\"%Y-%m-%d\")\n    md_to_docx(content, f\"工作简报_{today}_公文格式.docx\")\n\nschedule.every().monday.at(\"09:00\").do(generate_report)\n```\n\n---\n\n## 格式规范\n\n### 页面设置\n| 设置项 | 规范值 |\n|--------|--------|\n| 上边距 | 3.7cm |\n| 下边距 | 3.5cm |\n| 左边距 | 2.8cm |\n| 右边距 | 2.6cm |\n| 行间距 | 固定值 26 磅 |\n| 首行缩进 | 2字符（640 twips） |\n\n### 字体设置\n| 元素 | Markdown | 字体 | 字号 |\n|------|----------|------|------|\n| 大标题（单个#） | `#` | 方正小标宋简体 | 二号 |\n| 一级标题（多个#） | `#` | 黑体 | 三号 |\n| 二级标题 | `##` | 黑体 | 三号 |\n| 三级标题 | `###` | 楷体_GB2312 | 三号 |\n| 四级标题 | `####` | 仿宋_GB2312 | 三号 |\n| 正文 | 普通文本 | 仿宋_GB2312 | 三号 |\n| 加粗文本 | `**text**` | 黑体 | 三号 |\n| 斜体文本 | `*text*` | 楷体_GB2312 | 三号 |\n| 链接 | `[text](url)` | 仿宋_GB2312 蓝色下划线 | 三号 |\n| 表格表头 | `| 表头 |` | 黑体 | 三号 |\n| 表格内容 | `| 内容 |` | 仿宋_GB2312 | 三号 |\n| 代码块 | ` ``` ` | 仿宋_GB2312 | 小四号 |\n| 页码 | - | 宋体 | 四号 |\n\n### 标题编号规则\n| 层级 | 格式示例 | 说明 |\n|------|----------|------|\n| 大标题 | 公文标题 | 单个#标题居中，不加序号 |\n| 一级标题 | 一、章节名称 | 多个#标题自动加序号 |\n| 二级标题 | 一、章节名称 | ## 标题自动加序号 |\n| 三级标题 | （一）小节名称 | ### 标题加中文括号序号 |\n| 四级标题 | 正文格式 | #### 标题不加序号 |\n\n### 支持的 Markdown 元素\n| 元素 | 转换效果 |\n|------|----------|\n| 标题 `# / ## / ### / ####` | 智能层级判断 + 自动编号 |\n| 段落 | 正文仿宋三号，首行缩进2字符 |\n| 有序列表 `1. 2. 3.` | 自动编号，支持嵌套 |\n| 无序列表 `- / *` | 圆点标记，支持嵌套 |\n| 表格 `| ... |` | Word表格，表头黑体 |\n| 图片 `![alt](url)` | 居中图片 + 图注 |\n| 链接 `[text](url)` | 蓝色下划线超链接 |\n| 加粗 `**text**` | 黑体 |\n| 斜体 `*text*` | 楷体 |\n| 代码块 ` ``` ` | 仿宋小四号 |\n| 水平线 `---` | 忽略 |\n\n---\n\n## 依赖要求\n\n| 依赖 | 版本 |\n|------|------|\n| Python | >= 3.8 |\n| python-docx | >= 1.1.0 |\n| markdown-it-py | >= 3.0.0 |\n\n---\n\n## 支持平台\n\n- ✅ Windows 10/11\n- ✅ Linux\n- ✅ macOS\n\n---\n\n## 项目链接\n\n- GitHub: https://github.com/EdwardWason/official-doc\n- Release: https://github.com/EdwardWason/official-doc/releases\n- README: https://github.com/EdwardWason/official-doc/blob/main/README.md\n\nFile v1.1.0:README.md\n\n# 📄 Official Doc - Document Format Converter\n\n🇨🇳 [中文文档](README_CN.md) | 🇺🇸 English\n\nConvert Markdown documents to Chinese government official document format (GB/T 9704-2012) Word documents. Focused on formatting conversion only — does not add red header, record mark, signature block, or other decorative elements of official documents.\n\n---\n\n## ⚠️ Important Notes\n\nThis tool only provides formatting functionality and does not review content. Please ensure that the official documents generated using this tool comply with relevant regulations and requirements.\n\n---\n\n## ✨ Features\n\n| Feature | Description |\n|---------|-------------|\n| 🚀 **One-click Conversion** | Convert Markdown to Word official document format easily |\n| 📋 **Standard Compliance** | Strictly follows GB/T 9704-2012 standard |\n| 🤖 **Multi-Agent Support** | Works with OpenClaw, Hermes Agent, Claude Code, etc. |\n| 🔄 **Dual Output** | Generate both Markdown (for machines) and Word (for humans) |\n| 📊 **Automation Ready** | Supports scheduled tasks for automatic report generation |\n| 📦 **Easy Integration** | Provides standard Python API for system integration |\n\n---\n\n## 🆕 v1.1.0 New Features\n\n- Introduced **markdown-it-py** parser, supporting multi-line paragraphs and nested lists\n- Smart `#` heading detection: a single `#` is treated as a main title (centered, no numbering); multiple `#` headings are treated as first-level headings (with numbering)\n- First line indent precisely aligned with national standard (640 twips = width of 2 Size-3 Chinese characters)\n- Added support for **tables, images, hyperlinks, code blocks, and nested lists**\n- **Bold text** is automatically converted to SimHei (黑体); *italic text* is automatically converted to KaiTi (楷体)\n\n---\n\n## 🚀 Quick Start\n\n### System Requirements\n\n| Component | Requirement |\n|-----------|-------------|\n| OS | Windows 10/11, Linux, macOS |\n| Python | 3.8+ (3.11 / 3.12 / 3.13 supported) |\n| Dependency | python-docx >= 1.1.0, markdown-it-py >=","readmeExcerpt":"Skill: Gongwen Formatter 公文格式转换 Owner: edwardwason Summary: 公文格式转换 — 将 Markdown 转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文件。可选能力：远程图片下载（仅 http/https/data:image，可通过 download_images=False 关闭）。Do NOT：不做文体识别、不添加红头/版记/落款、不做内容审核。 Tags: chinese:1.1.4, document:1.1.4, formatting:1.1.4, gb9704:1.1.4, latest:1.1.9, markdown:1.1.4, security:1.1.4, word:1.1.4 Version history: v1.1.9 | 2026-09-22T09:33:58.779Z | user v1.1.9 displayNam","codeSnippets":[],"executableExamples":[{"language":"python","snippet":"from official_doc import md_to_docx\n\nmd_content = \"\"\"# 工作简报\n\n## 一、上周工作总结\n\n本周完成了系统升级任务。\n\n### （一）主要工作\n1. 服务器部署\n2. 数据迁移\n3. 测试验证\n\n### （二）下周计划\n继续推进优化工作。\n\"\"\"\n\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\nprint(\"转换成功\" if success else \"转换失败\")"},{"language":"python","snippet":"from official_doc import md_to_docx\n\nmd_content = \"\"\"# 项目进度表\n\n## 工作进展\n\n| 项目名称 | 负责人 | 进度 | 备注 |\n|----------|--------|------|------|\n| A项目 | 张三 | 80% | 正常 |\n| B项目 | 李四 | 60% | 需加速 |\n\n![架构图](https://example.com/arch.png)\n\n详细说明请参考[官方文档](https://example.com)。\n\"\"\"\n\nmd_to_docx(md_content, \"进度表_公文格式.docx\")"},{"language":"python","snippet":"from official_doc import md_to_docx\n\nclass OfficialDocSkill:\n    name = \"official-doc\"\n    description = \"公文格式转换 - 将 Markdown 转为党政机关公文格式\"\n\n    def execute(self, md_content, output_path=None):\n        if output_path is None:\n            output_path = \"output_公文格式.docx\"\n\n        success = md_to_docx(md_content, output_path)\n\n        return {\n            \"success\": success,\n            \"output_path\": output_path,\n            \"message\": \"公文格式转换完成\" if success else \"转换失败\"\n        }"},{"language":"python","snippet":"import schedule\nimport time\nfrom official_doc import md_to_docx\n\ndef generate_report():\n    content = generate_report_content()\n    today = time.strftime(\"%Y-%m-%d\")\n    md_to_docx(content, f\"工作简报_{today}_公文格式.docx\")\n\nschedule.every().monday.at(\"09:00\").do(generate_report)"},{"language":"python","snippet":"md_to_docx(md_content, output_path, download_images=False)\n# When disabled, remote images are replaced with a [Image: alt] text placeholder, with no network requests made."},{"language":"bash","snippet":"pip install \"python-docx~=1.1.0\" \"markdown-it-py~=3.0.0\""}],"parameters":null,"dependencies":[],"permissions":[],"extractedFiles":[{"path":"skill.md","content":"---\nslug: gongwen-formatter\nname: gongwen-formatter\ndisplayName: Gongwen Formatter 公文格式转换\nname_cn: 公文格式转换\nversion: 1.1.9\nauthor: EdwardWason\nlicense: MIT\nhomepage: https://github.com/EdwardWason/official-doc\ndescription: 公文格式转换 — 将 Markdown 转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文件。可选能力：远程图片下载（仅 http/https/data:image，可通过 download_images=False 关闭）。Do NOT：不做文体识别、不添加红头/版记/落款、不做内容审核。\nsummary: 将 Markdown 转换为符合 GB/T 9704-2012 标准的党政机关公文格式 Word 文件。\nallowed-tools:\n  - filesystem (write .docx output)\n  - net.http (GET image download, http/https only, toggleable via download_images=False)\ntriggers:\n  - 公文格式转换\n  - 转换公文格式\n---\n\n# 📄 official-doc - 公文格式转换\n\n## 技能信息\n\n### 基本信息\n| 属性 | 说明 |\n|------|------|\n| **名称** | official-doc |\n| **中文名称** | 公文格式转换 |\n| **版本** | 1.1.9 |\n| **作者** | EdwardWason |\n| **许可证** | MIT |\n| **主页** | https://github.com/EdwardWason/official-doc |\n\n### 触发词\n- **公文格式转换**\n- **转换公文格式**\n\n### 功能描述\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\n\n### 适用场景\n- AI Agent 生成公文格式报告\n- 定时任务自动生成工作简报、周报、月报\n- Markdown 文档批量转换为标准公文格式\n- 行业研报格式标准化输出\n\n### Do NOT（超出范围）\n- ❌ **不做文体识别**：不区分通知/通报/报告/请示等公文文种，统一按 Markdown 结构转换\n- ❌ **不添加公文装饰要素**：不生成红头、版记、落款、签发人、密级标识等\n- ❌ **不做内容审核**：不审查内容合规性、不校验公文要素完整性\n- ❌ **不做双向转换**：仅支持 Markdown → Word 单向，不支持 Word → Markdown 反向\n- ❌ **不读取本地敏感文件**：不读取 memory/profile/credentials 等任何用户数据\n\n### v1.1.0 新增功能\n- 引入 markdown-it-py 解析器，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- 加粗文本自动转为楷体加粗，斜体文本自动转为楷体\n\n### v1.1.2 安全升级（响应 ClawHub SkillSpector 审计）\n- `download_image()` 增加 URL scheme 白名单（仅 `http://`/`https://`/`data:image`），防止 SSRF\n- `md_to_docx()` 新增 `download_images=True` 参数，受限网络环境可设为 `False` 完全关闭网络请求\n- `_handle_standalone_image()` 关闭图片下载时以 `[图片: alt]` 文字占位替代\n- `requirements.txt` 改用 `~=` 兼容版本锁定（python-docx~=1.1.0、markdown-it-py~=3.0.0）\n- README 中英文版增加 \"图片下载网络请求说明 / Network Access Disclosure\" 用户警告段落\n\n### v1.1.3 修复（响应 v1.1.2 后 SkillSpector 二次审计）\n- 修复 v1.1.2 漏改：README/skill.md/skill.json 中残留的 `>=` 全部改为 `~=`（依赖版本一致性）\n- frontmatter 增加 `allowed-tools` 字段，声明 filesystem（写 .docx）和 net.http（图片下载，可关闭）两项权限\n- 7 项 findings 中：2 项真实漏改（本次修复）、3 项 stale（已修复但被重复扫描，本次通过 allowed-tools 增强声明）、2 项过度修改（保留现有设计，不采纳）\n\n### v1.1.4 格式修复（对齐公文规范）\n- **加粗句（`**text**`）修复**：由\"黑体不加粗\"改为\"楷体_GB2312 加粗\"——符合公文段首\"一是/二是\"句式标准格式\n- **三级标题（`###`）修复**：由\"楷体不加粗\"改为\"楷体_GB2312 加粗\"——符合 GB/T 9704 二级标题（（一））楷体加粗规范\n- 黑体标题（`#`/`##`）、正文仿宋、斜体楷体等保持不变\n\n### v1.1.8 格式增强（间隔号序号规范化为公文标准序号）\n- **「一 · 源头」→「一、源头」**：识别到间隔号体例时自动改写为公文标准序号，\n  `##` →「一、」（阿拉伯数字自动转中文数字），`###` →「（五）」\n- 结构性标题（「结语 ·」「附一 ·」）保持原样不套序号\n\n### v1.1.7 格式修复（序号去重扩展·间隔号体例）\n- **间隔号序号去重**：新增「一 · 源头」「1 · 标题」间隔号体例识别，\n  以及「结语 ·」「附一 ·」结构性标题识别，避免自动编号与原文序号重复\n- 涌现写作交付成稿常用间隔号体例，此前会产生「二、一·源头」这类重复序号\n\n### v1.1.6 格式修复（段落按源码行拆分）\n- **连续非空行不再合并**：连续的非空行（软换行 `softbreak`）还原为独立段落，\n  解决\"甲方：/住所：/法定代表人：\"这类一行一要素文本被挤在同一段的问题\n- 拆分后的每段独立应用两端对齐 + 固定行距 + 首行缩进 2 字（640 twips）\n- 本版一并纳入此前仅写入代码 docstring 的 v1.1.5 标题层级重定义（`#` 大标题 / `##` 一级标题 / `###` 楷体加粗 / `####` 仿宋加粗 + 序号去重）\n\n---\n\n## 权限声明\n\n本技能执"},{"path":"README.md","content":"# 📄 Official Doc - Document Format Converter\n\n🇨🇳 [中文文档](README_CN.md) | 🇺🇸 English\n\nConvert Markdown documents to Chinese government official document format (GB/T 9704-2012) Word documents. Focused on formatting conversion only — does not add red header, record mark, signature block, or other decorative elements of official documents.\n\n---\n\n## ⚠️ Important Notes\n\nThis tool only provides formatting functionality and does not review content. Please ensure that the official documents generated using this tool comply with relevant regulations and requirements.\n\n### Network Access Disclosure for Image Download\n\n- When the Markdown contains remote images via `![alt](http/https URL)`, this tool will **automatically issue outbound network requests** to download and embed them into the Word document.\n- Only `http://`, `https://`, and `data:image` schemes are allowed; other schemes (e.g., `file://`, `ftp://`) are silently skipped to prevent SSRF.\n- **Privacy & Compliance Notice**: In restricted network environments (intranet, classified networks, air-gapped systems), disable remote image download by passing `download_images=False`:\n\n```python\nmd_to_docx(md_content, output_path, download_images=False)\n# When disabled, remote images are replaced with a [Image: alt] text placeholder, with no network requests made.\n```\n\n- For untrusted Markdown sources, review image URLs beforehand to avoid leaking network metadata to attacker-controlled endpoints.\n\n---\n\n## ✨ Features\n\n| Feature | Description |\n|---------|-------------|\n| 🚀 **One-click Conversion** | Convert Markdown to Word official document format easily |\n| 📋 **Standard Compliance** | Strictly follows GB/T 9704-2012 standard |\n| 🤖 **Multi-Agent Support** | Works with OpenClaw, Hermes Agent, Claude Code, etc. |\n| 🔄 **Dual Output** | Generate both Markdown (for machines) and Word (for humans) |\n| 📊 **Automation Ready** | Supports scheduled tasks for automatic report generation |\n| 📦 **Easy Integration** | Provides standard Python API for system integration |\n\n---\n\n## 🆕 v1.1.0 New Features\n\n- Introduced **markdown-it-py** parser, supporting multi-line paragraphs and nested lists\n- Smart `#` heading detection: a single `#` is treated as a main title (centered, no numbering); multiple `#` headings are treated as first-level headings (with numbering)\n- First line indent precisely aligned with national standard (640 twips = width of 2 Size-3 Chinese characters)\n- Added support for **tables, images, hyperlinks, code blocks, and nested lists**\n- **Bold text** is automatically converted to KaiTi_GB2312 bold (楷体加粗); *italic text* is automatically converted to KaiTi (楷体)\n\n---\n\n## 🚀 Quick Start\n\n### System Requirements\n\n| Component | Requirement |\n|-----------|-------------|\n| OS | Windows 10/11, Linux, macOS |\n| Python | 3.8+ (3.11 / 3.12 / 3.13 supported) |\n| Dependency | python-docx ~= 1.1.0, markdown-it-py ~= 3.0.0 |\n\n### Installation\n\n**Method 1: Using pip**\n```bash\npip install \"python-docx~=1.1.0\" \"m"},{"path":"_meta.json","content":"{\n  \"ownerId\": \"kn75zj7vzdyvap84adxa8heyyd82f5eh\",\n  \"slug\": \"gongwen-formatter\",\n  \"version\": \"1.1.9\",\n  \"publishedAt\": 1790069638779\n}"},{"path":"CHANGELOG.md","content":"# Changelog\n\n本文件记录 official-doc（gongwen-formatter）所有版本的变更。\n\n格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.0.0/)，\n版本号遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/)。\n\n## [1.1.9] - 2026-09-22\n\n### 元数据（三平台同步 · SkillHub 标题双语化）\n\n#### Changed\n- `displayName` 改为中英双语 `Gongwen Formatter 公文格式转换`，便于中文用户在 SkillHub 检索（无功能变更）\n- 三平台同步发布（GitHub + ClawHub + SkillHub）\n\n## [1.1.8] - 2026-09-20\n\n### 格式增强（间隔号序号规范化为公文标准序号）\n\n#### Changed\n- **间隔号序号规范化**：识别到「一 · 源头」「2 · 源头」间隔号体例时，\n  不再原样保留，而是改写为公文标准序号：\n  - `##`（一级标题）：「一 · 源头」→「一、源头」，阿拉伯数字自动转中文数字（「2 · 」→「二、」）\n  - `###`（二级标题）：「五 · 天长专章」→「（五）天长专章」\n  - 新增 `normalize_heading_number()`，在 `heading_open` 渲染前原地改写 children 首 token\n- 结构性标题（「结语 ·」「附一 ·」等）保持原样，不套序号\n\n## [1.1.7] - 2026-09-20\n\n### 格式修复（序号去重正则未覆盖间隔号体例，导致自动编号与原文序号重复）\n\n#### Fixed\n- **间隔号序号未被识别**：涌现写作交付成稿常用「一 · 源头」「五 · 天长专章」等间隔号体例，\n  此前 `has_heading_number()` 仅识别「一、」「（一）」「1.」「第X章」四种格式，\n  间隔号写法匹配不上 → 引擎判定\"原文没带序号\" → 自动补号，产生「二、一·源头」「（一）五·天长专章」等重复\n  - 修复：新增 `[一二三四五六七八九十]{1,3}\\s*[·・•.]\\s*` 和 `\\d{1,2}\\s*[·・•]\\s*` 两条正则\n  - 同时增加结构性标题识别：`结语 ·`、`引言 ·`、`附一 ·`、`附录` 等，\n    这些标题本身即序号终结标记，不应再追加公文序号\n\n## [1.1.6] - 2026-09-14\n\n### 格式修复（响应跨任务调用反馈：合同/协议\"一行一要素\"被合并为单段）\n\n#### Fixed\n- **连续非空行被合并为单段**：Markdown 中连续的非空行（行间为软换行 `softbreak`）此前被解析为同一个段落，\n  \"甲方：/住所：/法定代表人：\"这类一行一要素的协议抬头会被挤在同一段内显示\n  - 根因：`render_inline_with_formatting` 对 `softbreak` 直接 `pass`，行边界信息在渲染阶段被丢弃\n  - 修复：新增 `split_inline_on_linebreaks()`，在 `paragraph_open` 处按 `softbreak`/`hardbreak`\n    将 inline children 拆分为多个独立段，每段独立应用两端对齐 + 固定行距 + 首行缩进 640 twips（2 字）\n  - 效果：每个源码行还原为独立段落，各自首行缩进 2 字，消除段内断行造成的左边缘参差\n\n#### Notes\n- 本版一并纳入此前仅写入代码 docstring、未落到 CHANGELOG / 版本号文件的 v1.1.5 标题层级重定义：\n  `#` 大标题（方正小标宋简体二号，居中，一律不加序号）/ `##` 一级标题（黑体三号）/\n  `###` 楷体_GB2312 加粗 / `####` 仿宋_GB2312 加粗；标题原文已带序号时不再自动补序号\n\n## [1.1.4] - 2026-07-15\n\n### 格式修复（对齐公文规范，响应跨任务调用反馈）\n\n#### Fixed\n- **加粗句（`**text**`）修复**：由\"黑体不加粗\"改为\"楷体_GB2312 加粗\"\n  - 原问题：`**一是强化谋划动员**` 这类段首加粗句被渲染为黑体三号且无加粗效果，强调完全丢失\n  - 根因：`render_inline_with_formatting` 的 strong 分支使用 `set_font(run, '黑体', font_size)`，black 默认 False\n  - 修复：strong 分支改为 `set_font(run, '楷体_GB2312', font_size, bold=True)`，符合公文段首\"一是/二是\"句式标准格式\n- **三级标题（`###`）修复**：由\"楷体不加粗\"改为\"楷体_GB2312 加粗\"\n  - 根因：h3 分支的标题文字和前缀均未传 `bold=True`\n  - 修复：h3 分支统一传 `bold=True`，符合 GB/T 9704 二级标题（（一））楷体加粗规范\n- `render_inline_with_formatting` 增加 `bold` 参数，支持标题整体加粗\n\n#### 保持不变的格式\n- 黑体标题（`#`/`##`）不加粗（用户明确要求，黑体本身已足够醒目）\n- 正文仿宋三号不加粗\n- 斜体楷体不加粗\n- 链接蓝色下划线\n\n## [1.1.3] - 2026-07-14\n\n### 修复（响应 v1.1.2 后 SkillSpector 二次审计 7 findings）\n\n#### Fixed\n- 修复 v1.1.2 漏改：README.md / README_CN.md / skill.md / skill.json 中残留的 `>=` 全部改为 `~=`（依赖版本一致性）\n  - 根因：v1.1.2 只改了 requirements.txt 和 setup.py，漏改了 README 安装示例、skill.md 依赖表、skill.json dependencies 字段\n  - SkillSpector 扫描所有文件，因此仍报告 `>=` 为 Unpinned Dependencies\n\n#### Added\n- frontmatter 增加 `allowed-tools` 字段，声明 filesystem（写 .docx）和 net.http（图片下载，可关闭）两项权限\n  - 目的：让 ClawHub SkillSpector 能从 frontmatter 识别权限声明，减少 MCP Least Privilege finding\n\n#### SkillSpector v1.1.2 二次审计 7 findings 评估\n| Finding | 评估 | 处理 |\n|---------|------|------|\n| MCP "},{"path":"README_CN.md","content":"# 📄 Official Doc - 公文格式转换\n\n🇨🇳 中文文档 | 🇺🇸 [English](README.md)\n\n将 Markdown 文档转换为符合 **GB/T 9704-2012** 党政机关公文格式的 Word 文档。专注排版格式转换，不添加红头、版记、落款等公文装饰要素。\n\n---\n\n## ⚠️ 重要说明\n\n本工具仅提供格式排版功能，不负责内容审核。请确保使用本工具生成的公文内容符合相关规定和要求。\n\n### 关于图片下载的网络请求说明\n\n- 当 Markdown 中包含 `![alt](http/https URL)` 远程图片时，本工具会**自动发起网络请求**下载并嵌入到 Word 文档中。\n- 仅允许 `http://`、`https://` 和 `data:image` 协议；其他 scheme（如 `file://`、`ftp://`）会被静默跳过，防止 SSRF。\n- **隐私与合规提示**：在受限网络环境（内网、保密网络、隔离环境）中使用时，建议通过 `download_images=False` 参数关闭远程图片下载：\n\n```python\nmd_to_docx(md_content, output_path, download_images=False)\n# 关闭后，远程图片将以 [图片: alt] 文字占位替代，不发起任何网络请求\n```\n\n- 对不可信来源的 Markdown 文档，请先审阅图片 URL，避免向攻击者控制的端点泄露网络元数据。\n\n---\n\n## ✨ 功能特点\n\n| 功能 | 描述 |\n|------|------|\n| 🚀 **一键转换** | Markdown 转 Word 公文格式，简单易用 |\n| 📋 **标准遵循** | 严格按照 GB/T 9704-2012 党政机关公文格式标准 |\n| 🤖 **多智能体兼容** | 支持 OpenClaw、Hermes Agent、Claude Code 等 AI 智能体 |\n| 🔄 **双重输出** | 一份内容，同时生成 Markdown（供机器读）和 Word（供人读） |\n| 📊 **自动化支持** | 支持定时任务自动生成简报、周报、月报 |\n| 📦 **易于集成** | 提供标准 Python API，便于其他系统集成 |\n\n---\n\n## 🆕 v1.1.0 新特性\n\n- 引入 **markdown-it-py** 解析器，支持多行段落、嵌套列表\n- `#` 标题智能判断：单个视为大标题（居中不加序号），多个视为一级标题（加序号）\n- 首行缩进精确对齐国标（640 twips = 2个三号汉字宽度）\n- 新增表格、图片、超链接、代码块、嵌套列表支持\n- **加粗文本**自动转为楷体加粗，*斜体文本*自动转为楷体\n\n---\n\n## 🚀 快速开始\n\n### 环境要求\n\n| 组件 | 要求 |\n|------|------|\n| 操作系统 | Windows 10/11、Linux、macOS |\n| Python | 3.8+（支持 3.11 / 3.12 / 3.13） |\n| 依赖 | python-docx ~= 1.1.0, markdown-it-py ~= 3.0.0 |\n\n### 安装方法\n\n**方式一：使用 pip 安装**\n```bash\npip install \"python-docx~=1.1.0\" \"markdown-it-py~=3.0.0\"\n```\n\n**方式二：克隆仓库**\n```bash\ngit clone https://github.com/EdwardWason/official-doc.git\ncd official-doc\npip install -r requirements.txt\n```\n\n### 使用示例\n\n```python\nfrom official_doc import md_to_docx\n\n# Markdown 内容\nmd_content = \"\"\"# 工作简报\n\n## 一、上周工作总结\n\n本周完成了系统升级任务，主要包括：\n\n### （一）主要工作\n1. 完成服务器部署\n2. 完成数据迁移\n3. 完成测试验证\n\n### （二）存在问题\n部分功能需要进一步优化。\n\n### （三）下周计划\n继续推进优化工作。\n\"\"\"\n\n# 转换为公文格式\nsuccess = md_to_docx(md_content, \"工作简报_公文格式.docx\")\nprint(\"转换成功\" if success else \"转换失败\")\n```\n\n---\n\n## 📋 公文格式规范（GB/T 9704-2012）\n\n### 页面设置\n\n| 设置项 | 规范值 |\n|--------|--------|\n| 纸张尺寸 | A4 (210mm × 297mm) |\n| 上边距 | 3.7cm |\n| 下边距 | 3.5cm |\n| 左边距 | 2.8cm |\n| 右边距 | 2.6cm |\n| 行间距 | 固定值 26 磅 |\n| 首行缩进 | 2字符（640 twips） |\n\n### 字体规范\n\n| 元素 | Markdown 标记 | 字体 | 字号 |\n|------|--------------|------|------|\n| 大标题 | `#`（单个） | 方正小标宋简体 | 二号 |\n| 一级标题 | `##` / `#`（多个） | 黑体 | 三号 |\n| 二级标题 | `###` | 楷体_GB2312 加粗 | 三号 |\n| 三级标题 | `####` | 仿宋_GB2312 | 三号 |\n| 正文 | 普通文本 | 仿宋_GB2312 | 三号 |\n| 页码 | - | 宋体 | 四号 |\n\n### 标题编号规则\n\n| 层级 | 判断条件 | 格式示例 |\n|------|----------|----------|\n| 大标题 | 文档中仅一个 `#` | 公文标题（居中，不加序号） |\n| 一级标题 | `##` 或多个 `#` | 一、章节名称 |\n| 二级标题 | `###` | （一）小节名称 |\n| 三级标题 | `####` | 1. 项目名称 |\n\n### 支持的 Markdown 元素\n\n| 元素 | Markdown 语法 | 说明 |\n|------|--------------|------|\n| 标题 | `#` `##` `###` `####` | 智能标题判断 |\n| 段落 | 普通文本 | 支持多行段落 |\n| 有序列表 | `1. 2. 3.` | 支持嵌套列表 |\n| 无序列表 | `- - -` | 支持嵌套列表 |\n| 表格 | `\\| 列 \\| 列 \\|` | 完整表格支持 |\n| 图片 | `![alt](url)` | 行内图片 |\n| 超链接 | `[文本](url)` | 超链接 |\n| 加粗 | `**文本**` | 自动转为楷体加粗 |\n| 斜体 | `*文本*` | 自动转为楷体 |\n| 代码块 | `` ```代码``` `` | 等宽字体"}],"languages":[],"docsSourceLabel":"CLAWHUB","editorialOverview":"公文格式转换 — 将 Markdown 转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文件。可选能力：远程图片下载（仅 http/https/data:image，可通过 download_images=False 关闭）。Do NOT：不做文体识别、不添加红头/版记/落款、不做内容审核。 Skill: Gongwen Formatter 公文格式转换 Owner: edwardwason Summary: 公文格式转换 — 将 Markdown 转换为符合 GB/T 9704-2012 党政机关公文格式的 Word 文件。可选能力：远程图片下载（仅 http/https/data:image，可通过 download_images=False 关闭）。Do NOT：不做文体识别、不添加红头/版记/落款、不做内容审核。 Tags: chinese:1.1.4, document:1.1.4, formatting:1.1.4, gb9704:1.1.4, latest:1.1.9, markdown:1.1.4, security:1.1.4, word:1.1.4 Version history: v1.1.9 | 2026-09-22T09:33:58.779Z | user v1.1.9 displayNam","editorialQuality":{"score":100,"threshold":65,"status":"ready","wordCount":1019,"uniquenessScore":53,"reasons":[]}},"media":{"evidence":{"source":"no-media","verified":false,"confidence":"low","updatedAt":"2026-10-09T17:54:34.903Z","emptyReason":"No screenshots, media assets, or demo links are available."},"primaryImageUrl":null,"mediaAssetCount":0,"assets":[],"demoUrl":null},"ownerResources":{"evidence":{"source":"unclaimed","verified":false,"confidence":"low","updatedAt":"2026-10-09T17:54:34.903Z","emptyReason":"This page has not been claimed by the agent owner."},"hasCustomPage":false,"customPageUpdatedAt":null,"customLinks":[],"structuredLinks":{"docsUrl":null,"demoUrl":null,"supportUrl":null,"pricingUrl":null,"statusUrl":null},"customPage":null},"relatedAgents":{"evidence":{"source":"protocol-neighbors","verified":false,"confidence":"medium","updatedAt":"2026-10-10T02:30:32.162Z","emptyReason":null},"items":[{"id":"8ebccd8e-3863-4187-8355-c3f14e1f9edf","entityType":"agent","canonicalPath":"/agent/iofficeai-aionui","slug":"iofficeai-aionui","name":"AionUi","description":"Free, local, open-source 24/7 Cowork app and OpenClaw for Gemini CLI, Claude Code, Codex, OpenCode, Qwen Code, Goose CLI, Auggie, and more | 🌟 Star if you like it!","url":"https://github.com/iOfficeAI/AionUi","homepage":"https://www.aionui.com","source":"GITHUB_REPOS","protocols":["MCP","OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-10-09T19:11:12.944Z","createdAt":"2026-02-25T03:38:16.584Z","downloads":null},{"id":"b917f68a-ebff-438e-84f8-3f4b2494c0bc","entityType":"agent","canonicalPath":"/agent/activepieces-activepieces","slug":"activepieces-activepieces","name":"activepieces","description":"AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents","url":"https://github.com/activepieces/activepieces","homepage":"https://www.activepieces.com","source":"GITHUB_REPOS","protocols":["OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-04-15T02:22:12.426Z","createdAt":"2026-02-25T03:38:12.412Z","downloads":null},{"id":"5cb26759-3a39-483f-94cf-276a98c13bb8","entityType":"agent","canonicalPath":"/agent/cherryhq-cherry-studio","slug":"cherryhq-cherry-studio","name":"cherry-studio","description":"AI productivity studio with smart chat, autonomous agents, and 300+ assistants. Unified access to frontier LLMs","url":"https://github.com/CherryHQ/cherry-studio","homepage":"https://cherry-ai.com","source":"GITHUB_REPOS","protocols":["MCP","OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-04-11T14:38:40.986Z","createdAt":"2026-02-25T03:38:19.379Z","downloads":null},{"id":"6f6582d0-5d76-4f0f-b81d-86520247950b","entityType":"agent","canonicalPath":"/agent/copilotkit-copilotkit","slug":"copilotkit-copilotkit","name":"CopilotKit","description":"The Frontend for Agents & Generative UI. React + Angular","url":"https://github.com/CopilotKit/CopilotKit","homepage":"https://docs.copilotkit.ai","source":"GITHUB_REPOS","protocols":["OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-03-25T09:50:57.846Z","createdAt":"2026-02-25T03:39:14.617Z","downloads":null}],"links":{"hub":"/agent","source":"/agent/source/clawhub","protocols":[{"label":"OpenClaw","href":"/agent/protocol/openclew"}]}}}