ninestep/docx-format-skill
Overview
This skill provides precise .docx formatting, analysis, and batch modification using python-docx. It targets document format inspection, unified typography, handling mixed Chinese/English fonts, table-contained content, and adjusting cross-reference or reference list styles. Scripts are generated and executed with a reproducible workflow to avoid dependency issues.
How this skill works
I ask for the input and output file paths and whether you want analysis or modification. Based on your goal I pick or generate a Python script template that processes doc.paragraphs and doc.tables, sets Chinese fonts via qn('w:eastAsia'), and applies the requested formatting rules. The generated script is intended to run with the recommended runner: uv run --with python-docx python3 script.py, then I validate the results and advise any fixes.
When to use it
- Analyze fonts, sizes, indentation and line spacing across a .docx
- Batch-normalize typography for reports, theses, or official documents
- Fix mixed Chinese/English font issues using qn('w:eastAsia')
- Process documents whose main text is inside tables
- Adjust reference list or cross-reference formatting consistently
- Convert Markdown to styled .docx and apply a target layout
Best practices
- Always provide full input and output paths and keep a backup of the original file
- Ensure the script processes both doc.paragraphs and all doc.tables to avoid missed content
- Use qn('w:eastAsia') to set Chinese fonts separately from Latin fonts
- Run scripts with: uv run --with python-docx python3 script.py to include dependencies
- Test on a small sample document before bulk processing
Example use cases
- Standardize body text to Times New Roman + 宋体, 10.5pt, first-line indent 21pt across 100 reports
- Detect and report inconsistent font sizes and paragraph spacing for an academic manuscript
- Convert input.md into a styled output.docx with numbered headings and justified paragraphs
- Reformat a thesis reference section to hanging indent and color-coded citation markers
- Batch-fix documents where Chinese text was rendered with a fallback font
FAQ
No. This skill only works with .docx files.
How do you handle Chinese fonts?
I set Latin font via run.font.name and Chinese font via run._element.rPr.rFonts.set(qn('w:eastAsia'), 'FontName').