docxmlater 1.16.0 → 1.18.0
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 +491 -259
- package/dist/core/Document.d.ts +22 -2
- package/dist/core/Document.d.ts.map +1 -1
- package/dist/core/Document.js +199 -7
- package/dist/core/Document.js.map +1 -1
- package/dist/core/DocumentParser.d.ts.map +1 -1
- package/dist/core/DocumentParser.js +41 -42
- package/dist/core/DocumentParser.js.map +1 -1
- package/dist/core/DocumentValidator.d.ts.map +1 -1
- package/dist/core/DocumentValidator.js +4 -3
- package/dist/core/DocumentValidator.js.map +1 -1
- package/dist/elements/Hyperlink.d.ts +1 -0
- package/dist/elements/Hyperlink.d.ts.map +1 -1
- package/dist/elements/Hyperlink.js +57 -36
- package/dist/elements/Hyperlink.js.map +1 -1
- package/dist/elements/ImageManager.d.ts.map +1 -1
- package/dist/elements/ImageManager.js +2 -1
- package/dist/elements/ImageManager.js.map +1 -1
- package/dist/elements/Paragraph.d.ts +3 -0
- package/dist/elements/Paragraph.d.ts.map +1 -1
- package/dist/elements/Paragraph.js +11 -2
- package/dist/elements/Paragraph.js.map +1 -1
- package/dist/elements/Run.d.ts.map +1 -1
- package/dist/elements/Run.js +6 -4
- package/dist/elements/Run.js.map +1 -1
- package/dist/elements/StructuredDocumentTag.d.ts +2 -0
- package/dist/elements/StructuredDocumentTag.d.ts.map +1 -1
- package/dist/elements/StructuredDocumentTag.js +5 -1
- package/dist/elements/StructuredDocumentTag.js.map +1 -1
- package/dist/elements/Table.d.ts.map +1 -1
- package/dist/elements/Table.js +3 -2
- package/dist/elements/Table.js.map +1 -1
- package/dist/formatting/AbstractNumbering.d.ts.map +1 -1
- package/dist/formatting/AbstractNumbering.js +2 -1
- package/dist/formatting/AbstractNumbering.js.map +1 -1
- package/dist/formatting/NumberingManager.d.ts.map +1 -1
- package/dist/formatting/NumberingManager.js +6 -5
- package/dist/formatting/NumberingManager.js.map +1 -1
- package/dist/formatting/Style.d.ts.map +1 -1
- package/dist/formatting/Style.js +2 -1
- package/dist/formatting/Style.js.map +1 -1
- package/dist/types/styleConfig.d.ts +1 -0
- package/dist/types/styleConfig.d.ts.map +1 -1
- package/dist/utils/deepClone.d.ts +3 -0
- package/dist/utils/deepClone.d.ts.map +1 -0
- package/dist/utils/deepClone.js +50 -0
- package/dist/utils/deepClone.js.map +1 -0
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +3 -2
- package/dist/utils/validation.js.map +1 -1
- package/dist/zip/ZipHandler.d.ts.map +1 -1
- package/dist/zip/ZipHandler.js +3 -2
- package/dist/zip/ZipHandler.js.map +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,259 +1,491 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
A
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
###
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
###
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
-
|
|
223
|
-
-
|
|
224
|
-
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
- `
|
|
239
|
-
- `
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
-
|
|
257
|
-
-
|
|
258
|
-
|
|
259
|
-
|
|
1
|
+
# docXMLater
|
|
2
|
+
|
|
3
|
+
A comprehensive, production-ready TypeScript/JavaScript framework for creating, reading, and manipulating Microsoft Word (.docx) documents programmatically.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### Core Document Operations
|
|
8
|
+
- Create DOCX files from scratch
|
|
9
|
+
- Read and modify existing DOCX files
|
|
10
|
+
- Buffer-based operations (load/save from memory)
|
|
11
|
+
- Document properties (core, extended, custom)
|
|
12
|
+
- Memory management with dispose pattern
|
|
13
|
+
|
|
14
|
+
### Text & Paragraph Formatting
|
|
15
|
+
- Character formatting: bold, italic, underline, strikethrough, subscript, superscript
|
|
16
|
+
- Font properties: family, size, color (RGB and theme colors), highlight
|
|
17
|
+
- Text effects: small caps, all caps, shadow, emboss, engrave
|
|
18
|
+
- Paragraph alignment, indentation, spacing, borders, shading
|
|
19
|
+
- Text search and replace with regex support
|
|
20
|
+
- Custom styles (paragraph, character, table)
|
|
21
|
+
|
|
22
|
+
### Lists & Tables
|
|
23
|
+
- Numbered lists (decimal, roman, alpha)
|
|
24
|
+
- Bulleted lists with various bullet styles
|
|
25
|
+
- Multi-level lists with custom numbering
|
|
26
|
+
- Tables with formatting, borders, shading
|
|
27
|
+
- Cell spanning (merge cells horizontally and vertically)
|
|
28
|
+
- Advanced table properties (margins, widths, alignment)
|
|
29
|
+
|
|
30
|
+
### Rich Content
|
|
31
|
+
- Images (PNG, JPEG, GIF, SVG) with positioning and text wrapping
|
|
32
|
+
- Headers & footers (different first page, odd/even pages)
|
|
33
|
+
- Hyperlinks (external URLs, internal bookmarks)
|
|
34
|
+
- Hyperlink defragmentation utility (fixes fragmented links from Google Docs)
|
|
35
|
+
- Bookmarks and cross-references
|
|
36
|
+
- Shapes and text boxes
|
|
37
|
+
|
|
38
|
+
### Advanced Features
|
|
39
|
+
- Track changes (revisions for insertions, deletions, formatting)
|
|
40
|
+
- Comments and annotations
|
|
41
|
+
- Table of contents generation with customizable heading levels
|
|
42
|
+
- Fields: merge fields, date/time, page numbers, TOC fields
|
|
43
|
+
- Footnotes and endnotes
|
|
44
|
+
- Content controls (Structured Document Tags)
|
|
45
|
+
- Multiple sections with different page layouts
|
|
46
|
+
- Page orientation, size, and margins
|
|
47
|
+
|
|
48
|
+
### Developer Tools
|
|
49
|
+
- Complete XML generation and parsing (ReDoS-safe, position-based parser)
|
|
50
|
+
- 40+ unit conversion functions (twips, EMUs, points, pixels, inches, cm)
|
|
51
|
+
- Validation utilities and corruption detection
|
|
52
|
+
- Full TypeScript support with comprehensive type definitions
|
|
53
|
+
- Error handling utilities
|
|
54
|
+
- Logging infrastructure with multiple log levels
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm install docxmlater
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
### Creating a New Document
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { Document } from 'docxmlater';
|
|
68
|
+
|
|
69
|
+
// Create a new document
|
|
70
|
+
const doc = Document.create();
|
|
71
|
+
|
|
72
|
+
// Add a paragraph
|
|
73
|
+
const para = doc.createParagraph();
|
|
74
|
+
para.addText('Hello, World!', { bold: true, fontSize: 24 });
|
|
75
|
+
|
|
76
|
+
// Save to file
|
|
77
|
+
await doc.save('hello.docx');
|
|
78
|
+
|
|
79
|
+
// Don't forget to dispose
|
|
80
|
+
doc.dispose();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Loading and Modifying Documents
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { Document } from 'docxmlater';
|
|
87
|
+
|
|
88
|
+
// Load existing document
|
|
89
|
+
const doc = await Document.load('input.docx');
|
|
90
|
+
|
|
91
|
+
// Find and replace text
|
|
92
|
+
doc.replaceText(/old text/g, 'new text');
|
|
93
|
+
|
|
94
|
+
// Add a new paragraph
|
|
95
|
+
const para = doc.createParagraph();
|
|
96
|
+
para.addText('Added paragraph', { italic: true });
|
|
97
|
+
|
|
98
|
+
// Save modifications
|
|
99
|
+
await doc.save('output.docx');
|
|
100
|
+
doc.dispose();
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Working with Tables
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { Document } from 'docxmlater';
|
|
107
|
+
|
|
108
|
+
const doc = Document.create();
|
|
109
|
+
|
|
110
|
+
// Create a 3x4 table
|
|
111
|
+
const table = doc.createTable(3, 4);
|
|
112
|
+
|
|
113
|
+
// Set header row
|
|
114
|
+
const headerRow = table.getRow(0);
|
|
115
|
+
headerRow.getCell(0).addParagraph().addText('Column 1', { bold: true });
|
|
116
|
+
headerRow.getCell(1).addParagraph().addText('Column 2', { bold: true });
|
|
117
|
+
headerRow.getCell(2).addParagraph().addText('Column 3', { bold: true });
|
|
118
|
+
headerRow.getCell(3).addParagraph().addText('Column 4', { bold: true });
|
|
119
|
+
|
|
120
|
+
// Add data
|
|
121
|
+
table.getRow(1).getCell(0).addParagraph().addText('Data 1');
|
|
122
|
+
table.getRow(1).getCell(1).addParagraph().addText('Data 2');
|
|
123
|
+
|
|
124
|
+
// Apply borders
|
|
125
|
+
table.setBorders({
|
|
126
|
+
top: { style: 'single', size: 4, color: '000000' },
|
|
127
|
+
bottom: { style: 'single', size: 4, color: '000000' },
|
|
128
|
+
left: { style: 'single', size: 4, color: '000000' },
|
|
129
|
+
right: { style: 'single', size: 4, color: '000000' },
|
|
130
|
+
insideH: { style: 'single', size: 4, color: '000000' },
|
|
131
|
+
insideV: { style: 'single', size: 4, color: '000000' }
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
await doc.save('table.docx');
|
|
135
|
+
doc.dispose();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Adding Images
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { Document } from 'docxmlater';
|
|
142
|
+
import { readFileSync } from 'fs';
|
|
143
|
+
|
|
144
|
+
const doc = Document.create();
|
|
145
|
+
|
|
146
|
+
// Load image from file
|
|
147
|
+
const imageBuffer = readFileSync('photo.jpg');
|
|
148
|
+
|
|
149
|
+
// Add image to document
|
|
150
|
+
const para = doc.createParagraph();
|
|
151
|
+
await para.addImage(imageBuffer, {
|
|
152
|
+
width: 400,
|
|
153
|
+
height: 300,
|
|
154
|
+
format: 'jpg'
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
await doc.save('with-image.docx');
|
|
158
|
+
doc.dispose();
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Hyperlink Management
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { Document } from 'docxmlater';
|
|
165
|
+
|
|
166
|
+
const doc = await Document.load('document.docx');
|
|
167
|
+
|
|
168
|
+
// Get all hyperlinks
|
|
169
|
+
const hyperlinks = doc.getHyperlinks();
|
|
170
|
+
console.log(`Found ${hyperlinks.length} hyperlinks`);
|
|
171
|
+
|
|
172
|
+
// Update URLs in batch (30-50% faster than manual iteration)
|
|
173
|
+
doc.updateHyperlinkUrls('http://old-domain.com', 'https://new-domain.com');
|
|
174
|
+
|
|
175
|
+
// Fix fragmented hyperlinks from Google Docs
|
|
176
|
+
const mergedCount = doc.defragmentHyperlinks({
|
|
177
|
+
resetFormatting: true // Fix corrupted fonts
|
|
178
|
+
});
|
|
179
|
+
console.log(`Merged ${mergedCount} fragmented hyperlinks`);
|
|
180
|
+
|
|
181
|
+
await doc.save('updated.docx');
|
|
182
|
+
doc.dispose();
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Custom Styles
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { Document, Style } from 'docxmlater';
|
|
189
|
+
|
|
190
|
+
const doc = Document.create();
|
|
191
|
+
|
|
192
|
+
// Create custom paragraph style
|
|
193
|
+
const customStyle = new Style('CustomHeading', 'paragraph');
|
|
194
|
+
customStyle.setName('Custom Heading');
|
|
195
|
+
customStyle.setRunFormatting({
|
|
196
|
+
bold: true,
|
|
197
|
+
fontSize: 32,
|
|
198
|
+
color: '0070C0'
|
|
199
|
+
});
|
|
200
|
+
customStyle.setParagraphFormatting({
|
|
201
|
+
alignment: 'center',
|
|
202
|
+
spacingAfter: 240
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// Add style to document
|
|
206
|
+
doc.getStylesManager().addStyle(customStyle);
|
|
207
|
+
|
|
208
|
+
// Apply style to paragraph
|
|
209
|
+
const para = doc.createParagraph();
|
|
210
|
+
para.addText('Styled Heading');
|
|
211
|
+
para.applyStyle('CustomHeading');
|
|
212
|
+
|
|
213
|
+
await doc.save('styled.docx');
|
|
214
|
+
doc.dispose();
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## API Overview
|
|
218
|
+
|
|
219
|
+
### Document Class
|
|
220
|
+
|
|
221
|
+
**Creation & Loading:**
|
|
222
|
+
- `Document.create(options?)` - Create new document
|
|
223
|
+
- `Document.load(filepath)` - Load from file
|
|
224
|
+
- `Document.loadFromBuffer(buffer)` - Load from memory
|
|
225
|
+
|
|
226
|
+
**Content Management:**
|
|
227
|
+
- `createParagraph()` - Add paragraph
|
|
228
|
+
- `createTable(rows, cols)` - Add table
|
|
229
|
+
- `createSection()` - Add section
|
|
230
|
+
- `getBodyElements()` - Get all body content
|
|
231
|
+
|
|
232
|
+
**Search & Replace:**
|
|
233
|
+
- `findText(pattern)` - Find text matches
|
|
234
|
+
- `replaceText(pattern, replacement)` - Replace text
|
|
235
|
+
|
|
236
|
+
**Hyperlinks:**
|
|
237
|
+
- `getHyperlinks()` - Get all hyperlinks
|
|
238
|
+
- `updateHyperlinkUrls(oldUrl, newUrl)` - Batch URL update
|
|
239
|
+
- `defragmentHyperlinks(options?)` - Fix fragmented links
|
|
240
|
+
|
|
241
|
+
**Statistics:**
|
|
242
|
+
- `getWordCount()` - Count words
|
|
243
|
+
- `getCharacterCount(includeSpaces?)` - Count characters
|
|
244
|
+
- `estimateSize()` - Estimate file size
|
|
245
|
+
|
|
246
|
+
**Saving:**
|
|
247
|
+
- `save(filepath)` - Save to file
|
|
248
|
+
- `toBuffer()` - Save to Buffer
|
|
249
|
+
- `dispose()` - Free resources (important!)
|
|
250
|
+
|
|
251
|
+
### Paragraph Class
|
|
252
|
+
|
|
253
|
+
**Content:**
|
|
254
|
+
- `addText(text, formatting?)` - Add text run
|
|
255
|
+
- `addRun(run)` - Add custom run
|
|
256
|
+
- `addHyperlink(hyperlink)` - Add hyperlink
|
|
257
|
+
- `addImage(buffer, options)` - Add image
|
|
258
|
+
|
|
259
|
+
**Formatting:**
|
|
260
|
+
- `setAlignment(alignment)` - Left, center, right, justify
|
|
261
|
+
- `setIndentation(options)` - First line, hanging, left, right
|
|
262
|
+
- `setSpacing(options)` - Line spacing, before/after
|
|
263
|
+
- `setBorders(borders)` - Paragraph borders
|
|
264
|
+
- `setShading(shading)` - Background color
|
|
265
|
+
- `applyStyle(styleId)` - Apply paragraph style
|
|
266
|
+
|
|
267
|
+
**Properties:**
|
|
268
|
+
- `setKeepNext(value)` - Keep with next paragraph
|
|
269
|
+
- `setKeepLines(value)` - Keep lines together
|
|
270
|
+
- `setPageBreakBefore(value)` - Page break before
|
|
271
|
+
|
|
272
|
+
**Numbering:**
|
|
273
|
+
- `setNumbering(numId, level)` - Apply list numbering
|
|
274
|
+
|
|
275
|
+
### Run Class
|
|
276
|
+
|
|
277
|
+
**Text:**
|
|
278
|
+
- `setText(text)` - Set run text
|
|
279
|
+
- `getText()` - Get run text
|
|
280
|
+
|
|
281
|
+
**Character Formatting:**
|
|
282
|
+
- `setBold(value)` - Bold text
|
|
283
|
+
- `setItalic(value)` - Italic text
|
|
284
|
+
- `setUnderline(style?)` - Underline
|
|
285
|
+
- `setStrikethrough(value)` - Strikethrough
|
|
286
|
+
- `setFont(name)` - Font family
|
|
287
|
+
- `setFontSize(size)` - Font size in points
|
|
288
|
+
- `setColor(color)` - Text color (hex)
|
|
289
|
+
- `setHighlight(color)` - Highlight color
|
|
290
|
+
|
|
291
|
+
**Advanced:**
|
|
292
|
+
- `setSubscript(value)` - Subscript
|
|
293
|
+
- `setSuperscript(value)` - Superscript
|
|
294
|
+
- `setSmallCaps(value)` - Small capitals
|
|
295
|
+
- `setAllCaps(value)` - All capitals
|
|
296
|
+
|
|
297
|
+
### Table Class
|
|
298
|
+
|
|
299
|
+
**Structure:**
|
|
300
|
+
- `addRow()` - Add row
|
|
301
|
+
- `getRow(index)` - Get row by index
|
|
302
|
+
- `getCell(row, col)` - Get specific cell
|
|
303
|
+
|
|
304
|
+
**Formatting:**
|
|
305
|
+
- `setBorders(borders)` - Table borders
|
|
306
|
+
- `setAlignment(alignment)` - Table alignment
|
|
307
|
+
- `setWidth(width)` - Table width
|
|
308
|
+
- `setLayout(layout)` - Fixed or auto layout
|
|
309
|
+
|
|
310
|
+
**Style:**
|
|
311
|
+
- `applyStyle(styleId)` - Apply table style
|
|
312
|
+
|
|
313
|
+
### TableCell Class
|
|
314
|
+
|
|
315
|
+
**Content:**
|
|
316
|
+
- `addParagraph()` - Add paragraph to cell
|
|
317
|
+
- `getParagraphs()` - Get all paragraphs
|
|
318
|
+
|
|
319
|
+
**Formatting:**
|
|
320
|
+
- `setBorders(borders)` - Cell borders
|
|
321
|
+
- `setShading(color)` - Cell background
|
|
322
|
+
- `setVerticalAlignment(alignment)` - Top, center, bottom
|
|
323
|
+
- `setWidth(width)` - Cell width
|
|
324
|
+
|
|
325
|
+
**Spanning:**
|
|
326
|
+
- `setHorizontalMerge(mergeType)` - Horizontal merge
|
|
327
|
+
- `setVerticalMerge(mergeType)` - Vertical merge
|
|
328
|
+
|
|
329
|
+
### Utilities
|
|
330
|
+
|
|
331
|
+
**Unit Conversions:**
|
|
332
|
+
```typescript
|
|
333
|
+
import { twipsToPoints, inchesToTwips, emusToPixels } from 'docxmlater';
|
|
334
|
+
|
|
335
|
+
const points = twipsToPoints(240); // 240 twips = 12 points
|
|
336
|
+
const twips = inchesToTwips(1); // 1 inch = 1440 twips
|
|
337
|
+
const pixels = emusToPixels(914400, 96); // 914400 EMUs = 96 pixels at 96 DPI
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**Validation:**
|
|
341
|
+
```typescript
|
|
342
|
+
import { validateRunText, detectXmlInText, cleanXmlFromText } from 'docxmlater';
|
|
343
|
+
|
|
344
|
+
// Detect XML patterns in text
|
|
345
|
+
const result = validateRunText('Some <w:t>text</w:t>');
|
|
346
|
+
if (result.hasXml) {
|
|
347
|
+
console.warn(result.message);
|
|
348
|
+
const cleaned = cleanXmlFromText(result.text);
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
**Corruption Detection:**
|
|
353
|
+
```typescript
|
|
354
|
+
import { detectCorruptionInDocument } from 'docxmlater';
|
|
355
|
+
|
|
356
|
+
const doc = await Document.load('suspect.docx');
|
|
357
|
+
const report = detectCorruptionInDocument(doc);
|
|
358
|
+
|
|
359
|
+
if (report.isCorrupted) {
|
|
360
|
+
console.log(`Found ${report.locations.length} corruption issues`);
|
|
361
|
+
report.locations.forEach(loc => {
|
|
362
|
+
console.log(`Line ${loc.lineNumber}: ${loc.issue}`);
|
|
363
|
+
console.log(`Suggested fix: ${loc.suggestedFix}`);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
## TypeScript Support
|
|
369
|
+
|
|
370
|
+
Full TypeScript definitions included:
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
import {
|
|
374
|
+
Document,
|
|
375
|
+
Paragraph,
|
|
376
|
+
Run,
|
|
377
|
+
Table,
|
|
378
|
+
RunFormatting,
|
|
379
|
+
ParagraphFormatting,
|
|
380
|
+
DocumentProperties
|
|
381
|
+
} from 'docxmlater';
|
|
382
|
+
|
|
383
|
+
// Type-safe formatting
|
|
384
|
+
const formatting: RunFormatting = {
|
|
385
|
+
bold: true,
|
|
386
|
+
fontSize: 12,
|
|
387
|
+
color: 'FF0000'
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// Type-safe document properties
|
|
391
|
+
const properties: DocumentProperties = {
|
|
392
|
+
title: 'My Document',
|
|
393
|
+
author: 'John Doe',
|
|
394
|
+
created: new Date()
|
|
395
|
+
};
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
## Version History
|
|
399
|
+
|
|
400
|
+
**Current Version: 1.16.0**
|
|
401
|
+
|
|
402
|
+
See [CHANGELOG.md](CHANGELOG.md) for detailed version history.
|
|
403
|
+
|
|
404
|
+
## RAG-CLI Integration (Development Only)
|
|
405
|
+
|
|
406
|
+
This project includes MCP (Model Context Protocol) configuration to allow Claude Code to access docXMLater documentation from Documentation_Hub during development.
|
|
407
|
+
|
|
408
|
+
**Note:** RAG-CLI uses `python-docx` for DOCX indexing, not docXMLater. These are complementary tools:
|
|
409
|
+
- **RAG-CLI**: Index DOCX files for search/retrieval (read-only)
|
|
410
|
+
- **docXMLater**: Create, modify, format DOCX files (read-write)
|
|
411
|
+
|
|
412
|
+
The `.mcp.json` configuration is for development assistance only and does not represent a runtime integration between the two projects.
|
|
413
|
+
|
|
414
|
+
## Testing
|
|
415
|
+
|
|
416
|
+
The framework includes comprehensive test coverage:
|
|
417
|
+
|
|
418
|
+
- **2073+ test cases** across 59 test files
|
|
419
|
+
- Tests cover all phases of implementation
|
|
420
|
+
- Integration tests for complex scenarios
|
|
421
|
+
- Performance benchmarks
|
|
422
|
+
- Edge case validation
|
|
423
|
+
|
|
424
|
+
Run tests:
|
|
425
|
+
|
|
426
|
+
```bash
|
|
427
|
+
npm test # Run all tests
|
|
428
|
+
npm run test:watch # Watch mode
|
|
429
|
+
npm run test:coverage # Coverage report
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
## Performance Considerations
|
|
433
|
+
|
|
434
|
+
- Use `dispose()` to free resources after document operations
|
|
435
|
+
- Buffer-based operations are faster than file I/O
|
|
436
|
+
- Batch hyperlink updates are 30-50% faster than manual iteration
|
|
437
|
+
- Large documents (1000+ pages) supported with memory management
|
|
438
|
+
- Streaming support for very large files
|
|
439
|
+
|
|
440
|
+
## Architecture
|
|
441
|
+
|
|
442
|
+
The framework follows a modular architecture:
|
|
443
|
+
|
|
444
|
+
```
|
|
445
|
+
src/
|
|
446
|
+
├── core/ # Document, Parser, Generator, Validator
|
|
447
|
+
├── elements/ # Paragraph, Run, Table, Image, etc.
|
|
448
|
+
├── formatting/ # Style, Numbering managers
|
|
449
|
+
├── managers/ # Drawing, Image, Relationship managers
|
|
450
|
+
├── xml/ # XML generation and parsing
|
|
451
|
+
├── zip/ # ZIP archive handling
|
|
452
|
+
└── utils/ # Validation, units, error handling
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
Key design principles:
|
|
456
|
+
- KISS (Keep It Simple, Stupid) - no over-engineering
|
|
457
|
+
- Position-based XML parsing (ReDoS-safe)
|
|
458
|
+
- Defensive programming with comprehensive validation
|
|
459
|
+
- Memory-efficient with explicit disposal pattern
|
|
460
|
+
- Full ECMA-376 (OpenXML) compliance
|
|
461
|
+
|
|
462
|
+
## Requirements
|
|
463
|
+
|
|
464
|
+
- Node.js 18.0.0 or higher
|
|
465
|
+
- TypeScript 5.0+ (for development)
|
|
466
|
+
|
|
467
|
+
## Dependencies
|
|
468
|
+
|
|
469
|
+
- `jszip` - ZIP archive handling
|
|
470
|
+
|
|
471
|
+
## License
|
|
472
|
+
|
|
473
|
+
MIT
|
|
474
|
+
|
|
475
|
+
## Contributing
|
|
476
|
+
|
|
477
|
+
Contributions welcome! Please:
|
|
478
|
+
1. Fork the repository
|
|
479
|
+
2. Create a feature branch
|
|
480
|
+
3. Add tests for new features
|
|
481
|
+
4. Ensure all tests pass
|
|
482
|
+
5. Submit a pull request
|
|
483
|
+
|
|
484
|
+
## Support
|
|
485
|
+
|
|
486
|
+
- GitHub Issues: https://github.com/ItMeDiaTech/docXMLater/issues
|
|
487
|
+
- Documentation: See CLAUDE.md for detailed implementation notes
|
|
488
|
+
|
|
489
|
+
## Acknowledgments
|
|
490
|
+
|
|
491
|
+
Built with careful attention to the ECMA-376 Office Open XML specification. Special thanks to the OpenXML community for comprehensive documentation and examples.
|