@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.
- package/README.md +186 -78
- package/package.json +4 -3
- package/templates/.agent/skills/marketing-report-expert/SKILL.md +70 -0
- package/templates/.agent/skills/minimax-docx/LICENSE +21 -0
- package/templates/.agent/skills/minimax-docx/SKILL.md +274 -0
- package/templates/.agent/skills/minimax-docx/assets/styles/academic_styles.xml +250 -0
- package/templates/.agent/skills/minimax-docx/assets/styles/corporate_styles.xml +284 -0
- package/templates/.agent/skills/minimax-docx/assets/styles/default_styles.xml +449 -0
- package/templates/.agent/skills/minimax-docx/assets/xsd/aesthetic-rules.xsd +470 -0
- package/templates/.agent/skills/minimax-docx/assets/xsd/business-rules.xsd +130 -0
- package/templates/.agent/skills/minimax-docx/assets/xsd/common-types.xsd +159 -0
- package/templates/.agent/skills/minimax-docx/assets/xsd/wml-subset.xsd +589 -0
- package/templates/.agent/skills/minimax-docx/references/cjk_typography.md +357 -0
- package/templates/.agent/skills/minimax-docx/references/cjk_university_template_guide.md +184 -0
- package/templates/.agent/skills/minimax-docx/references/comments_guide.md +191 -0
- package/templates/.agent/skills/minimax-docx/references/design_good_bad_examples.md +829 -0
- package/templates/.agent/skills/minimax-docx/references/design_principles.md +819 -0
- package/templates/.agent/skills/minimax-docx/references/openxml_element_order.md +308 -0
- package/templates/.agent/skills/minimax-docx/references/openxml_encyclopedia_part1.md +4061 -0
- package/templates/.agent/skills/minimax-docx/references/openxml_encyclopedia_part2.md +2820 -0
- package/templates/.agent/skills/minimax-docx/references/openxml_encyclopedia_part3.md +3381 -0
- package/templates/.agent/skills/minimax-docx/references/openxml_namespaces.md +82 -0
- package/templates/.agent/skills/minimax-docx/references/openxml_units.md +72 -0
- package/templates/.agent/skills/minimax-docx/references/scenario_a_create.md +284 -0
- package/templates/.agent/skills/minimax-docx/references/scenario_b_edit_content.md +295 -0
- package/templates/.agent/skills/minimax-docx/references/scenario_c_apply_template.md +456 -0
- package/templates/.agent/skills/minimax-docx/references/track_changes_guide.md +200 -0
- package/templates/.agent/skills/minimax-docx/references/troubleshooting.md +506 -0
- package/templates/.agent/skills/minimax-docx/references/typography_guide.md +294 -0
- package/templates/.agent/skills/minimax-docx/references/xsd_validation_guide.md +158 -0
- package/templates/.agent/skills/minimax-docx/scripts/doc_to_docx.sh +40 -0
- package/templates/.agent/skills/minimax-docx/scripts/docx_preview.sh +37 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Cli/MiniMaxAIDocx.Cli.csproj +19 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Cli/Program.cs +18 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/AnalyzeCommand.cs +147 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/ApplyTemplateCommand.cs +322 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/CreateCommand.cs +324 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/DiffCommand.cs +155 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/EditContentCommand.cs +487 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/FixOrderCommand.cs +108 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/MergeRunsCommand.cs +122 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Commands/ValidateCommand.cs +107 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/MiniMaxAIDocx.Core.csproj +15 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/CommentSynchronizer.cs +169 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/ElementOrder.cs +80 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/NamespaceConstants.cs +42 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/RunMerger.cs +81 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/StyleAnalyzer.cs +81 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/TrackChangesHelper.cs +99 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/OpenXml/UnitConverter.cs +23 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples.cs +1832 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch1.cs +910 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch2.cs +999 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch3.cs +1048 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/AestheticRecipeSamples_Batch4.cs +1038 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/CharacterFormattingSamples.cs +1020 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/DocumentCreationSamples.cs +1121 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/FieldAndTocSamples.cs +624 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/FootnoteAndCommentSamples.cs +675 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/HeaderFooterSamples.cs +838 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/ImageSamples.cs +917 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/ListAndNumberingSamples.cs +826 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/ParagraphFormattingSamples.cs +1199 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/StyleSystemSamples.cs +1487 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/TableSamples.cs +1163 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Samples/TrackChangesSamples.cs +595 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Typography/CjkHelper.cs +39 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Typography/FontDefaults.cs +24 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Typography/PageSizes.cs +20 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/BusinessRuleValidator.cs +224 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/GateCheckValidator.cs +148 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/ValidationResult.cs +23 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.Core/Validation/XsdValidator.cs +69 -0
- package/templates/.agent/skills/minimax-docx/scripts/dotnet/MiniMaxAIDocx.slnx +4 -0
- package/templates/.agent/skills/minimax-docx/scripts/env_check.sh +196 -0
- package/templates/.agent/skills/minimax-docx/scripts/setup.ps1 +274 -0
- package/templates/.agent/skills/minimax-docx/scripts/setup.sh +504 -0
- package/templates/.agent/skills/minimax-multimodal-toolkit/SKILL.md +359 -0
- package/templates/.agent/skills/minimax-pdf/README.md +222 -0
- package/templates/.agent/skills/minimax-pdf/SKILL.md +201 -0
- package/templates/.agent/skills/minimax-pdf/design/design.md +381 -0
- package/templates/.agent/skills/minimax-pdf/scripts/cover.py +1579 -0
- package/templates/.agent/skills/minimax-pdf/scripts/fill_inspect.py +200 -0
- package/templates/.agent/skills/minimax-pdf/scripts/fill_write.py +242 -0
- package/templates/.agent/skills/minimax-pdf/scripts/make.sh +491 -0
- package/templates/.agent/skills/minimax-pdf/scripts/merge.py +112 -0
- package/templates/.agent/skills/minimax-pdf/scripts/palette.py +559 -0
- package/templates/.agent/skills/minimax-pdf/scripts/reformat_parse.py +374 -0
- package/templates/.agent/skills/minimax-pdf/scripts/render_body.py +1055 -0
- package/templates/.agent/skills/minimax-pdf/scripts/render_cover.cjs +111 -0
- package/templates/.agent/skills/minimax-xlsx/SKILL.md +138 -0
- package/templates/.agent/skills/minimax-xlsx/references/create.md +691 -0
- package/templates/.agent/skills/minimax-xlsx/references/edit.md +684 -0
- package/templates/.agent/skills/minimax-xlsx/references/fix.md +37 -0
- package/templates/.agent/skills/minimax-xlsx/references/format.md +768 -0
- package/templates/.agent/skills/minimax-xlsx/references/ooxml-cheatsheet.md +231 -0
- package/templates/.agent/skills/minimax-xlsx/references/read-analyze.md +97 -0
- package/templates/.agent/skills/minimax-xlsx/references/validate.md +772 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/formula_check.py +422 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/libreoffice_recalc.py +248 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/shared_strings_builder.py +163 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/style_audit.py +575 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_add_column.py +395 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_insert_row.py +274 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_pack.py +87 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_reader.py +362 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_shift_rows.py +396 -0
- package/templates/.agent/skills/minimax-xlsx/scripts/xlsx_unpack.py +130 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/[Content_Types].xml +9 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/_rels/.rels +6 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/_rels/workbook.xml.rels +19 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/sharedStrings.xml +33 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/styles.xml +160 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/workbook.xml +30 -0
- package/templates/.agent/skills/minimax-xlsx/templates/minimal_xlsx/xl/worksheets/sheet1.xml +70 -0
- package/templates/.agent/skills/pptx-generator/SKILL.md +249 -0
- package/templates/.agent/skills/pptx-generator/references/design-system.md +392 -0
- package/templates/.agent/skills/pptx-generator/references/editing.md +162 -0
- package/templates/.agent/skills/pptx-generator/references/pitfalls.md +112 -0
- package/templates/.agent/skills/pptx-generator/references/pptxgenjs.md +420 -0
- package/templates/.agent/skills/pptx-generator/references/slide-types.md +413 -0
- package/templates/.agent/skills/tutorial-video-expert/SKILL.md +88 -0
- package/templates/.agent/skills/ui-ux-pro-max/SKILL.md +170 -585
- package/templates/.agent/skills/vision-analysis/SKILL.md +174 -0
- package/templates/.agent/workflows/analyze.md +3 -0
- package/templates/.agent/workflows/brand-report.md +44 -0
- package/templates/.agent/workflows/report.md +49 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# Scenario B: Editing / Filling Content in Existing DOCX
|
|
2
|
+
|
|
3
|
+
## Core Principle
|
|
4
|
+
|
|
5
|
+
**"First, do no harm."** When editing an existing document, minimize changes. Touch only what needs to change. Preserve all formatting, styles, relationships, and structure that are not directly involved in the edit.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## When to Use
|
|
10
|
+
|
|
11
|
+
- Replacing placeholder text (`{{name}}`, `$DATE$`, `[PLACEHOLDER]`)
|
|
12
|
+
- Updating specific paragraphs or table cells
|
|
13
|
+
- Filling in form fields
|
|
14
|
+
- Adding or removing paragraphs in a known location
|
|
15
|
+
- Inserting tracked changes for review workflows
|
|
16
|
+
|
|
17
|
+
Do NOT use when: the user wants to change the look/style of the entire document (→ Scenario C) or create from scratch (→ Scenario A).
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Workflow
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
1. Preview → CLI: analyze <input.docx>
|
|
25
|
+
2. Analyze → Understand structure: sections, styles, headings, tables
|
|
26
|
+
3. Identify → Locate exact edit targets (paragraph index, table index, placeholder text)
|
|
27
|
+
4. Edit → Apply surgical changes via CLI or direct XML
|
|
28
|
+
5. Validate → CLI: validate <output.docx>
|
|
29
|
+
6. Diff → Compare before/after to verify only intended changes were made
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## When to Use API vs Direct XML
|
|
35
|
+
|
|
36
|
+
### Use CLI Edit Command When:
|
|
37
|
+
- Replacing placeholder text (e.g., `{{fieldName}}` → actual value)
|
|
38
|
+
- Filling table data from JSON
|
|
39
|
+
- Updating document properties (title, author)
|
|
40
|
+
- Simple text insertions or deletions
|
|
41
|
+
|
|
42
|
+
### Use Direct XML Manipulation When:
|
|
43
|
+
- Text spans multiple runs with different formatting (run-boundary issues)
|
|
44
|
+
- Adding complex structures (nested tables, multi-image layouts)
|
|
45
|
+
- Manipulating Track Changes markup
|
|
46
|
+
- Modifying header/footer content
|
|
47
|
+
- Adjusting section properties
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Placeholder Patterns
|
|
52
|
+
|
|
53
|
+
The CLI natively supports `{{fieldName}}` placeholders:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Replace all {{placeholders}} from a JSON map
|
|
57
|
+
dotnet run ... edit input.docx --fill-placeholders data.json --output filled.docx
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Where `data.json`:
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"companyName": "Acme Corp",
|
|
64
|
+
"date": "March 21, 2026",
|
|
65
|
+
"amount": "$15,000.00",
|
|
66
|
+
"recipientName": "Jane Smith"
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Other placeholder formats (`$FIELD$`, `[PLACEHOLDER]`) require text replacement:
|
|
71
|
+
```bash
|
|
72
|
+
dotnet run ... edit input.docx --replace "$DATE$" "March 21, 2026" --output updated.docx
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Text Replacement Strategies
|
|
78
|
+
|
|
79
|
+
### Simple Replacement
|
|
80
|
+
|
|
81
|
+
When the entire search text is within a single `w:r` (run):
|
|
82
|
+
|
|
83
|
+
```xml
|
|
84
|
+
<!-- Before -->
|
|
85
|
+
<w:r>
|
|
86
|
+
<w:rPr><w:b /></w:rPr>
|
|
87
|
+
<w:t>{{companyName}}</w:t>
|
|
88
|
+
</w:r>
|
|
89
|
+
|
|
90
|
+
<!-- After — formatting preserved -->
|
|
91
|
+
<w:r>
|
|
92
|
+
<w:rPr><w:b /></w:rPr>
|
|
93
|
+
<w:t>Acme Corp</w:t>
|
|
94
|
+
</w:r>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Direct replacement. The run's `w:rPr` is untouched.
|
|
98
|
+
|
|
99
|
+
### Complex Replacement (Split Runs)
|
|
100
|
+
|
|
101
|
+
When the search text is split across multiple runs (common when Word applies spell-check or formatting mid-text):
|
|
102
|
+
|
|
103
|
+
```xml
|
|
104
|
+
<!-- "{{companyName}}" split into 3 runs -->
|
|
105
|
+
<w:r><w:rPr><w:b /></w:rPr><w:t>{{company</w:t></w:r>
|
|
106
|
+
<w:r><w:rPr><w:b /><w:i /></w:rPr><w:t>Na</w:t></w:r>
|
|
107
|
+
<w:r><w:rPr><w:b /></w:rPr><w:t>me}}</w:t></w:r>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Strategy:
|
|
111
|
+
1. Concatenate text across runs to find the match
|
|
112
|
+
2. Place the replacement text in the **first** run (preserving its `w:rPr`)
|
|
113
|
+
3. Remove the text from subsequent runs (or remove the runs entirely if empty)
|
|
114
|
+
|
|
115
|
+
```xml
|
|
116
|
+
<!-- After -->
|
|
117
|
+
<w:r><w:rPr><w:b /></w:rPr><w:t>Acme Corp</w:t></w:r>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**Rule**: Always preserve the formatting of the first run in the match.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Table Editing
|
|
125
|
+
|
|
126
|
+
### By Index
|
|
127
|
+
|
|
128
|
+
Tables are 0-indexed in document order:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
dotnet run ... edit input.docx --table-index 0 --table-data data.json --output updated.docx
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### By Header Matching
|
|
135
|
+
|
|
136
|
+
Find a table by its header row content:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
dotnet run ... edit input.docx --table-match "Name,Amount,Date" --table-data data.json
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Table Data JSON Format
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"rows": [
|
|
147
|
+
["Alice Johnson", "$5,000", "2026-03-15"],
|
|
148
|
+
["Bob Smith", "$3,200", "2026-03-18"]
|
|
149
|
+
],
|
|
150
|
+
"appendRows": true
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
- `appendRows: true` — add rows after existing data
|
|
155
|
+
- `appendRows: false` (default) — replace all data rows (keeps header row)
|
|
156
|
+
|
|
157
|
+
### Direct XML Table Editing
|
|
158
|
+
|
|
159
|
+
To modify a specific cell, locate it by row/column index:
|
|
160
|
+
|
|
161
|
+
```xml
|
|
162
|
+
<!-- Row 2 (0-indexed), Column 1 -->
|
|
163
|
+
<w:tr> <!-- tr[2] -->
|
|
164
|
+
<w:tc>...</w:tc>
|
|
165
|
+
<w:tc> <!-- tc[1] — target cell -->
|
|
166
|
+
<w:p>
|
|
167
|
+
<w:r><w:t>Old Value</w:t></w:r>
|
|
168
|
+
</w:p>
|
|
169
|
+
</w:tc>
|
|
170
|
+
</w:tr>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Replace the `w:t` content. Do NOT modify `w:tcPr` (cell properties) or `w:tblPr` (table properties).
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Track Changes Guidance
|
|
178
|
+
|
|
179
|
+
### When to Add Revision Marks
|
|
180
|
+
- User explicitly requests tracked changes
|
|
181
|
+
- Document already has tracking enabled (`w:trackChanges` in settings)
|
|
182
|
+
- Collaborative review workflow
|
|
183
|
+
|
|
184
|
+
### When NOT to Add Revision Marks
|
|
185
|
+
- Form filling / placeholder replacement (these are "completing" the document, not "revising" it)
|
|
186
|
+
- Direct edits where the user wants a clean result
|
|
187
|
+
- Batch data filling operations
|
|
188
|
+
|
|
189
|
+
### Adding Tracked Changes
|
|
190
|
+
|
|
191
|
+
See `references/track_changes_guide.md` for full XML examples.
|
|
192
|
+
|
|
193
|
+
Quick reference — inserting text with tracking:
|
|
194
|
+
```xml
|
|
195
|
+
<w:ins w:id="1" w:author="MiniMaxAI" w:date="2026-03-21T10:00:00Z">
|
|
196
|
+
<w:r>
|
|
197
|
+
<w:t>New text here</w:t>
|
|
198
|
+
</w:r>
|
|
199
|
+
</w:ins>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Deleting text with tracking:
|
|
203
|
+
```xml
|
|
204
|
+
<w:del w:id="2" w:author="MiniMaxAI" w:date="2026-03-21T10:00:00Z">
|
|
205
|
+
<w:r>
|
|
206
|
+
<w:delText>Removed text</w:delText> <!-- MUST use delText, not t -->
|
|
207
|
+
</w:r>
|
|
208
|
+
</w:del>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Common Pitfalls
|
|
214
|
+
|
|
215
|
+
### 1. Breaking Run Boundaries
|
|
216
|
+
|
|
217
|
+
**Problem**: Replacing text that spans runs by naively modifying individual runs destroys inline formatting.
|
|
218
|
+
|
|
219
|
+
**Fix**: Concatenate run text, find match boundaries, consolidate into the first run, remove consumed runs.
|
|
220
|
+
|
|
221
|
+
### 2. Hyperlink Content
|
|
222
|
+
|
|
223
|
+
**Problem**: Replacing text inside a `w:hyperlink` element without preserving the hyperlink wrapper removes the link.
|
|
224
|
+
|
|
225
|
+
```xml
|
|
226
|
+
<w:hyperlink r:id="rId5">
|
|
227
|
+
<w:r>
|
|
228
|
+
<w:rPr><w:rStyle w:val="Hyperlink" /></w:rPr>
|
|
229
|
+
<w:t>Click here</w:t> <!-- Only replace this text -->
|
|
230
|
+
</w:r>
|
|
231
|
+
</w:hyperlink>
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
**Fix**: Only modify the `w:t` inside the hyperlink's run. Never remove or replace the `w:hyperlink` element itself.
|
|
235
|
+
|
|
236
|
+
### 3. Tracked Change Context
|
|
237
|
+
|
|
238
|
+
**Problem**: Replacing text that is inside a `w:ins` or `w:del` element without understanding the revision context creates invalid markup.
|
|
239
|
+
|
|
240
|
+
**Fix**: If the target text is inside a revision mark, either:
|
|
241
|
+
- Replace within the revision context (preserving the `w:ins`/`w:del` wrapper)
|
|
242
|
+
- Or delete the old revision and create a new one
|
|
243
|
+
|
|
244
|
+
### 4. Style Preservation
|
|
245
|
+
|
|
246
|
+
**Problem**: Adding new paragraphs without specifying a style causes them to inherit `Normal`, which may not match the surrounding context.
|
|
247
|
+
|
|
248
|
+
**Fix**: When inserting paragraphs, copy the `w:pStyle` from an adjacent paragraph of the same type.
|
|
249
|
+
|
|
250
|
+
### 5. Numbering Continuity
|
|
251
|
+
|
|
252
|
+
**Problem**: Inserting a new list item breaks numbering sequence.
|
|
253
|
+
|
|
254
|
+
**Fix**: Ensure the new paragraph has the same `w:numId` and `w:ilvl` as adjacent list items. If continuing a sequence, set `w:numPr` to match.
|
|
255
|
+
|
|
256
|
+
### 6. XML Special Characters
|
|
257
|
+
|
|
258
|
+
**Problem**: User content contains `&`, `<`, `>`, `"`, `'` — these must be escaped in XML.
|
|
259
|
+
|
|
260
|
+
**Fix**: Always XML-escape user-provided text before inserting into `w:t` elements:
|
|
261
|
+
- `&` → `&`
|
|
262
|
+
- `<` → `<`
|
|
263
|
+
- `>` → `>`
|
|
264
|
+
- `"` → `"`
|
|
265
|
+
- `'` → `'`
|
|
266
|
+
|
|
267
|
+
### 7. Whitespace Preservation
|
|
268
|
+
|
|
269
|
+
**Problem**: Leading/trailing spaces in `w:t` are stripped by XML parsers.
|
|
270
|
+
|
|
271
|
+
**Fix**: Add `xml:space="preserve"` attribute:
|
|
272
|
+
```xml
|
|
273
|
+
<w:t xml:space="preserve"> text with leading space</w:t>
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Diff Verification
|
|
279
|
+
|
|
280
|
+
After editing, always compare the before and after states:
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
# Structural diff — shows only changed elements
|
|
284
|
+
dotnet run ... diff original.docx modified.docx
|
|
285
|
+
|
|
286
|
+
# Text-only diff — shows content changes
|
|
287
|
+
dotnet run ... diff original.docx modified.docx --text-only
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Verify:
|
|
291
|
+
- Only intended text changed
|
|
292
|
+
- No styles were modified
|
|
293
|
+
- No relationships were added/removed unexpectedly
|
|
294
|
+
- Table structure intact (same number of rows/columns unless intentionally changed)
|
|
295
|
+
- Images and other media unchanged
|