gostyan/docx-skill-4-cn-paper/docx-editor-cn

Claude Code and agent skill by gostyan/docx-skill-4-cn-paper

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files). Triggers include: any mention of \"Word doc\", \"word document\", \".docx\", or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a \"report\", \"memo\", \"letter\", \"template\", or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.

Install

npx vskill@latest install gostyan/docx-skill-4-cn-paper/docx-editor-cn

SKILL.md

DOCX creation, editing, and analysis

Overview

A .docx file is a ZIP archive containing XML files.

Quick Reference

TaskApproach
Read/analyze contentpandoc or unpack for raw XML
Create new documentnode scripts/new_doc.js (edit CONTENT section first)
Edit existing documentUnpack → edit XML → repack - see Editing Existing Documents below
Insert 三线表 (XML editing)python scripts/table.py unpacked/ "1-1" "标题" --headers … --rows …
Insert block formula (XML editing)python scripts/formula.py unpacked/ "LaTeX" 1 --anchor "锚文本"
Converting .doc to .docx

Legacy .doc files must be converted before editing:

bash
python scripts/office/soffice.py --headless --convert-to docx document.doc
Reading Content
bash
# Text extraction with tracked changes
pandoc --track-changes=all document.docx -o output.md
# Raw XML access
python scripts/office/unpack.py document.docx unpacked/
Converting to Images
bash
python scripts/office/soffice.py --headless --convert-to pdf document.docx
pdftoppm -jpeg -r 150 document.pdf page
Accepting Tracked Changes

To produce a clean document with all tracked changes accepted (requires LibreOffice):

bash
python scripts/accept_changes.py input.docx output.docx

Creating New Documents

Generate .docx files with JavaScript, then validate. Install: npm install -g docx

Setup
javascript
const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, ImageRun,
Header, Footer, AlignmentType, PageOrientation, LevelFormat, ExternalHyperlink,
TableOfContents, HeadingLevel, BorderStyle, WidthType, ShadingType,
VerticalAlign, PageNumber, PageBreak } = require('docx');
const doc = new Document({ sections: [{ children: [/* content */] }] });
Packer.toBuffer(doc).then(buffer => fs.writeFileSync("doc.docx", buffer));
Validation

After creating the file, validate it. If validation fails, unpack, fix the XML, and repack.

bash
python scripts/office/validate.py doc.docx
Page Size
javascript
// Chinese academic papers use A4 with 2.5cm margins on all sides
sections: [{
properties: {
page: {
size: {
width: 11906, // A4 width in DXA
height: 16838 // A4 height in DXA
},
margin: { top: 1418, right: 1418, bottom: 1418, left: 1418 } // 2.5cm = 1418 DXA
}
},
children: [/* content */]
}]

Common page sizes (DXA units, 1440 DXA = 1 inch, 567 DXA = 1 cm):

PaperWidthHeightContent Width (2.5cm margins)
A4 (Chinese standard)11,90616,8389,070
US Letter12,24015,8409,404

Landscape orientation: docx-js swaps width/height internally, so pass portrait dimensions and let it handle the swap:

javascript
size: {
width: 12240, // Pass SHORT edge as width
height: 15840, // Pass LONG edge as height
orientation: PageOrientation.LANDSCAPE // docx-js swaps them in the XML
},
// Content width = 15840 - left margin - right margin (uses the long edge)
Styles (Academic Thesis Formatting)

CRITICAL: When generating academic papers, course designs, or mathematical documents, strictly adhere to the following Chinese academic formatting standards.

1. Global Page & Normal Text (【全局页面与正文规范】)

  • Page: A4 (11906 × 16838 DXA), margins all 2.5cm (1418 DXA).
  • Fonts: Chinese = SimSun (宋体), English/Math/Code = Cambria Math (default); Times New Roman is an acceptable alternative for English text.
  • Size: 12pt (小四) -> size: 24 in docx-js (half-points).
  • Paragraph: First-line indent 2 characters (firstLine: 480 DXA), Line spacing single (line: 240, lineRule: LineRuleType.AUTO) by default; alternatives: fixed 20pt (line: 400, lineRule: LineRuleType.EXACT) or 1.5x (line: 360, lineRule: LineRuleType.AUTO). Before/After spacing 0pt.

2. Headings (【标题规范】)

  • Heading 1 (一级标题): SimHei (黑体), 16pt (三号, size: 32), Bold, Centered, 1.2x line spacing (line: 288). Auto-numbering: Arabic 1, 2, 3 (displayed in heading text or prefixed manually as 一、二、). See Heading & Reference Auto-Numbering below.
  • Heading 2 (二级标题): SimHei (黑体), 14pt (四号, size: 28), Bold, Left-aligned, 1.5x line spacing (line: 360). Auto-numbering: 1.1, 1.2, 2.1 (chapter-tracking Arabic decimal).
  • Heading 3 (三级标题): SimHei (黑体), 12pt (小四, size: 24), Bold, Left-aligned, 1.1x line spacing (line: 264). Auto-numbering: 1.1.1, 2.4.1.

⚠️ Heading Numbering Rule: Use a single all-decimal multi-level numbering config for all three heading levels. This is the ONLY way to get correct cross-chapter tracking (1.1, 2.1, 2.4 etc.) while keeping H2/H3 numbers purely Arabic. If CHINESE_COUNTING is used for H1 level, H2 will render as 二.4 instead of 2.4 — this is a known OOXML rendering issue.

3. Figures, Tables & Math (【图表与公式规范】)

  • Figure Captions (图标题): SimSun (宋体), 11pt (size: 22), Centered, Bold. Spacing: Single spacing, 0.5 lines before (before: 120), 3pt after (after: 60). Position: Below the figure. Format: "图 章-图序" e.g. "图 1-1".
  • Table Captions (表标题): SimSun (宋体), 11pt (size: 22), Centered, no indent, Bold. Spacing: Single spacing, 0.5 lines before (before: 120), 3pt after (after: 60). Position: Above the table. Format: "表 章-表序" e.g. "表 1-1". Tables MUST use 三线表 (three-line table) style (thick top/bottom, thin after header, no other borders).
  • Block Math Formulas: Use the formula table layout — a 3-column borderless table: [1cm spacer | formula centered | equation number right-aligned 1cm]. Use scripts/formula.py to generate the XML. Inline math: write as plain text with italic formatting.

Creating a new document — use the template script:

bash
# Copy the template, edit the CONTENT section, then run:
node scripts/new_doc.js
# Outputs output.docx with all styles, numbering, and page setup pre-configured.
# Change OUTPUT_PATH inside the script if needed.

scripts/new_doc.js provides ready-to-use helper functions: h1/h2/h3(text), body(text), tableCaption/figCaption(label), threeLineTable(headers, rows, colWidths), ref(text), blank(). The STYLES / NUMBERING / page constants at the top of the file are the canonical implementation of all specs below; refer to that file for exact docx-js values.

Lists (NEVER use unicode bullets)
javascript
// ❌ WRONG - never manually insert bullet characters
new Paragraph({ children: [new TextRun("• Item")] }) // BAD
new Paragraph({ children: [new TextRun("\u2022 Item")] }) // BAD
// ✅ CORRECT - use numbering config with LevelFormat.BULLET
const doc = new Document({
numbering: {
config: [
{ reference: "bullets",
levels: [{ level: 0, format: LevelFormat.BULLET, text: "•", alignment: AlignmentType.LEFT,
style: { paragraph: { indent: { left: 720, hanging: 360 } } } }] },
{ reference: "numbers",
levels: [{ level: 0, format: LevelFormat.DECIMAL, text: "%1.", alignment: AlignmentType.LEFT,
style: { paragraph: { indent: { left: 720, hanging: 360 } } } }] },
]
},
sections: [{
children: [
new Paragraph({ numbering: { reference: "bullets", level: 0 },
children: [new TextRun("Bullet item")] }),
new Paragraph({ numbering: { reference: "numbers", level: 0 },
children: [new TextRun("Numbered item")] }),
]
}]
});
// ⚠️ Each reference creates INDEPENDENT numbering
// Same reference = continues (1,2,3 then 4,5,6)
// Different reference = restarts (1,2,3 then 1,2,3)
Tables (三线表 / Three-Line Table)

Chinese academic papers MUST use 三线表: thick top/bottom (1.5pt), thin after header (0.75pt), no other borders. Caption goes above the table.

For new documents — use `threeLineTable()` helper in `scripts/new_doc.js`:

javascript
// Inside the CONTENT array:
tableCaption('符号说明'),
threeLineTable(
['符号', '说明'], // headers
[['S', '状态空间'], ['A', '动作空间']], // data rows
[1800, 7270] // DXA column widths; must sum to 9070
),

For editing existing documents (XML) — use `scripts/table.py`:

bash
# Insert after paragraph containing anchor text:
python scripts/table.py unpacked/ "1-1" "符号说明" \\
--headers "符号,说明" \\
--rows '[["S","状态空间"],["A","动作空间"]]' \\
--anchor "以下是符号说明"
# Custom column widths (must sum to 9070):
python scripts/table.py unpacked/ "2-1" "参数" \\
--headers "参数,取值,说明" \\
--rows '[["lr","0.001","学习率"]]' \\
--widths "1800,1500,5770"
# Print XML snippet only (no file modification):
python scripts/table.py --caption "示例" \\
--headers "列1,列2" --rows '[["a","b"]]'

Key rules:

  • Content width = 9070 DXA (A4 2.5cm margins); columnWidths must sum exactly to 9070
  • Always use WidthType.DXA — never WidthType.PERCENTAGE
  • Table width = sum of columnWidths; set matching width on each cell too
Images
javascript
// CRITICAL: type parameter is REQUIRED
new Paragraph({
children: [new ImageRun({
type: "png", // Required: png, jpg, jpeg, gif, bmp, svg
data: fs.readFileSync("image.png"),
transformation: { width: 200, height: 150 },
altText: { title: "Title", description: "Desc", name: "Name" } // All three required
})]
})
Page Breaks
javascript
// CRITICAL: PageBreak must be inside a Paragraph
new Paragraph({ children: [new PageBreak()] })
// Or use pageBreakBefore
new Paragraph({ pageBreakBefore: true, children: [new TextRun("New page")] })
Table of Contents
javascript
// The overridden Heading1/2/3 styles (defined in paragraphStyles above) include outlineLevel,
// which TableOfContents uses to build the TOC. Using heading: HeadingLevel.HEADING_X on
// each paragraph applies that overridden style automatically — giving both TOC support AND
// the custom SimHei/size formatting. Do NOT skip paragraphStyles and rely on built-in styles.
new TableOfContents("目录", { hyperlink: true, headingStyleRange: "1-3" })
// Apply to heading paragraphs — heading property applies the overridden style:
new Paragraph({
heading: HeadingLevel.HEADING_1, // → w:pStyle "Heading1" (SimHei 16pt, outlineLevel:0)
children: [new TextRun("一、引言")]
})
new Paragraph({
heading: HeadingLevel.HEADING_2, // → w:pStyle "Heading2" (SimHei 14pt, outlineLevel:1)
children: [new TextRun("1.1 研究背景")]
})
Headers/Footers
javascript
sections: [{
properties: {
page: { margin: { top: 1418, right: 1418, bottom: 1418, left: 1418 } } // 2.5cm = 1418 DXA
},
headers: {
default: new Header({ children: [new Paragraph({ children: [new TextRun("Header")] })] })
},
footers: {
default: new Footer({ children: [new Paragraph({
children: [new TextRun("Page "), new TextRun({ children: [PageNumber.CURRENT] })]
})] })
},
children: [/* content */]
}]
Heading Auto-Numbering (Word per-chapter reset)

H1 uses Chinese numerals written literally in text (一、二、三). H2/H3 use Word auto-numbering via per-chapter numbering references (sections_c1, sections_c2, ...). Each chapter boundary resets H2/H3 counters automatically — adding/removing sections within a chapter triggers full auto-update.

CRITICAL — numbering format rule:

NEVER use LevelFormat.CHINESE_COUNTING for H1 in a multi-level config — %1 in H2 text expands to "二", giving 二.4. Always use LevelFormat.DECIMAL for every level.

Numbering references are generated dynamically by buildNumberingConfig(chapterCount). Each chapter gets its own sections_c{N} reference with 2 levels (H2, H3). This ensures H2/H3 reset per chapter while Word handles all numbering.

javascript
// H1 — Chinese numerals in text (no Word numbering)
h1Chinese('一、引言') // → "一、引言" (Heading1 style)

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
276
Repository forks
8
7-day trend score
28

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/gostyan/docx-skill-4-cn-paper/docx-editor-cn/badge)](https://verified-skill.com/skills/gostyan/docx-skill-4-cn-paper/docx-editor-cn)

Something wrong with this skill or its page? Tell us.