@nguyenphp/antigravity-marketing 1.0.18 → 1.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/README.md +186 -78
  2. package/package.json +4 -3
  3. package/templates/.agent/skills/marketing-report-expert/SKILL.md +70 -0
  4. package/templates/.agent/skills/minimax-docx/LICENSE +21 -0
  5. package/templates/.agent/skills/minimax-docx/SKILL.md +274 -0
  6. package/templates/.agent/skills/minimax-docx/assets/styles/academic_styles.xml +250 -0
  7. package/templates/.agent/skills/minimax-docx/assets/styles/corporate_styles.xml +284 -0
  8. package/templates/.agent/skills/minimax-docx/assets/styles/default_styles.xml +449 -0
  9. package/templates/.agent/skills/minimax-docx/assets/xsd/aesthetic-rules.xsd +470 -0
  10. package/templates/.agent/skills/minimax-docx/assets/xsd/business-rules.xsd +130 -0
  11. package/templates/.agent/skills/minimax-docx/assets/xsd/common-types.xsd +159 -0
  12. package/templates/.agent/skills/minimax-docx/assets/xsd/wml-subset.xsd +589 -0
  13. package/templates/.agent/skills/minimax-docx/references/cjk_typography.md +357 -0
  14. package/templates/.agent/skills/minimax-docx/references/cjk_university_template_guide.md +184 -0
  15. package/templates/.agent/skills/minimax-docx/references/comments_guide.md +191 -0
  16. package/templates/.agent/skills/minimax-docx/references/design_good_bad_examples.md +829 -0
  17. package/templates/.agent/skills/minimax-docx/references/design_principles.md +819 -0
  18. package/templates/.agent/skills/minimax-docx/references/openxml_element_order.md +308 -0
  19. package/templates/.agent/skills/minimax-docx/references/openxml_encyclopedia_part1.md +4061 -0
  20. package/templates/.agent/skills/minimax-docx/references/openxml_encyclopedia_part2.md +2820 -0
  21. package/templates/.agent/skills/minimax-docx/references/openxml_encyclopedia_part3.md +3381 -0
  22. package/templates/.agent/skills/minimax-docx/references/openxml_namespaces.md +82 -0
  23. package/templates/.agent/skills/minimax-docx/references/openxml_units.md +72 -0
  24. package/templates/.agent/skills/minimax-docx/references/scenario_a_create.md +284 -0
  25. package/templates/.agent/skills/minimax-docx/references/scenario_b_edit_content.md +295 -0
  26. package/templates/.agent/skills/minimax-docx/references/scenario_c_apply_template.md +456 -0
  27. package/templates/.agent/skills/minimax-docx/references/track_changes_guide.md +200 -0
  28. package/templates/.agent/skills/minimax-docx/references/troubleshooting.md +506 -0
  29. package/templates/.agent/skills/minimax-docx/references/typography_guide.md +294 -0
  30. package/templates/.agent/skills/minimax-docx/references/xsd_validation_guide.md +158 -0
  31. package/templates/.agent/skills/minimax-docx/scripts/doc_to_docx.sh +40 -0
  32. package/templates/.agent/skills/minimax-docx/scripts/docx_preview.sh +37 -0
  33. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Cli/MiniMaxAIDocx.Cli.csproj +19 -0
  34. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Cli/Program.cs +18 -0
  35. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/AnalyzeCommand.cs +147 -0
  36. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/ApplyTemplateCommand.cs +322 -0
  37. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/CreateCommand.cs +324 -0
  38. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/DiffCommand.cs +155 -0
  39. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/EditContentCommand.cs +487 -0
  40. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/FixOrderCommand.cs +108 -0
  41. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/MergeRunsCommand.cs +122 -0
  42. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/ValidateCommand.cs +107 -0
  43. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/MiniMaxAIDocx.Core.csproj +15 -0
  44. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/CommentSynchronizer.cs +169 -0
  45. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/ElementOrder.cs +80 -0
  46. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/NamespaceConstants.cs +42 -0
  47. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/RunMerger.cs +81 -0
  48. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/StyleAnalyzer.cs +81 -0
  49. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/TrackChangesHelper.cs +99 -0
  50. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/UnitConverter.cs +23 -0
  51. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples.cs +1832 -0
  52. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch1.cs +910 -0
  53. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch2.cs +999 -0
  54. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch3.cs +1048 -0
  55. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch4.cs +1038 -0
  56. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/CharacterFormattingSamples.cs +1020 -0
  57. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/DocumentCreationSamples.cs +1121 -0
  58. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/FieldAndTocSamples.cs +624 -0
  59. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/FootnoteAndCommentSamples.cs +675 -0
  60. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/HeaderFooterSamples.cs +838 -0
  61. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/ImageSamples.cs +917 -0
  62. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/ListAndNumberingSamples.cs +826 -0
  63. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/ParagraphFormattingSamples.cs +1199 -0
  64. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/StyleSystemSamples.cs +1487 -0
  65. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/TableSamples.cs +1163 -0
  66. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/TrackChangesSamples.cs +595 -0
  67. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Typography/CjkHelper.cs +39 -0
  68. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Typography/FontDefaults.cs +24 -0
  69. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Typography/PageSizes.cs +20 -0
  70. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/BusinessRuleValidator.cs +224 -0
  71. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/GateCheckValidator.cs +148 -0
  72. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/ValidationResult.cs +23 -0
  73. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/XsdValidator.cs +69 -0
  74. package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.slnx +4 -0
  75. package/templates/.agent/skills/minimax-docx/scripts/env_check.sh +196 -0
  76. package/templates/.agent/skills/minimax-docx/scripts/setup.ps1 +274 -0
  77. package/templates/.agent/skills/minimax-docx/scripts/setup.sh +504 -0
  78. package/templates/.agent/skills/minimax-multimodal-toolkit/SKILL.md +359 -0
  79. package/templates/.agent/skills/minimax-pdf/README.md +222 -0
  80. package/templates/.agent/skills/minimax-pdf/SKILL.md +201 -0
  81. package/templates/.agent/skills/minimax-pdf/design/design.md +381 -0
  82. package/templates/.agent/skills/minimax-pdf/scripts/cover.py +1579 -0
  83. package/templates/.agent/skills/minimax-pdf/scripts/fill_inspect.py +200 -0
  84. package/templates/.agent/skills/minimax-pdf/scripts/fill_write.py +242 -0
  85. package/templates/.agent/skills/minimax-pdf/scripts/make.sh +491 -0
  86. package/templates/.agent/skills/minimax-pdf/scripts/merge.py +112 -0
  87. package/templates/.agent/skills/minimax-pdf/scripts/palette.py +559 -0
  88. package/templates/.agent/skills/minimax-pdf/scripts/reformat_parse.py +374 -0
  89. package/templates/.agent/skills/minimax-pdf/scripts/render_body.py +1055 -0
  90. package/templates/.agent/skills/minimax-pdf/scripts/render_cover.cjs +111 -0
  91. package/templates/.agent/skills/minimax-xlsx/SKILL.md +138 -0
  92. package/templates/.agent/skills/minimax-xlsx/references/create.md +691 -0
  93. package/templates/.agent/skills/minimax-xlsx/references/edit.md +684 -0
  94. package/templates/.agent/skills/minimax-xlsx/references/fix.md +37 -0
  95. package/templates/.agent/skills/minimax-xlsx/references/format.md +768 -0
  96. package/templates/.agent/skills/minimax-xlsx/references/ooxml-cheatsheet.md +231 -0
  97. package/templates/.agent/skills/minimax-xlsx/references/read-analyze.md +97 -0
  98. package/templates/.agent/skills/minimax-xlsx/references/validate.md +772 -0
  99. package/templates/.agent/skills/minimax-xlsx/scripts/formula_check.py +422 -0
  100. package/templates/.agent/skills/minimax-xlsx/scripts/libreoffice_recalc.py +248 -0
  101. package/templates/.agent/skills/minimax-xlsx/scripts/shared_strings_builder.py +163 -0
  102. package/templates/.agent/skills/minimax-xlsx/scripts/style_audit.py +575 -0
  103. package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_add_column.py +395 -0
  104. package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_insert_row.py +274 -0
  105. package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_pack.py +87 -0
  106. package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_reader.py +362 -0
  107. package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_shift_rows.py +396 -0
  108. package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_unpack.py +130 -0
  109. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/[Content_Types].xml +9 -0
  110. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/_rels/.rels +6 -0
  111. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/_rels/workbook.xml.rels +19 -0
  112. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/sharedStrings.xml +33 -0
  113. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/styles.xml +160 -0
  114. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/workbook.xml +30 -0
  115. package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/worksheets/sheet1.xml +70 -0
  116. package/templates/.agent/skills/pptx-generator/SKILL.md +249 -0
  117. package/templates/.agent/skills/pptx-generator/references/design-system.md +392 -0
  118. package/templates/.agent/skills/pptx-generator/references/editing.md +162 -0
  119. package/templates/.agent/skills/pptx-generator/references/pitfalls.md +112 -0
  120. package/templates/.agent/skills/pptx-generator/references/pptxgenjs.md +420 -0
  121. package/templates/.agent/skills/pptx-generator/references/slide-types.md +413 -0
  122. package/templates/.agent/skills/tutorial-video-expert/SKILL.md +88 -0
  123. package/templates/.agent/skills/ui-ux-pro-max/SKILL.md +170 -585
  124. package/templates/.agent/skills/vision-analysis/SKILL.md +174 -0
  125. package/templates/.agent/workflows/analyze.md +3 -0
  126. package/templates/.agent/workflows/brand-report.md +44 -0
  127. package/templates/.agent/workflows/report.md +49 -0
@@ -0,0 +1,506 @@
1
+ # Troubleshooting Guide — Symptom-Driven
2
+
3
+ ## How to Use This Guide
4
+
5
+ Search by the **SYMPTOM** you observe, not the technical concept. Each entry follows:
6
+ - **Symptom** — what you see or what the user reports
7
+ - **Diagnosis** — how to confirm the root cause
8
+ - **Fix** — exact steps, commands, or code
9
+ - **Prevention** — how to avoid it next time
10
+
11
+ **Quick search keywords:** headings wrong, body text, repair, corrupt, font, tables missing, images missing, TOC broken, update table, page break, section break, hyperlink, numbered list, bullets, margins, page size, Chinese tofu, cover page, track changes, revision marks
12
+
13
+ ---
14
+
15
+ ## 1. "All headings look like body text" (Heading Styles Not Applied)
16
+
17
+ **Symptom:** After template application, headings have no formatting — they look like Normal paragraphs. Font size, bold, spacing are all wrong.
18
+
19
+ **Diagnosis:** The `pStyle` values in `document.xml` don't match the `styleId` values in `styles.xml`.
20
+
21
+ Common mismatches:
22
+ - Source uses `Heading1` but template defines the style as `1` (Chinese templates often use numeric styleIds)
23
+ - Source uses `heading1` (lowercase) but template has `Heading1` (case-sensitive!)
24
+ - `pStyle` references a style that simply doesn't exist in the output's `styles.xml`
25
+
26
+ Check with:
27
+ ```bash
28
+ # List all pStyle values used in the document
29
+ $CLI analyze --input output.docx | grep -i "pStyle"
30
+
31
+ # List all styleIds defined in styles.xml
32
+ $CLI analyze --input template.docx --part styles | grep "styleId"
33
+ ```
34
+
35
+ **Fix:** Build a styleId mapping table before applying the template. Update every `pStyle` value in the document content.
36
+
37
+ ```csharp
38
+ // Build mapping: source styleId → template styleId
39
+ var mapping = new Dictionary<string, string>();
40
+ // Compare by style name (w:name), not by styleId
41
+ foreach (var srcStyle in sourceStyles)
42
+ {
43
+ var templateStyle = templateStyles.FirstOrDefault(
44
+ s => s.StyleName?.Val?.Value == srcStyle.StyleName?.Val?.Value);
45
+ if (templateStyle != null)
46
+ mapping[srcStyle.StyleId!] = templateStyle.StyleId!;
47
+ }
48
+
49
+ // Apply mapping to all paragraphs
50
+ foreach (var para in body.Descendants<Paragraph>())
51
+ {
52
+ var pStyle = para.ParagraphProperties?.ParagraphStyleId;
53
+ if (pStyle != null && mapping.TryGetValue(pStyle.Val!, out var newId))
54
+ pStyle.Val = newId;
55
+ }
56
+ ```
57
+
58
+ **Prevention:** ALWAYS extract and compare styleIds from both source and template before template application. Never assume styleIds are the same across documents.
59
+
60
+ ---
61
+
62
+ ## 2. "Document opens with repair warnings" (XML Corruption)
63
+
64
+ **Symptom:** Word says "We found a problem with some content" or "Word found unreadable content" when opening.
65
+
66
+ **Diagnosis:** Element ordering is wrong. OpenXML is strict about child element order.
67
+
68
+ Common violations:
69
+ - `pPr` must come before runs in `w:p`
70
+ - `tblPr` must come before `tblGrid` in `w:tbl`
71
+ - `rPr` must come before `t`/`br`/`tab` in `w:r`
72
+ - `trPr` must come before `tc` in `w:tr`
73
+ - `tcPr` must come before content in `w:tc`
74
+
75
+ ```bash
76
+ # Validate to find ordering issues
77
+ $CLI validate --input doc.docx --xsd assets/xsd/wml-subset.xsd
78
+
79
+ # Auto-fix element ordering
80
+ $CLI fix-order --input doc.docx
81
+
82
+ # Re-validate
83
+ $CLI validate --input doc.docx --xsd assets/xsd/wml-subset.xsd
84
+ ```
85
+
86
+ **Fix:**
87
+ ```bash
88
+ $CLI fix-order --input doc.docx
89
+ ```
90
+
91
+ If auto-fix doesn't resolve it, unpack and inspect manually:
92
+ ```bash
93
+ $CLI unpack --input doc.docx --output unpacked/
94
+ # Check word/document.xml for ordering issues
95
+ # Fix, then repack:
96
+ $CLI pack --input unpacked/ --output fixed.docx
97
+ ```
98
+
99
+ **Prevention:** Read `references/openxml_element_order.md` before writing any XML manipulation code. Always append properties elements first, then content elements.
100
+
101
+ ---
102
+
103
+ ## 3. "All text is in wrong font" (Font Contamination)
104
+
105
+ **Symptom:** Template specifies 宋体/Times New Roman but document shows Google Sans, Arial, Calibri, or whatever font the source document used.
106
+
107
+ **Diagnosis:** Source document's `rPr` contains inline `rFonts` declarations that override template styles. Direct formatting always wins over style-based formatting in OpenXML.
108
+
109
+ ```bash
110
+ # Check for font contamination
111
+ $CLI analyze --input output.docx | grep -i "font"
112
+ # Look for rFonts in the content — if present, they're overriding styles
113
+ ```
114
+
115
+ **Fix:** Strip `rFonts` from `rPr` when copying content, but KEEP `w:eastAsia` for CJK text:
116
+
117
+ ```csharp
118
+ foreach (var rPr in body.Descendants<RunProperties>())
119
+ {
120
+ var rFonts = rPr.GetFirstChild<RunFonts>();
121
+ if (rFonts != null)
122
+ {
123
+ // Preserve EastAsia font for CJK — removing it causes tofu (□□□)
124
+ var eastAsia = rFonts.EastAsia?.Value;
125
+ rFonts.Remove();
126
+
127
+ // Re-add only eastAsia if it was set and text contains CJK
128
+ if (!string.IsNullOrEmpty(eastAsia))
129
+ {
130
+ rPr.Append(new RunFonts { EastAsia = eastAsia });
131
+ }
132
+ }
133
+ }
134
+ ```
135
+
136
+ Also strip these common direct formatting overrides:
137
+ - `w:sz` / `w:szCs` (font size)
138
+ - `w:color` (text color)
139
+ - `w:b` / `w:i` when they contradict the style
140
+
141
+ **Prevention:** Always clean direct formatting when copying content between documents. Keep only `pStyle`/`rStyle` references and `w:t` text.
142
+
143
+ ---
144
+
145
+ ## 4. "Tables are missing" (Tables Lost During Copy)
146
+
147
+ **Symptom:** Source had 5 tables but output only has 2 (or 0).
148
+
149
+ **Diagnosis:** Code used `body.findall('w:p')` or `body.Descendants<Paragraph>()` at the top level instead of iterating all children. This skips `w:tbl` elements.
150
+
151
+ ```bash
152
+ # Verify table count
153
+ $CLI analyze --input source.docx | grep -i "table"
154
+ $CLI analyze --input output.docx | grep -i "table"
155
+ ```
156
+
157
+ **Fix:** Use `list(body)` or `body.ChildElements` to get ALL top-level children including tables:
158
+
159
+ ```csharp
160
+ // WRONG — skips tables, section properties, and other non-paragraph elements
161
+ var paragraphs = body.Elements<Paragraph>();
162
+
163
+ // CORRECT — gets everything: paragraphs, tables, SDT blocks, etc.
164
+ var allElements = body.ChildElements.ToList();
165
+ ```
166
+
167
+ In Python with lxml:
168
+ ```python
169
+ # WRONG
170
+ elements = body.findall('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}p')
171
+
172
+ # CORRECT
173
+ elements = list(body) # all direct children
174
+ ```
175
+
176
+ **Prevention:** Always use `list(body)` or `body.ChildElements` for iteration, never filter by a single element type alone when copying content.
177
+
178
+ ---
179
+
180
+ ## 5. "Images are missing or show broken icon"
181
+
182
+ **Symptom:** Image placeholders appear but images don't render. Or images are completely absent.
183
+
184
+ **Diagnosis:** The `r:embed` rId in `w:drawing` doesn't match any relationship in `document.xml.rels`, or the media file wasn't copied to the output ZIP.
185
+
186
+ ```bash
187
+ # Check relationships
188
+ $CLI analyze --input output.docx --part rels | grep -i "image"
189
+
190
+ # Check if media files exist
191
+ $CLI unpack --input output.docx --output unpacked/
192
+ ls unpacked/word/media/
193
+ ```
194
+
195
+ **Fix:**
196
+ 1. Check source rels for image file paths
197
+ 2. Copy media files from source to output
198
+ 3. Add/update relationships in output rels
199
+ 4. Update `r:embed` values in drawing elements
200
+
201
+ ```csharp
202
+ // When copying content with images between documents:
203
+ foreach (var drawing in body.Descendants<Drawing>())
204
+ {
205
+ var blip = drawing.Descendants<DocumentFormat.OpenXml.Drawing.Blip>().FirstOrDefault();
206
+ if (blip?.Embed?.Value != null)
207
+ {
208
+ var sourceRel = sourcePart.GetReferenceRelationship(blip.Embed.Value);
209
+ // Copy the image part to the target document
210
+ var imagePart = targetPart.AddImagePart(ImagePartType.Png);
211
+ using var stream = sourcePart.GetPartById(blip.Embed.Value).GetStream();
212
+ imagePart.FeedData(stream);
213
+ // Update the rId reference
214
+ blip.Embed = targetPart.GetIdOfPart(imagePart);
215
+ }
216
+ }
217
+ ```
218
+
219
+ **Prevention:** Always do rId remapping + media file copy when moving content between documents. Never assume rIds are portable across documents.
220
+
221
+ ---
222
+
223
+ ## 6. "TOC shows stale/wrong entries" or "Update Table doesn't work"
224
+
225
+ **Symptom:** Table of contents shows the template's example entries (e.g., "第1章 绪论...1") instead of actual headings. Or clicking "Update Table" in Word does nothing.
226
+
227
+ **Diagnosis:**
228
+ - **Stale entries (normal):** TOC entries are static text cached inside the field. They don't auto-update until the user explicitly updates in Word.
229
+ - **Update Table fails:** The SDT wrapper or field code structure is damaged. The TOC in real templates is a mixed structure: SDT block + field code + static entries.
230
+
231
+ ```bash
232
+ # Check if TOC SDT exists
233
+ $CLI analyze --input output.docx | grep -i "sdt\|toc"
234
+ ```
235
+
236
+ **Fix:**
237
+ - **If entries are just stale:** This is expected behavior. The user must right-click TOC, then "Update Field" in Word. Or enable auto-update:
238
+ ```csharp
239
+ // See FieldAndTocSamples.EnableUpdateFieldsOnOpen()
240
+ FieldAndTocSamples.EnableUpdateFieldsOnOpen(settingsPart);
241
+ ```
242
+ - **If SDT is damaged:** Keep the entire SDT block from the template intact. Do not modify it.
243
+ - **If field code is missing:** Ensure the TOC contains: `fldChar begin` + `instrText` + `fldChar separate` + static entries + `fldChar end`. See `FieldAndTocSamples.CreateMixedTocStructure()` for the complete pattern.
244
+ - **If you rebuilt TOC from scratch (common mistake):** You likely destroyed the SDT wrapper. Use the template's original SDT block instead. See `Samples/FieldAndTocSamples.cs` method `CreateMixedTocStructure` for how real-world TOC is structured.
245
+
246
+ **Prevention:** When doing Base-Replace (C-2), keep the template's TOC zone completely untouched. Do not strip, rebuild, or modify the SDT block. The TOC will auto-update when the user opens in Word.
247
+
248
+ ---
249
+
250
+ ## 7. "Chapters don't start on new pages" (Missing Section Breaks)
251
+
252
+ **Symptom:** Content flows continuously without page breaks between chapters. Chapter 2 starts right after Chapter 1's last paragraph on the same page.
253
+
254
+ **Diagnosis:** No `sectPr` elements or page break paragraphs between chapters.
255
+
256
+ **Fix:** Insert a paragraph with `sectPr` in its `pPr` before each chapter heading, or insert a page break:
257
+
258
+ ```csharp
259
+ // Option 1: Section break (preserves per-section settings like headers/margins)
260
+ var breakPara = new Paragraph(
261
+ new ParagraphProperties(
262
+ new SectionProperties(
263
+ new SectionType { Val = SectionMarkValues.NextPage })));
264
+
265
+ // Option 2: Simple page break (lighter weight)
266
+ var breakPara = new Paragraph(
267
+ new Run(new Break { Type = BreakValues.Page }));
268
+
269
+ // Insert before each Heading1
270
+ body.InsertBefore(breakPara, heading1Paragraph);
271
+ ```
272
+
273
+ **Prevention:** When copying content, insert page/section breaks before Heading1 paragraphs as needed. Check source document's section structure before copying.
274
+
275
+ ---
276
+
277
+ ## 8. "Hyperlinks don't work" (Broken Links)
278
+
279
+ **Symptom:** Clicking a hyperlink in the output document does nothing, or it navigates to the wrong URL.
280
+
281
+ **Diagnosis:** `w:hyperlink r:id` points to a relationship that doesn't exist in `document.xml.rels`.
282
+
283
+ ```bash
284
+ # Check hyperlink relationships
285
+ $CLI analyze --input output.docx --part rels | grep -i "hyperlink"
286
+ ```
287
+
288
+ **Fix:** Merge source document's hyperlink relationships into output's rels file. Update rId references.
289
+
290
+ ```csharp
291
+ foreach (var hyperlink in body.Descendants<Hyperlink>())
292
+ {
293
+ if (hyperlink.Id?.Value != null)
294
+ {
295
+ var sourceRel = sourcePart.HyperlinkRelationships
296
+ .FirstOrDefault(r => r.Id == hyperlink.Id.Value);
297
+ if (sourceRel != null)
298
+ {
299
+ targetPart.AddHyperlinkRelationship(sourceRel.Uri, sourceRel.IsExternal);
300
+ var newRel = targetPart.HyperlinkRelationships.Last();
301
+ hyperlink.Id = newRel.Id;
302
+ }
303
+ }
304
+ }
305
+ ```
306
+
307
+ **Prevention:** Always merge ALL relationship types (images, hyperlinks, headers, footers) when combining documents. Never assume source rIds work in the target.
308
+
309
+ ---
310
+
311
+ ## 9. "Numbered lists show wrong numbers" or "Bullets disappeared"
312
+
313
+ **Symptom:** Lists that were numbered 1, 2, 3 now show 1, 1, 1 or have no numbers/bullets at all.
314
+
315
+ **Diagnosis:** `numId` in `pPr` references a numbering definition that doesn't exist in `numbering.xml`, or `abstractNumId` mapping is broken.
316
+
317
+ ```bash
318
+ # Check numbering definitions
319
+ $CLI analyze --input output.docx --part numbering
320
+ ```
321
+
322
+ **Fix:** Map source numIds to template numIds, or merge numbering definitions:
323
+
324
+ ```csharp
325
+ // 1. Copy abstractNum definitions from source to target numbering.xml
326
+ // 2. Create new num entries pointing to the copied abstractNum
327
+ // 3. Update all numId references in document content
328
+
329
+ var sourceNumbering = sourceNumberingPart.Numbering;
330
+ var targetNumbering = targetNumberingPart.Numbering;
331
+
332
+ // Get max existing IDs to avoid collisions
333
+ int maxAbstractNumId = targetNumbering.Elements<AbstractNum>()
334
+ .Max(a => a.AbstractNumberId?.Value ?? 0) + 1;
335
+ int maxNumId = targetNumbering.Elements<NumberingInstance>()
336
+ .Max(n => n.NumberID?.Value ?? 0) + 1;
337
+ ```
338
+
339
+ **Prevention:** Include `numbering.xml` reconciliation in template application workflow. See `Samples/ListAndNumberingSamples.cs` for correct numbering setup.
340
+
341
+ ---
342
+
343
+ ## 10. "Page margins/size are wrong"
344
+
345
+ **Symptom:** Output has different margins, page size, or orientation than the template.
346
+
347
+ **Diagnosis:** Source document's `sectPr` is overriding the template's `sectPr`. The final `sectPr` (child of `body`) controls the last section's layout.
348
+
349
+ ```bash
350
+ # Compare section properties
351
+ $CLI analyze --input template.docx | grep -i "sectPr\|margin\|pgSz"
352
+ $CLI analyze --input output.docx | grep -i "sectPr\|margin\|pgSz"
353
+ ```
354
+
355
+ **Fix:** Use the template's final `sectPr`. For intermediate `sectPr` elements (multi-section documents), merge carefully.
356
+
357
+ ```csharp
358
+ // Replace output's final sectPr with template's
359
+ var templateSectPr = templateBody.Elements<SectionProperties>().LastOrDefault();
360
+ var outputSectPr = outputBody.Elements<SectionProperties>().LastOrDefault();
361
+
362
+ if (templateSectPr != null)
363
+ {
364
+ var cloned = templateSectPr.CloneNode(true) as SectionProperties;
365
+ if (outputSectPr != null)
366
+ outputBody.ReplaceChild(cloned!, outputSectPr);
367
+ else
368
+ outputBody.Append(cloned!);
369
+ }
370
+ ```
371
+
372
+ **Prevention:** Always use the template's `sectPr` as authority for page layout. Strip source document's `sectPr` before copying content.
373
+
374
+ ---
375
+
376
+ ## 11. "Chinese text renders as boxes/tofu"
377
+
378
+ **Symptom:** Chinese characters display as square boxes (□□□) or missing glyphs.
379
+
380
+ **Diagnosis:** `rFonts w:eastAsia` is set to a font that doesn't exist on the system, or is missing entirely. Without an East Asian font declaration, the rendering engine may fall back to a font without CJK coverage.
381
+
382
+ **Fix:** Ensure all CJK text has `w:eastAsia` set to an available font:
383
+
384
+ ```csharp
385
+ foreach (var run in body.Descendants<Run>())
386
+ {
387
+ var text = run.InnerText;
388
+ if (ContainsCjk(text))
389
+ {
390
+ var rPr = run.RunProperties ?? new RunProperties();
391
+ var rFonts = rPr.GetFirstChild<RunFonts>();
392
+ if (rFonts == null)
393
+ {
394
+ rFonts = new RunFonts();
395
+ rPr.Append(rFonts);
396
+ }
397
+ // Set to a universally available CJK font
398
+ rFonts.EastAsia = "SimSun"; // 宋体 — safest default
399
+ if (run.RunProperties == null) run.PrependChild(rPr);
400
+ }
401
+ }
402
+
403
+ static bool ContainsCjk(string text)
404
+ {
405
+ return text.Any(c => c >= 0x4E00 && c <= 0x9FFF);
406
+ }
407
+ ```
408
+
409
+ Common safe CJK fonts: 宋体 (SimSun), 黑体 (SimHei), 仿宋 (FangSong), 楷体 (KaiTi).
410
+
411
+ **Prevention:** When cleaning `rPr` formatting, ALWAYS preserve `w:eastAsia` font declarations. See also `references/cjk_typography.md`.
412
+
413
+ ---
414
+
415
+ ## 12. "Template's cover page / declaration page is missing"
416
+
417
+ **Symptom:** Output document starts directly with body content — no cover page, no declaration, no abstract, no table of contents. The template's structural front matter was discarded.
418
+
419
+ **Diagnosis:** Used Overlay (C-1) strategy when Base-Replace (C-2) was needed. Overlay applies styles to the source document but discards the template's structural content (cover, declaration, abstract, TOC).
420
+
421
+ ```bash
422
+ # Check template structure
423
+ $CLI analyze --input template.docx
424
+ # If template has >50 paragraphs with cover/TOC/declaration, C-2 is needed
425
+ ```
426
+
427
+ **Fix:** Use Base-Replace (C-2) strategy — template is the base, only replace the example body content zone with the user's content:
428
+
429
+ 1. Identify the template's "body zone" (everything between TOC and final sectPr)
430
+ 2. Remove the template's example body content
431
+ 3. Insert the user's content into the body zone
432
+ 4. Keep everything else from the template (cover, declaration, abstract, TOC, sectPr)
433
+
434
+ ```bash
435
+ $CLI apply-template --input source.docx --template template.docx --output out.docx --strategy base-replace
436
+ ```
437
+
438
+ **Prevention:** Analyze template structure FIRST. If template has structural content (cover, TOC, declaration sections), always use C-2 (Base-Replace). Read `references/scenario_c_apply_template.md` for detailed decision criteria.
439
+
440
+ ---
441
+
442
+ ## 13. "Track changes markers appear unexpectedly"
443
+
444
+ **Symptom:** Output shows red/green revision marks (insertions, deletions) that weren't in the source document.
445
+
446
+ **Diagnosis:** Template had track changes enabled, or content was inserted as revisions rather than normal text.
447
+
448
+ ```bash
449
+ # Check for revision marks
450
+ $CLI analyze --input output.docx | grep -i "revision\|ins\|del\|track"
451
+ ```
452
+
453
+ **Fix:** Accept all revisions by flattening `w:ins` and `w:del` elements:
454
+
455
+ ```csharp
456
+ // Accept insertions: unwrap w:ins, keep content
457
+ foreach (var ins in body.Descendants<InsertedRun>().ToList())
458
+ {
459
+ var parent = ins.Parent!;
460
+ foreach (var child in ins.ChildElements.ToList())
461
+ {
462
+ parent.InsertBefore(child.CloneNode(true), ins);
463
+ }
464
+ ins.Remove();
465
+ }
466
+
467
+ // Accept deletions: remove w:del and its content entirely
468
+ foreach (var del in body.Descendants<DeletedRun>().ToList())
469
+ {
470
+ del.Remove();
471
+ }
472
+ ```
473
+
474
+ Or disable tracking in settings:
475
+ ```csharp
476
+ var settings = settingsPart.Settings;
477
+ var trackChanges = settings.GetFirstChild<TrackChanges>();
478
+ trackChanges?.Remove();
479
+ ```
480
+
481
+ **Prevention:** Check template's `settings.xml` for `trackChanges` before starting. If present, accept all revisions in the template first.
482
+
483
+ ---
484
+
485
+ ## Recovery Strategy — When Multiple Issues Exist
486
+
487
+ When a document has multiple problems, fix them in this priority order:
488
+
489
+ ```
490
+ 1. [Content_Types].xml — without this, nothing opens
491
+ 2. _rels/.rels — package relationships
492
+ 3. word/_rels/document.xml.rels — part relationships (images, hyperlinks)
493
+ 4. word/document.xml — element ordering (fix-order)
494
+ 5. word/styles.xml — style definitions and styleId mapping
495
+ 6. word/numbering.xml — list/numbering definitions
496
+ 7. Everything else — headers, footers, comments, settings
497
+ ```
498
+
499
+ ```bash
500
+ # Full recovery pipeline
501
+ $CLI unpack --input broken.docx --output unpacked/
502
+ $CLI validate --input broken.docx --xsd assets/xsd/wml-subset.xsd # find all errors
503
+ $CLI fix-order --input broken.docx # fix element ordering
504
+ $CLI validate --input broken.docx --business # check business rules
505
+ scripts/docx_preview.sh broken.docx # visual check
506
+ ```