This repository documents the skills under skills/. The primary skill, skills/word-expert-formatting, is a custom Claude Code skill that formats Chinese Word content and turns Markdown or plain text into a .docx locally — or normalizes and verifies a refreshed copy of an existing .docx.
It applies all-decimal heading numbering, and --auto-toc inserts a Word TOC field instead of static TOC text.
Requirements:
- Python 3
python-docx
python3 -m pip install python-docxThe script checks these at startup and exits with a clear error message if a required dependency is missing. Output documents are created from a blank Word document, so this workflow does not depend on a local template .docx file.
Reference: skills/word-expert-formatting/scripts/text_to_docx.py:3151
Run:
python3 skills/word-expert-formatting/scripts/text_to_docx.py <input-file> [output.docx] [--reserve-cover] [--auto-toc] [--with-cover|--without-cover] [--cover-text <text>] [--with-toc|--without-toc] [--style-config <path>]If output.docx is omitted, .md / .markdown / .txt inputs still write a same-basename .docx, while .docx inputs write <stem>.refreshed.docx next to the source file.
For skill-driven runs in this repository, ask first:
- whether to generate a cover page
- if yes, what cover text to use (manual input; default empty)
- whether to generate a TOC page
The skill treats those answers as explicit per-run decisions:
- generate cover + non-empty text: render the first non-empty line as the cover title and later non-empty lines as centered metadata
- generate cover + empty text: render a blank placeholder cover page
- do not generate cover: suppress automatic cover detection and placeholder insertion for that run; for an existing
.docx, this also means the existing cover region is fully frozen and no cover-region formatting, section, footer, or page-number changes are allowed - TOC generation is asked every time and then mapped to the script invocation for that run; when the existing cover region is frozen, TOC handling must stay after the detected body boundary
References:
skills/word-expert-formatting/SKILL.md:127skills/word-expert-formatting/scripts/text_to_docx.py:2634
The script currently:
- accepts
.md,.markdown,.txt, and.docx - formats headings, paragraphs, lists, tables, code blocks, footer page numbers, and simple cover sections
- renders Markdown inline emphasis (bold / italic / inline code / strikethrough), hyperlinks, task lists, blockquotes, and footnotes
- embeds local
images with page-fit sizing and rendersmermaidfenced blocks to images (local mmdc, then draw.io CLI, then mermaid.ink, finally falls back to a code block) - strips emoji from rendered text automatically while keeping code blocks and inline code verbatim
- uses all-decimal heading numbering
- can reserve a placeholder cover page when no cover is detected
- can generate a Word TOC field page when no explicit TOC heading is detected
- can take explicit cover / TOC decisions for a run, including manual cover text input
- loads per-level typography (font, size, color, bold, spacing, alignment) from an optional JSON config file instead of using the built-in defaults
- refreshes existing
.docxfiles into a new output file instead of deleting and rebuilding the body - preserves images, tables, page breaks, and section structure during existing
.docxrefresh - fully freezes the existing cover region when
--without-coveris chosen for an existing.docx, and only normalizes content after the detected body boundary - still allows explicit TOC decisions during existing
.docxrefresh without letting TOC handling modify the frozen cover region - uses a more formal pagination model when a cover page exists for generated output or for existing
.docxruns that are not in frozen-cover mode: the cover has no page number and the body section restarts numbering from 1 - writes a
.docxfile
Reference: skills/word-expert-formatting/scripts/text_to_docx.py:840
Font, size, color, bold, line spacing, spacing before/after, first-line indent, and alignment for each of the 20 style entries (title, headings 1–9, cover title/meta/corner, body, blockquote, table, code, footer, TOC title/entry) can be overridden without touching Python code.
By default the script looks for skills/word-expert-formatting/config/style.json next to itself; if that file is absent, the built-in hardcoded defaults apply unchanged. Pass --style-config <path> to use a different file, or to require one explicitly (an explicit path that doesn't exist is an error). A config file only needs to specify the fields it wants to change — everything else is deep-merged onto the defaults:
{"styles": {"h1": {"color": "1F4E79", "size_pt": 20}}}The shipped config/style.json mirrors the current hardcoded values exactly, and skills/word-expert-formatting/SKILL.md's "Style matrix" table is generated from it — run python3 skills/word-expert-formatting/scripts/generate_style_doc.py after editing the config to refresh that table (--check verifies it's already in sync).
Page geometry, bullet marker characters, non-typography colors, and heading-numbering/cover-detection logic are not part of this config and stay hardcoded in text_to_docx.py; the cover_title/cover_meta/cover_corner/toc_title entries also ignore the alignment field since their alignment is set explicitly in code.
References:
skills/word-expert-formatting/config/style.jsonskills/word-expert-formatting/scripts/text_to_docx.py:3691
Location:
skills/word-expert-formatting/SKILL.mdskills/word-expert-formatting/scripts/text_to_docx.py
Purpose:
- turn raw Markdown, TXT, HTML, or rough outlines into a Word-ready structured format
- apply a strict Chinese formal-document style model
- apply all-decimal heading numbering
- support local
.docxgeneration when the input is.md,.markdown, or.txt - support refreshed-copy normalization and verification when the input is an existing
.docx
Reference: skills/word-expert-formatting/SKILL.md:1
skills/word-expert-formatting/SKILL.md defines:
- supported input shapes
- heading hierarchy rules
- heading numbering behavior
- cover detection rules
- style mapping for headings, body text, tables, and footer page numbers
- output contracts for structured formatting results
- body paragraphs are normalized by clearing inherited indent, line spacing, and alignment before applying justified alignment and a 2-character first-line indent
- existing
.docxrefresh preserves images, tables, page breaks, and section structure instead of deleting and rebuilding the body - existing
.docxverification checks both paragraph layout and structure preservation
Reference: skills/word-expert-formatting/SKILL.md:27
Current script support includes:
- Markdown headings (
#to######) - paragraphs
- unordered lists
- ordered lists
- Markdown tables
- fenced code blocks
- simple cover recognition
- multi-line cover title blocks for existing
.docxcover refresh - for existing
.docxcover titles, refresh only corrects font and size; it does not change existing title alignment - placeholder cover insertion with
--reserve-cover - explicit cover generation with
--with-coverand--cover-text - explicit cover suppression with
--without-coverfor generated output, while existing.docxrefresh keeps any cover that is already present unchanged - explicit TOC detection (
目录,TOC,Table of Contents) - Word TOC field insertion with
--auto-toc - explicit TOC generation with
--with-toc - explicit TOC suppression with
--without-tocfor generated output, while existing.docxrefresh keeps any TOC that is already present - all-decimal heading numbering
- formal pagination when a cover exists: no page number on the cover, body numbering restarts from 1
- refreshed-copy normalization for existing
.docxwith structure preservation - existing
.docxverification for cover, TOC, body layout, tables, numbering, and structure counts - TXT paragraph blocks
- minimal TXT heading detection for TOC generation
- per-level typography overrides via
--style-config <path>or a defaultconfig/style.json, deep-merged onto built-in defaults
References:
skills/word-expert-formatting/scripts/text_to_docx.py:695skills/word-expert-formatting/scripts/text_to_docx.py:822
For tricky existing .docx cases where Word rendering does not match the normal refresh result, this skill also includes a local XML debug helper:
python3 skills/word-expert-formatting/scripts/debug_docx_xml.py unpack <input.docx> <output-dir>
python3 skills/word-expert-formatting/scripts/debug_docx_xml.py validate <output-dir> --original <input.docx>
python3 skills/word-expert-formatting/scripts/debug_docx_xml.py repack <output-dir> <output.docx> --original <input.docx>This path is intended for XML-level debugging and repair, not for normal generation.
| Dimension | Generic DOCX skill | word-expert-formatting |
|---|---|---|
| Positioning | Low-level Office/XML toolbox | End-to-end document-production workflow |
| Main job | Unpack, inspect, validate, repack .docx |
Generate or refresh documents to this repository's formatting contract |
| Best at | XML surgery, schema issues, relationships, tracked changes | Cover, TOC, heading hierarchy, pagination, body and table formatting |
Existing .docx handling |
Good for direct XML repair | Good for refreshed-copy normalization with structure preservation |
| Validation focus | XML correctness | Semantic output quality + structure preservation |
| User cost | Higher; better for expert debugging | Lower; better for repeatable daily use |
| Use when | Word rendering and XML disagree, or XML needs surgical fixes | Normal formatting, refresh, and verification work |
In short:
- the generic DOCX skill is the XML surgery toolkit
word-expert-formattingis the repeatable production line for this repository's target document format- the intended workflow is: use
word-expert-formattingby default, and fall back to the XML debug lane only for hard low-level cases
The skill contract and current Python script use a single heading numbering scheme:
- headings use an all-decimal hierarchy such as
1,1.1, and1.1.1 - this is intended for technical documents, project plans, implementation plans, and similar structured reports
Also, --auto-toc now inserts a real Word TOC field instead of static text entries. If the table of contents does not appear updated immediately in Word, use Word's update-table action after opening the document.
The newer explicit switches are intended for skill-driven runs:
--with-cover/--without-coveroverride automatic cover detection for that run; on existing.docx,--without-coveronly suppresses creating a new cover and does not remove or restyle one that already exists--cover-textimplies--with-coverwhen used alone--with-toc/--without-tocoverride fallback TOC generation for that run; on existing.docx,--without-toconly suppresses creating a new TOC and does not remove one that already exists--reserve-coverand--auto-tocremain available for direct CLI compatibility
When a cover page is present or --reserve-cover / --with-cover is used, the script now creates a separate body section so the cover stays unnumbered and the body starts again at page 1.
References:
skills/word-expert-formatting/SKILL.md:43skills/word-expert-formatting/scripts/text_to_docx.py:3455skills/word-expert-formatting/scripts/text_to_docx.py:309
- complex embedded HTML, remote images (rendered as placeholders), and highly customized layouts are not supported yet
mermaidfenced blocks need at least one working renderer (localmmdc, the draw.io CLI, or network access tomermaid.ink); if none are available, the block falls back to a plain code block instead of an imageSKILL.mdis a human-readable contract, not a config file the script parses — a formatting-rule change must be made in bothSKILL.mdandtext_to_docx.pyto actually affect output
Reference: skills/word-expert-formatting/SKILL.md:327
If a formatting rule change must affect generated .docx output, update both:
skills/word-expert-formatting/SKILL.mdskills/word-expert-formatting/scripts/text_to_docx.py
Reference: skills/word-expert-formatting/SKILL.md:165