Install
$ agentstack add skill-neu-zha-legal-ai-skills-legal-homework-formatter ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
Legal Homework Formatter
Purpose
This skill provides standardized formatting workflows for Chinese legal homework assignments. It helps documents follow a user-provided course template and the Law Journal Citation Handbook, while resolving common compatibility issues between WPS and Microsoft Word.
When to Use
Use this skill when:
- Creating new Chinese legal homework assignments in Word format
- Formatting existing homework to meet citation standards
- Fixing footnote display issues between WPS and Word
- Adjusting title, heading, or citation formats
- Generating or repairing a homework table of contents (目录/TOC)
- Converting draft content to properly formatted legal documents
Privacy and Required Inputs
This public version must never default to the maintainer's personal information or a private course template.
Before generating a title, filename, header, or metadata, ask the user for:
- assignment date prefix;
- assignment number/title;
- student name;
- student ID, if required;
- course or instructor-specific template, if required.
If the user does not provide a required identity field, use an explicit placeholder such as [待补: 姓名] or [待补: 学号] and flag it in the final checklist. Do not infer, reuse, or hard-code a real person's name, ID, school, email address, or local file path.
Reference Template
Use the user-provided course reference template as the base for generating homework documents when one is available. Its style system is the authoritative source for course-specific formatting. If no template is provided, create a conservative .docx with the formatting rules below and clearly tell the user which template-dependent checks could not be performed.
This public skill also includes an anonymized fallback template at:
assets/legal-homework-template-anonymized.docx
Use it when the user needs a working Word style base but has not provided a private course template. The template keeps the formatting structure while replacing identity fields with [日期], [序号], [姓名], and [学号]. Do not rename it to a private course filename when publishing or redistributing the skill.
For a user-facing material checklist and missing-information workflow, read:
references/user_materials_guide.md
Lessons From the 2026-05-13 Homework Formatting Pass
When the user asks to "strictly follow the homework skill" or provides the course reference template/PPT, apply these verified rules rather than relying on generic python-docx defaults:
- Use the user-provided reference template as the ZIP/DOCX base when available, not a blank document.
- Match the course PPT's "三名同一" rule: email subject, attachment file name, and document title should be identical.
- Main title: 小三, centered, no first-line indent,
spacing after="156", split the title into runs so Chinese name and hyphens render in 宋体 while English/date/student ID render in Times New Roman. - Body paragraphs: 五号, 宋体/Times New Roman, first-line indent
420twips, line spacing300(1.25x), paragraph after156twips, justified alignment. - Paragraph-after unit check:
w:after="156"is stored in OOXML twips, equal to 7.8 pt because Word uses twentieths of a point. In the civil-law reference template this corresponds to half of the document grid line pitch (docGrid linePitch="312"), so Word/WPS may display the same setting as about0.5 行or7.8 磅depending on UI/context. Treat these as equivalent, not conflicting. - Footnotes: 小五, 宋体/Times New Roman, single line spacing, left aligned, no first-line indent, no paragraph spacing before/after.
- Footnote numbering: remove `
fromword/settings.xmland any section-levelfootnotePr; homework footnotes should number continuously across the whole document. The reference template containseachPage`, but that setting causes duplicate-looking footnote numbers page by page. - If using manual Chinese heading numbers such as
一、and二、, remove `from heading styles1,2, and3`; otherwise Word may visually render duplicate numbering. - If the document was generated from Markdown/Pandoc or any converter that applies Word
Heading1/Heading2styles, do not only override run fonts and sizes. Also remove inherited heading paragraph styles and decorations from the final document, or Word may still render blue/green heading colors and automatic bullets/numbering: - remove `
,`, and similar converted heading styles from manually numbered titles/headings; - remove paragraph-level `` from all title/heading paragraphs;
- clear run-level `
values inherited from styles/themes, especiallyw:themeColor, then set direct black color`; - remove `
and` on generated title/heading runs unless the user explicitly asks for color. - run
python3 scripts/fix_pandoc_heading_artifacts.py input.docx --output output.docxbefore the final compatibility check when the source DOCX came from Pandoc/Markdown.
This bug appeared in a 2026-05-27 Word check: Pandoc's heading style survived OOXML post-processing, so Word displayed the main title and headings in blue-green and with black bullet markers even though font/size had been overwritten.
- After running any quote normalizer, re-check footnotes: standalone curly quote runs in footnotes may accidentally inherit body size. Force footnote quote runs (
“”‘’) back to 小五 (w:sz=18) and 宋体. - Do not save a finished footnoted document with
python-docxafter manually editing footnotes unless you have verifiedword/footnotes.xmlandfootnoteReferencemarkers are preserved. Prefer ZIP/XML surgery for final footnote and quote fixes. - Before writing footnote text into DOCX, strip leading/trailing whitespace from the citation payload. The template may use one normal delimiter space after the footnote number, but the citation text itself must not start with an extra blank.
- Do not place two footnote references back-to-back after the same sentence-final punctuation. If multiple sources support the same claim, combine them in one footnote separated by
;; if they support different clauses, place each marker after its own clause or legal article. - The homework template may include Chinese TOC styles. To add a directory, use the template's TOC styles and a clean Word field, but do not copy dirty old preview entries such as
PAGEREF _Toc.... - For Word compatibility, do not set `
just to force TOC updates. Word will show a field-update prompt. Also avoid copying a template's wholew:sdt` TOC content-control shell into generated files unless you have verified Word opens without repair prompts. Prefer clean ordinary TOC field paragraphs plus static preview entries. - Preserve WordprocessingML child order in generated paragraph properties. Word may show "unreadable content" even when ZIP/XML parsing succeeds if, for example,
w:spacingappears beforew:tabsin a TOC entry orw:pageBreakBeforeis inserted beforew:pStyle. - Homework TOC layout: the document title and
目录stay on the first page; the main body starts on the next page by settingw:pageBreakBeforeon the first body paragraph, not by inserting a visible ``. - Heading detection for TOC must use both style and text structure. Existing styles
1/2/3are strong clues but not always trustworthy because users often hand-format titles. Confirm with text patterns like一、,(一), and1.before including a paragraph in the TOC.
Style System (OOXML Reference)
Based on the reference template's styles.xml:
Paragraph Styles
| styleId | Name | sz (半磅) | 对应中文 | Bold | Other | |---------|------|----------|---------|------|-------| | a | Normal | 21 (五号/10.5pt) | 正文 | No | line=300 (1.25倍), after=50, firstLine=200, widowControl=0, adjustRightInd=0, snapToGrid=0 | | 1 | heading 1 | 28 (四号/14pt) | 一级标题 | Yes | keepNext, keepLines, numPr (auto "一、") | | 2 | heading 2 | 24 (小四号/12pt) | 二级标题 | Yes | keepNext, keepLines, numPr (auto "(一)") | | 3 | heading 3 | 21 (五号) | 三级标题 | Yes | keepNext, keepLines | | a7 | footnote text | 18 (小五号/9pt) | 脚注文本 | No | line=240 (单倍), left aligned | | TOC10 | TOC 标题1 | 28 (四号/14pt) | 目录标题 | No | centered, black | | TOC1 | toc 1 | 21/22-ish | 一级目录项 | No | right tab with dot leader when generated | | TOC2 | toc 2 | 21/22-ish | 二级目录项 | No | indented TOC item | | TOC3 | toc 3 | 21/22-ish | 三级目录项 | No | further indented TOC item |
Character Styles
| styleId | Name | Purpose | |---------|------|---------| | ab | footnote reference | Superscript footnote markers (上标) |
docDefaults
sz=21(五号/10.5pt),szCs=22(default paragraph-level rPr)- Default fonts in docDefaults:
ascii="Times New Roman" eastAsia="宋体" hAnsi="Times New Roman" cs="Times New Roman" - These are explicit font names, NOT theme font references (minorHAnsi/minorEastAsia)
Document Generation Workflow
Step 1: Gather Required Materials
- Homework questions (PDF/DOCX) - assignment requirements
- Reference template - user-provided formatting base, if required by the course
- Student information - ask the user for name (姓名), student ID (学号), and date prefix; use
[待补: ...]placeholders if missing
Step 2: Build Document Using Reference Template
Use the reference template as the ZIP base. Key principles:
Heading paragraphs (一级标题 like "一、XXX"):
一、菜单案
- Use pStyle="1" for 一级标题, pStyle="2" for 二级标题
- Run does NOT need rPr — style provides sz=28/24 and bold
- IMPORTANT: Remove numPr from styles 1, 2, 3 in styles.xml if using manual heading numbers (not auto-numbering)
Body paragraphs (正文):
正文内容...
- NO pStyle (inherits Normal/a: sz=21, line=300)
- Run rPr: only `` — NO explicit sz
- Bold body runs: add `` to rPr
- First-line indent: 420 twips (≈2 chars)
- Paragraph after: use 156 twips for generated homework body paragraphs. Although Normal style may show
after=50, the course reference template's actual filled body paragraphs useafter=156, and this is the safer value for submitted homework. - Alignment: set `` explicitly to avoid Word/WPS drift.
Document title (split into multiple runs, hyphen in 宋体 font):
0421 graded homework 4
-
[待补: 姓名]
-
[待补: 学号]
- NO pStyle, centered, sz=30 (小三号/15pt), bold
- Date prefix: follow the user's course requirement. If the course uses month+day, use e.g. "0421", not year+month+day.
- Date prefix may be the assignment release date, due date, or another course-specific value; ask the user instead of guessing.
- IMPORTANT: Hyphen "-" must be in its own run with explicit 宋体 font (ascii/hAnsi/cs all set to "宋体")
- IMPORTANT: pPr must include `
and` block - Title is split into 5 runs: date+text, hyphen, name, hyphen, student ID
Footnote references (in body text):
- Use character style rStyle="ab" (superscript, 9pt)
- Each footnoteReference must have a UNIQUE ID
- The course reference template uses separator IDs
-1and0; its sample regular footnote uses ID1. - Starting newly generated footnotes at
4is a conservative compatibility strategy for programmatic generation/repair, not a template requirement. It avoids collisions with legacy or AI-generated documents that misuse low IDs for separators or ordinary notes. - If preserving an existing clean template footnote, do not renumber it merely because it is ID
1; only ensure everyfootnoteReferencehas a matchingfootnotedefinition.
Footnote definitions (in footnotes.xml):
《民法典》第X条。
- Paragraph style: pStyle="a7" (sz=18/小五号, line=240/单倍)
- footnoteRef: rStyle="ab" (superscript)
- Text runs: only ``, sz=18 from a7 style
- Separator: w:id="-1" (separator), w:id="0" (continuationSeparator)
- If footnote text contains Chinese quotation marks, ensure the quote runs are also 小五: `
plus`. - Nested Chinese quotation marks should be outer double and inner single, e.g.
“违反‘打黑工’禁令的合同”.
Step 3: Heading Hierarchy
- 文档主标题(居中): follow the user-provided title pattern, e.g.
[date] graded homework [N]-[Name]-[ID]; use placeholders for missing identity fields - 一级标题(左对齐):
一、XXX,二、XXX, 四号, pStyle="1" - 二级标题(左对齐):
(一)XXX,(二)XXX, 小四号, pStyle="2" - 三级标题及以下: 五号, pStyle="3"
Step 4: Homework Table of Contents (目录)
Use this step when the user asks for 目录, TOC, "做目录", or when the assignment/template clearly expects a directory.
Core strategy
- Use the homework template's
TOC10,TOC1,TOC2, andTOC3styles when they are available. - Insert a clean ordinary Word TOC complex field:
TOC \o "1-3" \h \z \u. - Generate static preview TOC entries from detected headings; Word/WPS can later update page numbers.
- Keep the TOC field clean, but generate static preview entries with
TOC1/TOC2/TOC3style plus a paragraph-level right-aligned dot-leader tab stop atw:pos="8296". Some templates haveTOC2/TOC3indentation but no dot-leader tab, which makes preview page numbers appear beside the heading until Word updates the field. - Preserve untouched DOCX parts byte-for-byte when possible. If the document already has required TOC/heading styles and no
updateFields, avoid rewriting unrelated parts. - Do not copy old
PAGEREF _Toc...preview entries from a template; they may refer to missing bookmarks and produce Word errors. - Do not set
w:updateFields=trueinword/settings.xml; it causes Word to ask whether to update fields. - Do not copy a whole
w:sdtcontent-control TOC wrapper unless you have verified Word opens without repair prompts. A plain TOC field is safer.
TOC page layout
- Keep the document title and
目录on the first page. - Start the body on the next page by adding `` to the first body paragraph.
- Avoid inserting a visible page-break run (``) after the TOC because Quick Look/Word may display a stray square or layout artifact.
Heading detection and repair
- TOC levels map to common template styles:
一、...,二、...-> heading style1->TOC1(一)...,(二)...-> heading style2->TOC2- independent
1. ...,2. ...-> heading style3->TOC3 - Do not blindly trust existing Word styles. Users often hand-format headings, and converted documents may misuse styles.
- Use a double check:
- If style
1/2/3and text numbering agree, include it directly. - If style is missing but the paragraph is clearly a heading, add the correct heading style before generating TOC.
- If a paragraph has heading style but text does not look like a heading, do not include it; consider downgrading it to body style.
- If uncertain, leave it out and report it as "需人工确认标题".
- Only include levels 1-3 by default. Do not include fourth-level or lower material; homework TOCs get too dense quickly.
Validation
- Verify exactly one
TOC \o "1-3" \h \z \ufield exists when a TOC is requested. - Verify
PAGEREF,_Toc...anchors, and missing bookmarks are not present in the generated preview entries. - Verify generated
w:pPrchild order, especiallyw:pStylebeforew:pageBreakBefore, andw:tabsbeforew:spacing. - Verify
mc:Ignorableprefixes are declared andw:rPrchild order is valid. Runningdocx_compat_check.pyis useful; a repaired Word sample should not have undefined-prefix orrFontsordering errors. - Verify body
footnoteReferenceIDs and footnote text payload are unchanged unless the task also asked for footnote work. Byte-for-byteword/footnotes.xmlequality may change if namespace prefixes are normalized to satisfy Word. - Open in Word as well as WPS when possible. If Word reports "unreadable content", first check
mc:Ignorableundefined prefixes,w:rProrder, andw:pPrchild order, then rebuild the TOC as clean plain field paragraphs and removeupdateFields.
For a deterministic helper, use:
…
## Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- **Author:** [NEU-ZHA](https://github.com/NEU-ZHA)
- **Source:** [NEU-ZHA/legal-ai-skills](https://github.com/NEU-ZHA/legal-ai-skills)
- **License:** MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.