← 返回 Skills 市场
kaisersong

Kai Docx Generator

作者 Kaiser · GitHub ↗ · v1.1.1 · MIT-0
darwinlinuxwindows ✓ 安全检测通过
79
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install kai-docx-generator
功能描述
Generate professional .docx documents from Markdown text or fill data into .docx templates. Use when: converting markdown to Word, generating reports/contrac...
使用说明 (SKILL.md)

kai-docx-generator

Generate professional .docx documents from Markdown, or fill data into .docx templates.

Core Principles

  1. Zero Fabrication — Never invent content. If data is missing, use placeholder text ([待填写]) or ask the user.
  2. Template Filling is XML-level{{variable_name}} patterns are matched at the w:t XML node level inside the .docx. Values are sanitized to escape & \x3C > " ' and remove control characters.
  3. Security: Path Validation — Image paths must be relative or within the current working directory. Absolute paths (e.g. /tmp/...) and path traversal (..) are rejected.
  4. Auto-Truncation — Exceeding input limits (200KB, 20 images, 50 table rows, 20 table columns) triggers automatic truncation without error.
  5. Template Strictness--strict mode on fill_template.py returns exit code 1 when any placeholder remains unreplaced, enabling CI/CD gate usage.

Commands

Command What it does
python3 \x3Cskill-path>/scripts/generate.py \x3Cinput.md> \x3Coutput.docx> Convert Markdown to .docx
python3 \x3Cskill-path>/scripts/generate.py --style \x3Cstyle> \x3Cinput.md> \x3Coutput.docx> Convert with a specific style
`python3 \x3Cskill-path>/scripts/fill_template.py --data \x3Cdata.json frontmatter.md> --output \x3Cout.docx> \x3Ctemplate.docx>`
python3 \x3Cskill-path>/scripts/fill_template.py --strict --data \x3Cdata.json> --output \x3Cout.docx> \x3Ctemplate.docx> Fill template, fail if placeholders remain
python3 \x3Cskill-path>/scripts/validate.py \x3Cfile.docx> Validate .docx file structure

Markdown → .docx

python3 \x3Cskill-path>/scripts/generate.py input.md output.docx
python3 \x3Cskill-path>/scripts/generate.py --style report input.md output.docx

Content-Type → Style Routing

When no --style is specified, recommend a style based on topic keywords:

Topic keywords Recommended style Use case
合同、协议、条款、contract, agreement contract Contracts & legal documents
报告、分析、数据、KPI、report, analysis, dashboard report Business reports (blue headers)
会议纪要、meeting minutes, 讨论 meeting Meeting minutes (compact layout)
红头文件、通知、通报、dispatch, official notice dispatch Official dispatchs (red header)
技术、API、架构、代码、spec, architecture tech_spec Technical specs (monospace body)
公函、商务信、letter business_letter Business letters
公告、公告通知、notice, announcement notice Official notices (large bold text)
其他 / general standard General documents

When routing, announce: "推荐使用 [style] 样式 ([description]),可用 --style 覆盖。"

Default Output Filename

If the user does not specify an output filename, derive it from the input file:

  • \x3Cinput>.md\x3Cinput>.docx (same basename, replace extension)
  • For generated content (no input file), use: doc-\x3CYYYY-MM-DD>-\x3Cslug>.docx
  • Slug rule: lowercase the title/topic, replace spaces and non-ASCII with hyphens, keep only alphanumeric ASCII and hyphens, max 30 chars.

Supported Markdown Features

Feature Syntax
Headings (H1-H3) #, ##, ###
Paragraphs Text blocks
Bold / Italic **bold**, *italic*
Bullet / Numbered lists -, 1.
Tables Standard GFM tables
Code blocks Triple backticks, with optional language
Blockquotes (callout) > text → info box
Images ![caption](path)
Page break \x3C!-- pagebreak -->
Horizontal rule ---
YAML front matter `---\
title: ...\
---`

Style Presets

Style Use case
standard (default) General documents
contract Contracts & agreements (formal, 12pt)
report Business reports (blue headers, 10.5pt)
meeting Meeting minutes (compact, 10.5pt)
business_letter Business letters (traditional format)
tech_spec Technical specifications (monospace, dark theme)
dispatch Official dispatchs / 红头文件 (red header)
notice Official notices (bold, 14pt)

YAML Front Matter

---
title: Document Title          # 写入 docx core_properties.title
author: Author Name            # 写入 docx core_properties.author
date: 2026-04-10               # 写入 docx core_properties.created
lang: zh                       # 可选: zh | en, 影响默认文本
header:
  text: CONFIDENTIAL           # 页眉文字
  alignment: center            # left | center | right
footer:
  page_number: true            # 显示页码
toc:
  max_level: 3                 # TOC 包含的最大标题级别 (1-3)
---

All fields are optional. title, author, and date are written to the .docx core properties (visible in Word → File → Info).

Template Filling

# With JSON data
python3 \x3Cskill-path>/scripts/fill_template.py --data data.json --output output.docx template.docx

# With Markdown front matter as data
python3 \x3Cskill-path>/scripts/fill_template.py --data frontmatter.md --output output.docx template.docx

# Strict mode: fail if any placeholder remains unreplaced
python3 \x3Cskill-path>/scripts/fill_template.py --strict --data data.json --output output.docx template.docx

Data format (JSON):

{
  "company_name": "Acme Corp",
  "amount": "¥1,000,000",
  "date": "2026-04-10"
}

Template placeholders are {{variable_name}} patterns in the .docx text (matched at w:t XML node level). Values are automatically sanitized to escape XML special characters and remove control characters. Long values are truncated to prevent layout breakage.

--strict Mode

When --strict is passed, the script exits with code 1 if any {{placeholder}} remains unreplaced after filling. This enables CI/CD gating: all placeholders must have corresponding data keys.

Input Limits

  • Markdown size: 200KB max
  • Images: 20 max
  • Table rows: 50 max
  • Table columns: 20 max

Exceeding limits triggers automatic truncation with no error.

QA Process

After generating a .docx, run these checks:

Automated checks (run validate.py on the output):

  1. File is valid ZIP with required structure (word/document.xml, [Content_Types].xml, word/_rels/document.xml.rels)
  2. XML is parseable (no malformed tags)
  3. File size is reasonable (> 50KB warning, > 50MB warning)
  4. No unreplaced {{placeholders}} detected

Visual checks (open in Word/WPS): 5. Style conformance — headings use the correct style preset colors and fonts (see references/style-presets.md for exact values) 6. Spacing — callouts have proper spacing from surrounding elements 7. Tables — column widths are reasonable, no emoji overlap 8. Code blocks — monospace font + gray background rendering 9. TOC — if requested, TOC field code is present (requires Word to update fields) 10. Images — embedded images render at correct size, no broken links

Template filling checks: 11. All {{placeholders}} with matching data keys are replaced 12. No XML corruption — the output opens without error 13. Long values are truncated appropriately (no layout breakage)

Use --validate flag with generate.py to run automated checks automatically after generation.

Works with

  • kai-report-creator — generate .docx reports from markdown output
  • Any Markdown content (reports, specs, meeting notes, contracts)
  • Existing .docx templates with {{placeholder}} variables
安全使用建议
This skill looks safe for its stated purpose of creating and filling Word documents. Before installing, confirm you trust the package source and dependencies, use explicit output paths to avoid overwriting files, and review generated documents because large inputs may be truncated without an error.
功能分析
Type: OpenClaw Skill Name: kai-docx-generator Version: 1.1.1 The kai-docx-generator skill bundle is a well-structured tool for generating Word documents from Markdown or filling templates. It includes explicit security features such as path traversal protection for images in docx_engine.py and XML sanitization in template_filler.py to prevent injection attacks. The parser in md_to_ast.py also enforces resource limits (e.g., 200KB input size, 20 images) to prevent resource exhaustion. No indicators of malicious intent, data exfiltration, or unauthorized execution were found across the code, scripts, or documentation.
能力评估
Purpose & Capability
The stated purpose, README, SKILL.md commands, and evals consistently describe Markdown-to-.docx generation, .docx template filling, and .docx validation.
Instruction Scope
The skill asks the agent to run local Python scripts against user-specified input and output files, and it discloses that oversized inputs may be truncated without error. This is purpose-aligned but users should verify paths and final document contents.
Install Mechanism
The skill installs common Python document-processing dependencies via uv, but the registry source/homepage are not provided and the install spec does not show pinned versions.
Credentials
No credentials, required environment variables, external APIs, or network data flows are declared; local file access is expected for document conversion.
Persistence & Privilege
The artifacts do not show background persistence, privilege escalation, credential/session access, or autonomous activity outside the requested document-generation task.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install kai-docx-generator
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /kai-docx-generator 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.1.1
fix: remove leading page break in TOC that caused blank first pages; add structural TOC tests
元数据
Slug kai-docx-generator
版本 1.1.1
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Kai Docx Generator 是什么?

Generate professional .docx documents from Markdown text or fill data into .docx templates. Use when: converting markdown to Word, generating reports/contrac... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 79 次。

如何安装 Kai Docx Generator?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install kai-docx-generator」即可一键安装,无需额外配置。

Kai Docx Generator 是免费的吗?

是的,Kai Docx Generator 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Kai Docx Generator 支持哪些平台?

Kai Docx Generator 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(darwin, linux, windows)。

谁开发了 Kai Docx Generator?

由 Kaiser(@kaisersong)开发并维护,当前版本 v1.1.1。

💬 留言讨论