docxmlater 10.1.3 → 10.1.5
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 +759 -754
- package/dist/constants/legacyCompatFlags.js +1 -1
- package/dist/constants/legacyCompatFlags.js.map +1 -1
- package/dist/constants/limits.js.map +1 -1
- package/dist/core/Document.d.ts +50 -50
- package/dist/core/Document.d.ts.map +1 -1
- package/dist/core/Document.js +483 -471
- package/dist/core/Document.js.map +1 -1
- package/dist/core/DocumentContent.d.ts +9 -9
- package/dist/core/DocumentContent.d.ts.map +1 -1
- package/dist/core/DocumentContent.js +1 -1
- package/dist/core/DocumentContent.js.map +1 -1
- package/dist/core/DocumentGenerator.d.ts +11 -11
- package/dist/core/DocumentGenerator.d.ts.map +1 -1
- package/dist/core/DocumentGenerator.js +251 -251
- package/dist/core/DocumentGenerator.js.map +1 -1
- package/dist/core/DocumentIdManager.js.map +1 -1
- package/dist/core/DocumentParser.d.ts +15 -15
- package/dist/core/DocumentParser.d.ts.map +1 -1
- package/dist/core/DocumentParser.js +2123 -2155
- package/dist/core/DocumentParser.js.map +1 -1
- package/dist/core/DocumentValidator.d.ts.map +1 -1
- package/dist/core/DocumentValidator.js +2 -5
- package/dist/core/DocumentValidator.js.map +1 -1
- package/dist/core/Relationship.js.map +1 -1
- package/dist/core/RelationshipManager.d.ts.map +1 -1
- package/dist/core/RelationshipManager.js +3 -3
- package/dist/core/RelationshipManager.js.map +1 -1
- package/dist/elements/AlternateContent.js.map +1 -1
- package/dist/elements/Bookmark.d.ts.map +1 -1
- package/dist/elements/Bookmark.js +3 -1
- package/dist/elements/Bookmark.js.map +1 -1
- package/dist/elements/BookmarkManager.d.ts.map +1 -1
- package/dist/elements/BookmarkManager.js.map +1 -1
- package/dist/elements/Comment.d.ts.map +1 -1
- package/dist/elements/Comment.js +9 -6
- package/dist/elements/Comment.js.map +1 -1
- package/dist/elements/CommentManager.d.ts.map +1 -1
- package/dist/elements/CommentManager.js +18 -17
- package/dist/elements/CommentManager.js.map +1 -1
- package/dist/elements/CommonTypes.d.ts +21 -21
- package/dist/elements/CommonTypes.d.ts.map +1 -1
- package/dist/elements/CommonTypes.js +56 -56
- package/dist/elements/CommonTypes.js.map +1 -1
- package/dist/elements/CustomXml.js.map +1 -1
- package/dist/elements/Endnote.d.ts.map +1 -1
- package/dist/elements/Endnote.js +6 -6
- package/dist/elements/Endnote.js.map +1 -1
- package/dist/elements/EndnoteManager.d.ts.map +1 -1
- package/dist/elements/EndnoteManager.js +6 -7
- package/dist/elements/EndnoteManager.js.map +1 -1
- package/dist/elements/Field.d.ts.map +1 -1
- package/dist/elements/Field.js +82 -25
- package/dist/elements/Field.js.map +1 -1
- package/dist/elements/FieldHelpers.d.ts.map +1 -1
- package/dist/elements/FieldHelpers.js.map +1 -1
- package/dist/elements/FontManager.d.ts.map +1 -1
- package/dist/elements/FontManager.js +1 -1
- package/dist/elements/FontManager.js.map +1 -1
- package/dist/elements/Footer.js +2 -2
- package/dist/elements/Footer.js.map +1 -1
- package/dist/elements/Footnote.d.ts.map +1 -1
- package/dist/elements/Footnote.js +6 -6
- package/dist/elements/Footnote.js.map +1 -1
- package/dist/elements/FootnoteManager.d.ts.map +1 -1
- package/dist/elements/FootnoteManager.js +6 -7
- package/dist/elements/FootnoteManager.js.map +1 -1
- package/dist/elements/Header.js +2 -2
- package/dist/elements/Header.js.map +1 -1
- package/dist/elements/HeaderFooterManager.js.map +1 -1
- package/dist/elements/Hyperlink.d.ts +5 -3
- package/dist/elements/Hyperlink.d.ts.map +1 -1
- package/dist/elements/Hyperlink.js +134 -76
- package/dist/elements/Hyperlink.js.map +1 -1
- package/dist/elements/Image.d.ts.map +1 -1
- package/dist/elements/Image.js +238 -106
- package/dist/elements/Image.js.map +1 -1
- package/dist/elements/ImageManager.d.ts.map +1 -1
- package/dist/elements/ImageManager.js +1 -1
- package/dist/elements/ImageManager.js.map +1 -1
- package/dist/elements/ImageRun.js +1 -1
- package/dist/elements/ImageRun.js.map +1 -1
- package/dist/elements/MathElement.js.map +1 -1
- package/dist/elements/Paragraph.d.ts +24 -24
- package/dist/elements/Paragraph.d.ts.map +1 -1
- package/dist/elements/Paragraph.js +181 -188
- package/dist/elements/Paragraph.js.map +1 -1
- package/dist/elements/PreservedElement.js.map +1 -1
- package/dist/elements/PropertyChangeTypes.d.ts.map +1 -1
- package/dist/elements/PropertyChangeTypes.js +6 -6
- package/dist/elements/PropertyChangeTypes.js.map +1 -1
- package/dist/elements/RangeMarker.d.ts.map +1 -1
- package/dist/elements/RangeMarker.js.map +1 -1
- package/dist/elements/Revision.d.ts.map +1 -1
- package/dist/elements/Revision.js +4 -5
- package/dist/elements/Revision.js.map +1 -1
- package/dist/elements/RevisionContent.js.map +1 -1
- package/dist/elements/RevisionManager.d.ts.map +1 -1
- package/dist/elements/RevisionManager.js +40 -48
- package/dist/elements/RevisionManager.js.map +1 -1
- package/dist/elements/Run.d.ts +16 -16
- package/dist/elements/Run.d.ts.map +1 -1
- package/dist/elements/Run.js +256 -238
- package/dist/elements/Run.js.map +1 -1
- package/dist/elements/Section.d.ts.map +1 -1
- package/dist/elements/Section.js +36 -11
- package/dist/elements/Section.js.map +1 -1
- package/dist/elements/Shape.d.ts.map +1 -1
- package/dist/elements/Shape.js.map +1 -1
- package/dist/elements/StructuredDocumentTag.d.ts +6 -6
- package/dist/elements/StructuredDocumentTag.d.ts.map +1 -1
- package/dist/elements/StructuredDocumentTag.js +99 -104
- package/dist/elements/StructuredDocumentTag.js.map +1 -1
- package/dist/elements/Table.d.ts +11 -11
- package/dist/elements/Table.d.ts.map +1 -1
- package/dist/elements/Table.js +102 -107
- package/dist/elements/Table.js.map +1 -1
- package/dist/elements/TableCell.d.ts +10 -10
- package/dist/elements/TableCell.d.ts.map +1 -1
- package/dist/elements/TableCell.js +105 -106
- package/dist/elements/TableCell.js.map +1 -1
- package/dist/elements/TableGridChange.d.ts.map +1 -1
- package/dist/elements/TableGridChange.js.map +1 -1
- package/dist/elements/TableOfContents.d.ts.map +1 -1
- package/dist/elements/TableOfContents.js +4 -4
- package/dist/elements/TableOfContents.js.map +1 -1
- package/dist/elements/TableOfContentsElement.js.map +1 -1
- package/dist/elements/TableRow.d.ts.map +1 -1
- package/dist/elements/TableRow.js +13 -6
- package/dist/elements/TableRow.js.map +1 -1
- package/dist/elements/TextBox.d.ts.map +1 -1
- package/dist/elements/TextBox.js +3 -5
- package/dist/elements/TextBox.js.map +1 -1
- package/dist/formatting/AbstractNumbering.d.ts +4 -4
- package/dist/formatting/AbstractNumbering.d.ts.map +1 -1
- package/dist/formatting/AbstractNumbering.js +54 -49
- package/dist/formatting/AbstractNumbering.js.map +1 -1
- package/dist/formatting/NumberingInstance.d.ts.map +1 -1
- package/dist/formatting/NumberingInstance.js +1 -3
- package/dist/formatting/NumberingInstance.js.map +1 -1
- package/dist/formatting/NumberingLevel.d.ts +5 -5
- package/dist/formatting/NumberingLevel.d.ts.map +1 -1
- package/dist/formatting/NumberingLevel.js +119 -125
- package/dist/formatting/NumberingLevel.js.map +1 -1
- package/dist/formatting/NumberingManager.d.ts.map +1 -1
- package/dist/formatting/NumberingManager.js +9 -9
- package/dist/formatting/NumberingManager.js.map +1 -1
- package/dist/formatting/Style.d.ts +11 -11
- package/dist/formatting/Style.d.ts.map +1 -1
- package/dist/formatting/Style.js +219 -247
- package/dist/formatting/Style.js.map +1 -1
- package/dist/formatting/StylesManager.d.ts +2 -2
- package/dist/formatting/StylesManager.d.ts.map +1 -1
- package/dist/formatting/StylesManager.js +96 -102
- package/dist/formatting/StylesManager.js.map +1 -1
- package/dist/helpers/CleanupHelper.d.ts +1 -1
- package/dist/helpers/CleanupHelper.d.ts.map +1 -1
- package/dist/helpers/CleanupHelper.js +6 -6
- package/dist/helpers/CleanupHelper.js.map +1 -1
- package/dist/images/ImageOptimizer.js +7 -7
- package/dist/images/ImageOptimizer.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/managers/DrawingManager.js.map +1 -1
- package/dist/tracking/DocumentTrackingContext.d.ts.map +1 -1
- package/dist/tracking/DocumentTrackingContext.js +23 -7
- package/dist/tracking/DocumentTrackingContext.js.map +1 -1
- package/dist/tracking/TrackingContext.d.ts.map +1 -1
- package/dist/tracking/TrackingContext.js.map +1 -1
- package/dist/types/compatibility-types.js.map +1 -1
- package/dist/types/formatting.js.map +1 -1
- package/dist/types/list-types.d.ts +6 -6
- package/dist/types/list-types.js.map +1 -1
- package/dist/types/settings-types.js.map +1 -1
- package/dist/types/styleConfig.d.ts +2 -2
- package/dist/types/styleConfig.js.map +1 -1
- package/dist/utils/ChangelogGenerator.d.ts.map +1 -1
- package/dist/utils/ChangelogGenerator.js +97 -101
- package/dist/utils/ChangelogGenerator.js.map +1 -1
- package/dist/utils/CompatibilityUpgrader.d.ts.map +1 -1
- package/dist/utils/CompatibilityUpgrader.js +1 -1
- package/dist/utils/CompatibilityUpgrader.js.map +1 -1
- package/dist/utils/InMemoryRevisionAcceptor.d.ts.map +1 -1
- package/dist/utils/InMemoryRevisionAcceptor.js +1 -6
- package/dist/utils/InMemoryRevisionAcceptor.js.map +1 -1
- package/dist/utils/MoveOperationHelper.d.ts.map +1 -1
- package/dist/utils/MoveOperationHelper.js +1 -1
- package/dist/utils/MoveOperationHelper.js.map +1 -1
- package/dist/utils/RevisionAwareProcessor.d.ts.map +1 -1
- package/dist/utils/RevisionAwareProcessor.js +2 -4
- package/dist/utils/RevisionAwareProcessor.js.map +1 -1
- package/dist/utils/RevisionWalker.d.ts.map +1 -1
- package/dist/utils/RevisionWalker.js +4 -12
- package/dist/utils/RevisionWalker.js.map +1 -1
- package/dist/utils/SelectiveRevisionAcceptor.d.ts.map +1 -1
- package/dist/utils/SelectiveRevisionAcceptor.js +2 -6
- package/dist/utils/SelectiveRevisionAcceptor.js.map +1 -1
- package/dist/utils/ShadingResolver.d.ts.map +1 -1
- package/dist/utils/ShadingResolver.js +1 -1
- package/dist/utils/ShadingResolver.js.map +1 -1
- package/dist/utils/acceptRevisions.d.ts.map +1 -1
- package/dist/utils/acceptRevisions.js +23 -12
- package/dist/utils/acceptRevisions.js.map +1 -1
- package/dist/utils/cnfStyleDecoder.d.ts +1 -1
- package/dist/utils/cnfStyleDecoder.d.ts.map +1 -1
- package/dist/utils/cnfStyleDecoder.js +40 -40
- package/dist/utils/cnfStyleDecoder.js.map +1 -1
- package/dist/utils/corruptionDetection.d.ts.map +1 -1
- package/dist/utils/corruptionDetection.js.map +1 -1
- package/dist/utils/dateFormatting.js.map +1 -1
- package/dist/utils/deepClone.js +1 -1
- package/dist/utils/deepClone.js.map +1 -1
- package/dist/utils/diagnostics.d.ts.map +1 -1
- package/dist/utils/diagnostics.js +1 -1
- package/dist/utils/diagnostics.js.map +1 -1
- package/dist/utils/errorHandling.js.map +1 -1
- package/dist/utils/formatting.d.ts.map +1 -1
- package/dist/utils/formatting.js +10 -2
- package/dist/utils/formatting.js.map +1 -1
- package/dist/utils/list-detection.d.ts +2 -2
- package/dist/utils/list-detection.d.ts.map +1 -1
- package/dist/utils/list-detection.js +21 -23
- package/dist/utils/list-detection.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +12 -7
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/parsingHelpers.js.map +1 -1
- package/dist/utils/stripTrackedChanges.d.ts.map +1 -1
- package/dist/utils/stripTrackedChanges.js +3 -3
- package/dist/utils/stripTrackedChanges.js.map +1 -1
- package/dist/utils/textDiff.d.ts +1 -1
- package/dist/utils/textDiff.js +8 -8
- package/dist/utils/textDiff.js.map +1 -1
- package/dist/utils/units.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +24 -7
- package/dist/utils/validation.js.map +1 -1
- package/dist/utils/xmlSanitization.d.ts.map +1 -1
- package/dist/utils/xmlSanitization.js +3 -3
- package/dist/utils/xmlSanitization.js.map +1 -1
- package/dist/validation/RevisionAutoFixer.d.ts.map +1 -1
- package/dist/validation/RevisionAutoFixer.js +5 -5
- package/dist/validation/RevisionAutoFixer.js.map +1 -1
- package/dist/validation/RevisionValidator.d.ts.map +1 -1
- package/dist/validation/RevisionValidator.js +7 -9
- package/dist/validation/RevisionValidator.js.map +1 -1
- package/dist/validation/ValidationRules.js +3 -3
- package/dist/validation/ValidationRules.js.map +1 -1
- package/dist/validation/index.js.map +1 -1
- package/dist/xml/XMLBuilder.d.ts +1 -1
- package/dist/xml/XMLBuilder.d.ts.map +1 -1
- package/dist/xml/XMLBuilder.js +98 -100
- package/dist/xml/XMLBuilder.js.map +1 -1
- package/dist/xml/XMLParser.d.ts.map +1 -1
- package/dist/xml/XMLParser.js +61 -66
- package/dist/xml/XMLParser.js.map +1 -1
- package/dist/zip/ZipHandler.d.ts.map +1 -1
- package/dist/zip/ZipHandler.js.map +1 -1
- package/dist/zip/ZipReader.d.ts.map +1 -1
- package/dist/zip/ZipReader.js +1 -3
- package/dist/zip/ZipReader.js.map +1 -1
- package/dist/zip/ZipWriter.d.ts +1 -1
- package/dist/zip/ZipWriter.d.ts.map +1 -1
- package/dist/zip/ZipWriter.js +28 -36
- package/dist/zip/ZipWriter.js.map +1 -1
- package/dist/zip/types.js +1 -1
- package/dist/zip/types.js.map +1 -1
- package/package.json +92 -92
- package/src/__tests__/helper-methods.test.ts +512 -512
- package/src/constants/legacyCompatFlags.ts +138 -138
- package/src/constants/limits.ts +50 -50
- package/src/core/Document.ts +985 -1145
- package/src/core/DocumentContent.ts +461 -467
- package/src/core/DocumentGenerator.ts +1133 -1104
- package/src/core/DocumentIdManager.ts +158 -158
- package/src/core/DocumentParser.ts +2347 -2716
- package/src/core/DocumentValidator.ts +363 -372
- package/src/core/Relationship.ts +367 -367
- package/src/core/RelationshipManager.ts +429 -428
- package/src/elements/AlternateContent.ts +42 -42
- package/src/elements/Bookmark.ts +212 -210
- package/src/elements/BookmarkManager.ts +247 -250
- package/src/elements/Comment.ts +356 -359
- package/src/elements/CommentManager.ts +499 -502
- package/src/elements/CommonTypes.ts +524 -549
- package/src/elements/CustomXml.ts +36 -36
- package/src/elements/Endnote.ts +221 -217
- package/src/elements/EndnoteManager.ts +246 -249
- package/src/elements/Field.ts +1292 -1233
- package/src/elements/FieldHelpers.ts +329 -333
- package/src/elements/FontManager.ts +336 -339
- package/src/elements/Footer.ts +269 -269
- package/src/elements/Footnote.ts +221 -217
- package/src/elements/FootnoteManager.ts +246 -249
- package/src/elements/Header.ts +269 -269
- package/src/elements/HeaderFooterManager.ts +219 -219
- package/src/elements/Hyperlink.ts +1288 -1193
- package/src/elements/Image.ts +1982 -1756
- package/src/elements/ImageManager.ts +437 -432
- package/src/elements/ImageRun.ts +59 -59
- package/src/elements/MathElement.ts +65 -65
- package/src/elements/Paragraph.ts +4347 -4287
- package/src/elements/PreservedElement.ts +53 -53
- package/src/elements/PropertyChangeTypes.ts +458 -442
- package/src/elements/RangeMarker.ts +382 -400
- package/src/elements/Revision.ts +1198 -1217
- package/src/elements/RevisionContent.ts +73 -73
- package/src/elements/RevisionManager.ts +1070 -1070
- package/src/elements/Run.ts +3103 -3073
- package/src/elements/Section.ts +1521 -1421
- package/src/elements/Shape.ts +884 -873
- package/src/elements/StructuredDocumentTag.ts +1176 -1207
- package/src/elements/Table.ts +2468 -2524
- package/src/elements/TableCell.ts +1617 -1621
- package/src/elements/TableGridChange.ts +149 -151
- package/src/elements/TableOfContents.ts +701 -691
- package/src/elements/TableOfContentsElement.ts +89 -89
- package/src/elements/TableRow.ts +960 -929
- package/src/elements/TextBox.ts +766 -768
- package/src/formatting/AbstractNumbering.ts +580 -579
- package/src/formatting/NumberingInstance.ts +295 -299
- package/src/formatting/NumberingLevel.ts +981 -1040
- package/src/formatting/NumberingManager.ts +833 -827
- package/src/formatting/Style.ts +1785 -1879
- package/src/formatting/StylesManager.ts +1090 -1130
- package/src/helpers/CleanupHelper.ts +524 -524
- package/src/images/ImageOptimizer.ts +274 -274
- package/src/index.ts +559 -554
- package/src/managers/DrawingManager.ts +319 -319
- package/src/tracking/DocumentTrackingContext.ts +687 -674
- package/src/tracking/TrackingContext.ts +175 -173
- package/src/types/compatibility-types.ts +49 -49
- package/src/types/formatting.ts +210 -210
- package/src/types/list-types.ts +14 -14
- package/src/types/settings-types.ts +59 -59
- package/src/types/styleConfig.ts +189 -189
- package/src/utils/ChangelogGenerator.ts +1583 -1581
- package/src/utils/CompatibilityUpgrader.ts +235 -237
- package/src/utils/InMemoryRevisionAcceptor.ts +691 -696
- package/src/utils/MoveOperationHelper.ts +233 -238
- package/src/utils/RevisionAwareProcessor.ts +518 -526
- package/src/utils/RevisionWalker.ts +427 -457
- package/src/utils/SelectiveRevisionAcceptor.ts +662 -683
- package/src/utils/ShadingResolver.ts +105 -107
- package/src/utils/acceptRevisions.ts +723 -714
- package/src/utils/cnfStyleDecoder.ts +212 -217
- package/src/utils/corruptionDetection.ts +346 -345
- package/src/utils/dateFormatting.ts +20 -20
- package/src/utils/deepClone.ts +77 -78
- package/src/utils/diagnostics.ts +125 -129
- package/src/utils/errorHandling.ts +80 -80
- package/src/utils/formatting.ts +220 -213
- package/src/utils/list-detection.ts +32 -42
- package/src/utils/logger.ts +412 -404
- package/src/utils/parsingHelpers.ts +190 -190
- package/src/utils/stripTrackedChanges.ts +356 -353
- package/src/utils/textDiff.ts +100 -100
- package/src/utils/units.ts +421 -421
- package/src/utils/validation.ts +553 -542
- package/src/utils/xmlSanitization.ts +179 -182
- package/src/validation/RevisionAutoFixer.ts +541 -542
- package/src/validation/RevisionValidator.ts +470 -460
- package/src/validation/ValidationRules.ts +338 -338
- package/src/validation/index.ts +30 -30
- package/src/xml/XMLBuilder.ts +857 -871
- package/src/xml/XMLParser.ts +877 -919
- package/src/zip/ZipHandler.ts +629 -637
- package/src/zip/ZipReader.ts +295 -299
- package/src/zip/ZipWriter.ts +374 -390
- package/src/zip/types.ts +116 -116
package/README.md
CHANGED
|
@@ -1,754 +1,759 @@
|
|
|
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
|
-
|
|
9
|
-
- Create DOCX files from scratch
|
|
10
|
-
- Read and modify existing DOCX files
|
|
11
|
-
- Buffer-based operations (load/save from memory)
|
|
12
|
-
- Document properties (core, extended, custom)
|
|
13
|
-
- Memory management with dispose pattern
|
|
14
|
-
- Bookmark pair validation and auto-repair (`validateBookmarkPairs()`)
|
|
15
|
-
- App.xml metadata preservation (HeadingPairs, TotalTime, etc.)
|
|
16
|
-
- Document background color/theme support
|
|
17
|
-
|
|
18
|
-
### Text & Paragraph Formatting
|
|
19
|
-
|
|
20
|
-
- Character formatting: bold, italic, underline, strikethrough, subscript, superscript
|
|
21
|
-
- Font properties: family, size, color (RGB and theme colors), highlight
|
|
22
|
-
- Text effects: small caps, all caps, shadow, emboss, engrave
|
|
23
|
-
- Paragraph alignment, indentation, spacing, borders, shading
|
|
24
|
-
- Text search and replace with regex support
|
|
25
|
-
- Custom styles (paragraph, character, table)
|
|
26
|
-
- CJK/East Asian paragraph properties (kinsoku, wordWrap, overflowPunct, topLinePunct)
|
|
27
|
-
- Underline color and theme color attributes
|
|
28
|
-
- Theme font references (asciiTheme, hAnsiTheme, eastAsiaTheme, csTheme)
|
|
29
|
-
|
|
30
|
-
### Lists & Tables
|
|
31
|
-
|
|
32
|
-
- Numbered lists (decimal, roman, alpha)
|
|
33
|
-
- Bulleted lists with various bullet styles
|
|
34
|
-
- Multi-level lists with custom numbering
|
|
35
|
-
- Tables with formatting, borders, shading
|
|
36
|
-
- Cell spanning (merge cells horizontally and vertically)
|
|
37
|
-
- Advanced table properties (margins, widths, alignment)
|
|
38
|
-
- Table navigation helpers (`getFirstParagraph()`, `getLastParagraph()`)
|
|
39
|
-
- Legacy horizontal merge (`hMerge`) support
|
|
40
|
-
- Table layout parsing (`fixed`/`auto`)
|
|
41
|
-
- Table style shading updates (modify styles.xml colors)
|
|
42
|
-
- Cell content management (trailing blank removal with structure preservation)
|
|
43
|
-
|
|
44
|
-
### Rich Content
|
|
45
|
-
|
|
46
|
-
- Images (PNG, JPEG, GIF, SVG, EMF, WMF) with positioning, text wrapping, and full ECMA-376 DrawingML attribute coverage
|
|
47
|
-
- Headers & footers (different first page, odd/even pages)
|
|
48
|
-
- Hyperlinks (external URLs, internal bookmarks)
|
|
49
|
-
- Hyperlink defragmentation utility (fixes fragmented links from Google Docs)
|
|
50
|
-
- Bookmarks and cross-references
|
|
51
|
-
- Body-level bookmark support (bookmarks between block elements)
|
|
52
|
-
- Shapes and text boxes
|
|
53
|
-
|
|
54
|
-
### Advanced Features
|
|
55
|
-
|
|
56
|
-
- Track changes (revisions for insertions, deletions, formatting)
|
|
57
|
-
- Granular character-level tracked changes (text diff-based)
|
|
58
|
-
- Comments and annotations
|
|
59
|
-
- Compatibility mode detection and upgrade (Word 2003/2007/2010/2013+ modes)
|
|
60
|
-
- Table of contents generation with customizable heading levels and relative indentation
|
|
61
|
-
- Fields: merge fields, date/time, page numbers, TOC fields
|
|
62
|
-
- Footnotes and endnotes (full round-trip with save pipeline, parsing, and clear API)
|
|
63
|
-
- Content controls (Structured Document Tags)
|
|
64
|
-
- Form field data preservation (text input, checkbox, dropdown per ECMA-376 §17.16)
|
|
65
|
-
- w14 run effects passthrough (Word 2010+ ligatures, numForm, textOutline, etc.)
|
|
66
|
-
- Expanded document settings (evenAndOddHeaders, mirrorMargins, autoHyphenation, decimalSymbol)
|
|
67
|
-
- People.xml auto-registration for tracked changes authors
|
|
68
|
-
- Style default attribute preservation (`w:default="1"`)
|
|
69
|
-
- Namespace order preservation in generated XML
|
|
70
|
-
- Multiple sections with different page layouts
|
|
71
|
-
- Page orientation, size, and margins
|
|
72
|
-
- Preserved element round-trip (math equations, alternate content, custom XML)
|
|
73
|
-
- Unified shading model with theme color support and inheritance resolution
|
|
74
|
-
- Lossless image optimization (PNG re-compression, BMP-to-PNG conversion)
|
|
75
|
-
- Run property change tracking (w:rPrChange) with direct API access
|
|
76
|
-
- Paragraph mark revision tracking (w:del/w:ins in w:pPr/w:rPr) for full tracked-changes fidelity
|
|
77
|
-
- Normal/NormalWeb style linking with preservation flags
|
|
78
|
-
|
|
79
|
-
### Developer Tools
|
|
80
|
-
|
|
81
|
-
- Complete XML generation and parsing (ReDoS-safe, position-based parser)
|
|
82
|
-
- 40+ unit conversion functions (twips, EMUs, points, pixels, inches, cm)
|
|
83
|
-
- Validation utilities and corruption detection
|
|
84
|
-
- Text diff utility for character-level comparisons
|
|
85
|
-
- webSettings.xml auto-generation
|
|
86
|
-
- Safe OOXML parsing helpers (zero-value handling, boolean parsing)
|
|
87
|
-
- Full TypeScript support with comprehensive type definitions
|
|
88
|
-
- Error handling utilities
|
|
89
|
-
- Logging infrastructure with multiple log levels
|
|
90
|
-
|
|
91
|
-
## Installation
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
npm install docxmlater
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
## Quick Start
|
|
98
|
-
|
|
99
|
-
### Creating a New Document
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
import { Document } from
|
|
103
|
-
|
|
104
|
-
// Create a new document
|
|
105
|
-
const doc = Document.create();
|
|
106
|
-
|
|
107
|
-
// Add a paragraph
|
|
108
|
-
const para = doc.createParagraph();
|
|
109
|
-
para.addText(
|
|
110
|
-
|
|
111
|
-
// Save to file
|
|
112
|
-
await doc.save(
|
|
113
|
-
|
|
114
|
-
// Don't forget to dispose
|
|
115
|
-
doc.dispose();
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Loading and Modifying Documents
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
import { Document } from
|
|
122
|
-
|
|
123
|
-
// Load existing document
|
|
124
|
-
const doc = await Document.load(
|
|
125
|
-
|
|
126
|
-
// Find and replace text
|
|
127
|
-
doc.replaceText(/old text/g,
|
|
128
|
-
|
|
129
|
-
// Add a new paragraph
|
|
130
|
-
const para = doc.createParagraph();
|
|
131
|
-
para.addText(
|
|
132
|
-
|
|
133
|
-
// Save modifications
|
|
134
|
-
await doc.save(
|
|
135
|
-
doc.dispose();
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Working with Tables
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
import { Document } from
|
|
142
|
-
|
|
143
|
-
const doc = Document.create();
|
|
144
|
-
|
|
145
|
-
// Create a 3x4 table
|
|
146
|
-
const table = doc.createTable(3, 4);
|
|
147
|
-
|
|
148
|
-
// Set header row
|
|
149
|
-
const headerRow = table.getRow(0);
|
|
150
|
-
headerRow.getCell(0).addParagraph().addText(
|
|
151
|
-
headerRow.getCell(1).addParagraph().addText(
|
|
152
|
-
headerRow.getCell(2).addParagraph().addText(
|
|
153
|
-
headerRow.getCell(3).addParagraph().addText(
|
|
154
|
-
|
|
155
|
-
// Add data
|
|
156
|
-
table.getRow(1).getCell(0).addParagraph().addText(
|
|
157
|
-
table.getRow(1).getCell(1).addParagraph().addText(
|
|
158
|
-
|
|
159
|
-
// Apply borders
|
|
160
|
-
table.setBorders({
|
|
161
|
-
top: { style:
|
|
162
|
-
bottom: { style:
|
|
163
|
-
left: { style:
|
|
164
|
-
right: { style:
|
|
165
|
-
insideH: { style:
|
|
166
|
-
insideV: { style:
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
await doc.save(
|
|
170
|
-
doc.dispose();
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### Adding Images
|
|
174
|
-
|
|
175
|
-
```typescript
|
|
176
|
-
import { Document } from
|
|
177
|
-
import { readFileSync } from
|
|
178
|
-
|
|
179
|
-
const doc = Document.create();
|
|
180
|
-
|
|
181
|
-
// Load image from file
|
|
182
|
-
const imageBuffer = readFileSync(
|
|
183
|
-
|
|
184
|
-
// Add image to document
|
|
185
|
-
const para = doc.createParagraph();
|
|
186
|
-
await para.addImage(imageBuffer, {
|
|
187
|
-
width: 400,
|
|
188
|
-
height: 300,
|
|
189
|
-
format:
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
await doc.save(
|
|
193
|
-
doc.dispose();
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### Hyperlink Management
|
|
197
|
-
|
|
198
|
-
```typescript
|
|
199
|
-
import { Document } from
|
|
200
|
-
|
|
201
|
-
const doc = await Document.load(
|
|
202
|
-
|
|
203
|
-
// Get all hyperlinks
|
|
204
|
-
const hyperlinks = doc.getHyperlinks();
|
|
205
|
-
console.log(`Found ${hyperlinks.length} hyperlinks`);
|
|
206
|
-
|
|
207
|
-
// Update URLs in batch (30-50% faster than manual iteration)
|
|
208
|
-
doc.updateHyperlinkUrls(
|
|
209
|
-
|
|
210
|
-
// Fix fragmented hyperlinks from Google Docs
|
|
211
|
-
const mergedCount = doc.defragmentHyperlinks({
|
|
212
|
-
resetFormatting: true, // Fix corrupted fonts
|
|
213
|
-
});
|
|
214
|
-
console.log(`Merged ${mergedCount} fragmented hyperlinks`);
|
|
215
|
-
|
|
216
|
-
await doc.save(
|
|
217
|
-
doc.dispose();
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
### Custom Styles
|
|
221
|
-
|
|
222
|
-
```typescript
|
|
223
|
-
import { Document, Style } from
|
|
224
|
-
|
|
225
|
-
const doc = Document.create();
|
|
226
|
-
|
|
227
|
-
// Create custom paragraph style
|
|
228
|
-
const customStyle = new Style(
|
|
229
|
-
customStyle.setName(
|
|
230
|
-
customStyle.setRunFormatting({
|
|
231
|
-
bold: true,
|
|
232
|
-
fontSize: 32,
|
|
233
|
-
color:
|
|
234
|
-
});
|
|
235
|
-
customStyle.setParagraphFormatting({
|
|
236
|
-
alignment:
|
|
237
|
-
spacingAfter: 240,
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
// Add style to document
|
|
241
|
-
doc.getStylesManager().addStyle(customStyle);
|
|
242
|
-
|
|
243
|
-
// Apply style to paragraph
|
|
244
|
-
const para = doc.createParagraph();
|
|
245
|
-
para.addText(
|
|
246
|
-
para.applyStyle(
|
|
247
|
-
|
|
248
|
-
await doc.save(
|
|
249
|
-
doc.dispose();
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
### Compatibility Mode Detection and Upgrade
|
|
253
|
-
|
|
254
|
-
```typescript
|
|
255
|
-
import { Document, CompatibilityMode } from
|
|
256
|
-
|
|
257
|
-
const doc = await Document.load(
|
|
258
|
-
|
|
259
|
-
// Check compatibility mode
|
|
260
|
-
console.log(`Mode: ${doc.getCompatibilityMode()}`); // e.g., 12 (Word 2007)
|
|
261
|
-
|
|
262
|
-
if (doc.isCompatibilityMode()) {
|
|
263
|
-
// Get detailed compatibility info
|
|
264
|
-
const info = doc.getCompatibilityInfo();
|
|
265
|
-
console.log(`Legacy flags: ${info.legacyFlags.length}`);
|
|
266
|
-
|
|
267
|
-
// Upgrade to Word 2013+ mode (equivalent to File > Info > Convert)
|
|
268
|
-
const report = doc.upgradeToModernFormat();
|
|
269
|
-
console.log(`Removed ${report.removedFlags.length} legacy flags`);
|
|
270
|
-
console.log(`Added ${report.addedSettings.length} modern settings`);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
await doc.save(
|
|
274
|
-
doc.dispose();
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
## API Overview
|
|
278
|
-
|
|
279
|
-
### Document Class
|
|
280
|
-
|
|
281
|
-
**Creation & Loading:**
|
|
282
|
-
|
|
283
|
-
- `Document.create(options?)` - Create new document
|
|
284
|
-
- `Document.load(filepath, options?)` - Load from file
|
|
285
|
-
- `Document.loadFromBuffer(buffer, options?)` - Load from memory
|
|
286
|
-
|
|
287
|
-
**Handling Tracked Changes:**
|
|
288
|
-
|
|
289
|
-
By default, docXMLater accepts all tracked changes during document loading to prevent corruption:
|
|
290
|
-
|
|
291
|
-
```typescript
|
|
292
|
-
// Default: Accepts all changes (recommended)
|
|
293
|
-
const doc = await Document.load('document.docx');
|
|
294
|
-
|
|
295
|
-
// Explicit control
|
|
296
|
-
const doc = await Document.load('document.docx', {
|
|
297
|
-
revisionHandling: 'accept' // Accept all changes (default)
|
|
298
|
-
// OR
|
|
299
|
-
revisionHandling: 'strip' // Remove all revision markup
|
|
300
|
-
// OR
|
|
301
|
-
revisionHandling: 'preserve' // Keep tracked changes (may cause corruption, but should not do so - report errors if found)
|
|
302
|
-
});
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
**Revision Handling Options:**
|
|
306
|
-
|
|
307
|
-
- `'
|
|
308
|
-
- `'
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
- `
|
|
318
|
-
- `
|
|
319
|
-
- `
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
- `
|
|
325
|
-
- `
|
|
326
|
-
- `
|
|
327
|
-
- `
|
|
328
|
-
- `
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
- `
|
|
334
|
-
- `
|
|
335
|
-
- `
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
- `
|
|
341
|
-
- `
|
|
342
|
-
- `
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
- `
|
|
348
|
-
- `
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
- `
|
|
354
|
-
- `
|
|
355
|
-
- `
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
- `
|
|
361
|
-
- `
|
|
362
|
-
- `
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
- `
|
|
368
|
-
- `
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
- `
|
|
378
|
-
- `
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
- `
|
|
388
|
-
- `
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
- `
|
|
396
|
-
- `
|
|
397
|
-
- `
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
- `
|
|
403
|
-
- `
|
|
404
|
-
- `
|
|
405
|
-
- `
|
|
406
|
-
- `
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
- `
|
|
412
|
-
- `
|
|
413
|
-
- `
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
- `
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
- `
|
|
430
|
-
- `
|
|
431
|
-
- `
|
|
432
|
-
- `
|
|
433
|
-
- `
|
|
434
|
-
- `
|
|
435
|
-
- `
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
- `
|
|
441
|
-
- `
|
|
442
|
-
- `
|
|
443
|
-
- `
|
|
444
|
-
- `
|
|
445
|
-
- `
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
- `
|
|
453
|
-
- `
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
- `
|
|
459
|
-
- `
|
|
460
|
-
- `
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
- `
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
- `
|
|
477
|
-
- `
|
|
478
|
-
- `
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
- `
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
- `
|
|
489
|
-
- `
|
|
490
|
-
- `
|
|
491
|
-
- `
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
- `
|
|
497
|
-
- `
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
- `
|
|
505
|
-
- `
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
- `
|
|
519
|
-
- `
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
- `
|
|
527
|
-
- `
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
- `
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
const
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
report.locations.
|
|
572
|
-
|
|
573
|
-
console.log(`
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
-
|
|
620
|
-
-
|
|
621
|
-
-
|
|
622
|
-
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
npm
|
|
629
|
-
npm run test:
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
-
|
|
636
|
-
-
|
|
637
|
-
-
|
|
638
|
-
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
├──
|
|
648
|
-
├──
|
|
649
|
-
├──
|
|
650
|
-
├──
|
|
651
|
-
├──
|
|
652
|
-
├──
|
|
653
|
-
├──
|
|
654
|
-
├──
|
|
655
|
-
├──
|
|
656
|
-
├──
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
-
|
|
664
|
-
-
|
|
665
|
-
-
|
|
666
|
-
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
-
|
|
729
|
-
|
|
730
|
-
##
|
|
731
|
-
|
|
732
|
-
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
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
|
+
|
|
9
|
+
- Create DOCX files from scratch
|
|
10
|
+
- Read and modify existing DOCX files
|
|
11
|
+
- Buffer-based operations (load/save from memory)
|
|
12
|
+
- Document properties (core, extended, custom)
|
|
13
|
+
- Memory management with dispose pattern
|
|
14
|
+
- Bookmark pair validation and auto-repair (`validateBookmarkPairs()`)
|
|
15
|
+
- App.xml metadata preservation (HeadingPairs, TotalTime, etc.)
|
|
16
|
+
- Document background color/theme support
|
|
17
|
+
|
|
18
|
+
### Text & Paragraph Formatting
|
|
19
|
+
|
|
20
|
+
- Character formatting: bold, italic, underline, strikethrough, subscript, superscript
|
|
21
|
+
- Font properties: family, size, color (RGB and theme colors), highlight
|
|
22
|
+
- Text effects: small caps, all caps, shadow, emboss, engrave
|
|
23
|
+
- Paragraph alignment, indentation, spacing, borders, shading
|
|
24
|
+
- Text search and replace with regex support
|
|
25
|
+
- Custom styles (paragraph, character, table)
|
|
26
|
+
- CJK/East Asian paragraph properties (kinsoku, wordWrap, overflowPunct, topLinePunct)
|
|
27
|
+
- Underline color and theme color attributes
|
|
28
|
+
- Theme font references (asciiTheme, hAnsiTheme, eastAsiaTheme, csTheme)
|
|
29
|
+
|
|
30
|
+
### Lists & Tables
|
|
31
|
+
|
|
32
|
+
- Numbered lists (decimal, roman, alpha)
|
|
33
|
+
- Bulleted lists with various bullet styles
|
|
34
|
+
- Multi-level lists with custom numbering
|
|
35
|
+
- Tables with formatting, borders, shading
|
|
36
|
+
- Cell spanning (merge cells horizontally and vertically)
|
|
37
|
+
- Advanced table properties (margins, widths, alignment)
|
|
38
|
+
- Table navigation helpers (`getFirstParagraph()`, `getLastParagraph()`)
|
|
39
|
+
- Legacy horizontal merge (`hMerge`) support
|
|
40
|
+
- Table layout parsing (`fixed`/`auto`)
|
|
41
|
+
- Table style shading updates (modify styles.xml colors)
|
|
42
|
+
- Cell content management (trailing blank removal with structure preservation)
|
|
43
|
+
|
|
44
|
+
### Rich Content
|
|
45
|
+
|
|
46
|
+
- Images (PNG, JPEG, GIF, SVG, EMF, WMF) with positioning, text wrapping, and full ECMA-376 DrawingML attribute coverage
|
|
47
|
+
- Headers & footers (different first page, odd/even pages)
|
|
48
|
+
- Hyperlinks (external URLs, internal bookmarks)
|
|
49
|
+
- Hyperlink defragmentation utility (fixes fragmented links from Google Docs)
|
|
50
|
+
- Bookmarks and cross-references
|
|
51
|
+
- Body-level bookmark support (bookmarks between block elements)
|
|
52
|
+
- Shapes and text boxes
|
|
53
|
+
|
|
54
|
+
### Advanced Features
|
|
55
|
+
|
|
56
|
+
- Track changes (revisions for insertions, deletions, formatting)
|
|
57
|
+
- Granular character-level tracked changes (text diff-based)
|
|
58
|
+
- Comments and annotations
|
|
59
|
+
- Compatibility mode detection and upgrade (Word 2003/2007/2010/2013+ modes)
|
|
60
|
+
- Table of contents generation with customizable heading levels and relative indentation
|
|
61
|
+
- Fields: merge fields, date/time, page numbers, TOC fields
|
|
62
|
+
- Footnotes and endnotes (full round-trip with save pipeline, parsing, and clear API)
|
|
63
|
+
- Content controls (Structured Document Tags)
|
|
64
|
+
- Form field data preservation (text input, checkbox, dropdown per ECMA-376 §17.16)
|
|
65
|
+
- w14 run effects passthrough (Word 2010+ ligatures, numForm, textOutline, etc.)
|
|
66
|
+
- Expanded document settings (evenAndOddHeaders, mirrorMargins, autoHyphenation, decimalSymbol)
|
|
67
|
+
- People.xml auto-registration for tracked changes authors
|
|
68
|
+
- Style default attribute preservation (`w:default="1"`)
|
|
69
|
+
- Namespace order preservation in generated XML
|
|
70
|
+
- Multiple sections with different page layouts
|
|
71
|
+
- Page orientation, size, and margins
|
|
72
|
+
- Preserved element round-trip (math equations, alternate content, custom XML)
|
|
73
|
+
- Unified shading model with theme color support and inheritance resolution
|
|
74
|
+
- Lossless image optimization (PNG re-compression, BMP-to-PNG conversion)
|
|
75
|
+
- Run property change tracking (w:rPrChange) with direct API access
|
|
76
|
+
- Paragraph mark revision tracking (w:del/w:ins in w:pPr/w:rPr) for full tracked-changes fidelity
|
|
77
|
+
- Normal/NormalWeb style linking with preservation flags
|
|
78
|
+
|
|
79
|
+
### Developer Tools
|
|
80
|
+
|
|
81
|
+
- Complete XML generation and parsing (ReDoS-safe, position-based parser)
|
|
82
|
+
- 40+ unit conversion functions (twips, EMUs, points, pixels, inches, cm)
|
|
83
|
+
- Validation utilities and corruption detection
|
|
84
|
+
- Text diff utility for character-level comparisons
|
|
85
|
+
- webSettings.xml auto-generation
|
|
86
|
+
- Safe OOXML parsing helpers (zero-value handling, boolean parsing)
|
|
87
|
+
- Full TypeScript support with comprehensive type definitions
|
|
88
|
+
- Error handling utilities
|
|
89
|
+
- Logging infrastructure with multiple log levels
|
|
90
|
+
|
|
91
|
+
## Installation
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npm install docxmlater
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Quick Start
|
|
98
|
+
|
|
99
|
+
### Creating a New Document
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { Document } from 'docxmlater';
|
|
103
|
+
|
|
104
|
+
// Create a new document
|
|
105
|
+
const doc = Document.create();
|
|
106
|
+
|
|
107
|
+
// Add a paragraph
|
|
108
|
+
const para = doc.createParagraph();
|
|
109
|
+
para.addText('Hello, World!', { bold: true, fontSize: 24 });
|
|
110
|
+
|
|
111
|
+
// Save to file
|
|
112
|
+
await doc.save('hello.docx');
|
|
113
|
+
|
|
114
|
+
// Don't forget to dispose
|
|
115
|
+
doc.dispose();
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Loading and Modifying Documents
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { Document } from 'docxmlater';
|
|
122
|
+
|
|
123
|
+
// Load existing document
|
|
124
|
+
const doc = await Document.load('input.docx');
|
|
125
|
+
|
|
126
|
+
// Find and replace text
|
|
127
|
+
doc.replaceText(/old text/g, 'new text');
|
|
128
|
+
|
|
129
|
+
// Add a new paragraph
|
|
130
|
+
const para = doc.createParagraph();
|
|
131
|
+
para.addText('Added paragraph', { italic: true });
|
|
132
|
+
|
|
133
|
+
// Save modifications
|
|
134
|
+
await doc.save('output.docx');
|
|
135
|
+
doc.dispose();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Working with Tables
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { Document } from 'docxmlater';
|
|
142
|
+
|
|
143
|
+
const doc = Document.create();
|
|
144
|
+
|
|
145
|
+
// Create a 3x4 table
|
|
146
|
+
const table = doc.createTable(3, 4);
|
|
147
|
+
|
|
148
|
+
// Set header row
|
|
149
|
+
const headerRow = table.getRow(0);
|
|
150
|
+
headerRow.getCell(0).addParagraph().addText('Column 1', { bold: true });
|
|
151
|
+
headerRow.getCell(1).addParagraph().addText('Column 2', { bold: true });
|
|
152
|
+
headerRow.getCell(2).addParagraph().addText('Column 3', { bold: true });
|
|
153
|
+
headerRow.getCell(3).addParagraph().addText('Column 4', { bold: true });
|
|
154
|
+
|
|
155
|
+
// Add data
|
|
156
|
+
table.getRow(1).getCell(0).addParagraph().addText('Data 1');
|
|
157
|
+
table.getRow(1).getCell(1).addParagraph().addText('Data 2');
|
|
158
|
+
|
|
159
|
+
// Apply borders
|
|
160
|
+
table.setBorders({
|
|
161
|
+
top: { style: 'single', size: 4, color: '000000' },
|
|
162
|
+
bottom: { style: 'single', size: 4, color: '000000' },
|
|
163
|
+
left: { style: 'single', size: 4, color: '000000' },
|
|
164
|
+
right: { style: 'single', size: 4, color: '000000' },
|
|
165
|
+
insideH: { style: 'single', size: 4, color: '000000' },
|
|
166
|
+
insideV: { style: 'single', size: 4, color: '000000' },
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
await doc.save('table.docx');
|
|
170
|
+
doc.dispose();
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Adding Images
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import { Document } from 'docxmlater';
|
|
177
|
+
import { readFileSync } from 'fs';
|
|
178
|
+
|
|
179
|
+
const doc = Document.create();
|
|
180
|
+
|
|
181
|
+
// Load image from file
|
|
182
|
+
const imageBuffer = readFileSync('photo.jpg');
|
|
183
|
+
|
|
184
|
+
// Add image to document
|
|
185
|
+
const para = doc.createParagraph();
|
|
186
|
+
await para.addImage(imageBuffer, {
|
|
187
|
+
width: 400,
|
|
188
|
+
height: 300,
|
|
189
|
+
format: 'jpg',
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
await doc.save('with-image.docx');
|
|
193
|
+
doc.dispose();
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Hyperlink Management
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import { Document } from 'docxmlater';
|
|
200
|
+
|
|
201
|
+
const doc = await Document.load('document.docx');
|
|
202
|
+
|
|
203
|
+
// Get all hyperlinks
|
|
204
|
+
const hyperlinks = doc.getHyperlinks();
|
|
205
|
+
console.log(`Found ${hyperlinks.length} hyperlinks`);
|
|
206
|
+
|
|
207
|
+
// Update URLs in batch (30-50% faster than manual iteration)
|
|
208
|
+
doc.updateHyperlinkUrls('http://old-domain.com', 'https://new-domain.com');
|
|
209
|
+
|
|
210
|
+
// Fix fragmented hyperlinks from Google Docs
|
|
211
|
+
const mergedCount = doc.defragmentHyperlinks({
|
|
212
|
+
resetFormatting: true, // Fix corrupted fonts
|
|
213
|
+
});
|
|
214
|
+
console.log(`Merged ${mergedCount} fragmented hyperlinks`);
|
|
215
|
+
|
|
216
|
+
await doc.save('updated.docx');
|
|
217
|
+
doc.dispose();
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Custom Styles
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import { Document, Style } from 'docxmlater';
|
|
224
|
+
|
|
225
|
+
const doc = Document.create();
|
|
226
|
+
|
|
227
|
+
// Create custom paragraph style
|
|
228
|
+
const customStyle = new Style('CustomHeading', 'paragraph');
|
|
229
|
+
customStyle.setName('Custom Heading');
|
|
230
|
+
customStyle.setRunFormatting({
|
|
231
|
+
bold: true,
|
|
232
|
+
fontSize: 32,
|
|
233
|
+
color: '0070C0',
|
|
234
|
+
});
|
|
235
|
+
customStyle.setParagraphFormatting({
|
|
236
|
+
alignment: 'center',
|
|
237
|
+
spacingAfter: 240,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// Add style to document
|
|
241
|
+
doc.getStylesManager().addStyle(customStyle);
|
|
242
|
+
|
|
243
|
+
// Apply style to paragraph
|
|
244
|
+
const para = doc.createParagraph();
|
|
245
|
+
para.addText('Styled Heading');
|
|
246
|
+
para.applyStyle('CustomHeading');
|
|
247
|
+
|
|
248
|
+
await doc.save('styled.docx');
|
|
249
|
+
doc.dispose();
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Compatibility Mode Detection and Upgrade
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import { Document, CompatibilityMode } from 'docxmlater';
|
|
256
|
+
|
|
257
|
+
const doc = await Document.load('legacy.docx');
|
|
258
|
+
|
|
259
|
+
// Check compatibility mode
|
|
260
|
+
console.log(`Mode: ${doc.getCompatibilityMode()}`); // e.g., 12 (Word 2007)
|
|
261
|
+
|
|
262
|
+
if (doc.isCompatibilityMode()) {
|
|
263
|
+
// Get detailed compatibility info
|
|
264
|
+
const info = doc.getCompatibilityInfo();
|
|
265
|
+
console.log(`Legacy flags: ${info.legacyFlags.length}`);
|
|
266
|
+
|
|
267
|
+
// Upgrade to Word 2013+ mode (equivalent to File > Info > Convert)
|
|
268
|
+
const report = doc.upgradeToModernFormat();
|
|
269
|
+
console.log(`Removed ${report.removedFlags.length} legacy flags`);
|
|
270
|
+
console.log(`Added ${report.addedSettings.length} modern settings`);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
await doc.save('modern.docx');
|
|
274
|
+
doc.dispose();
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## API Overview
|
|
278
|
+
|
|
279
|
+
### Document Class
|
|
280
|
+
|
|
281
|
+
**Creation & Loading:**
|
|
282
|
+
|
|
283
|
+
- `Document.create(options?)` - Create new document
|
|
284
|
+
- `Document.load(filepath, options?)` - Load from file
|
|
285
|
+
- `Document.loadFromBuffer(buffer, options?)` - Load from memory
|
|
286
|
+
|
|
287
|
+
**Handling Tracked Changes:**
|
|
288
|
+
|
|
289
|
+
By default, docXMLater accepts all tracked changes during document loading to prevent corruption:
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
// Default: Accepts all changes (recommended)
|
|
293
|
+
const doc = await Document.load('document.docx');
|
|
294
|
+
|
|
295
|
+
// Explicit control
|
|
296
|
+
const doc = await Document.load('document.docx', {
|
|
297
|
+
revisionHandling: 'accept' // Accept all changes (default)
|
|
298
|
+
// OR
|
|
299
|
+
revisionHandling: 'strip' // Remove all revision markup
|
|
300
|
+
// OR
|
|
301
|
+
revisionHandling: 'preserve' // Keep tracked changes (may cause corruption, but should not do so - report errors if found)
|
|
302
|
+
});
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
**Revision Handling Options:**
|
|
306
|
+
|
|
307
|
+
- `'accept'` (default): Removes revision markup, keeps inserted content, removes deleted content
|
|
308
|
+
- `'strip'`: Removes all revision markup completely
|
|
309
|
+
- `'preserve'`: Keeps tracked changes as-is (may cause Word "unreadable content" errors)
|
|
310
|
+
|
|
311
|
+
**Why Accept By Default?**
|
|
312
|
+
|
|
313
|
+
Documents with tracked changes can cause Word corruption errors during round-trip processing due to revision ID conflicts. Accepting changes automatically prevents this issue while preserving document content.
|
|
314
|
+
|
|
315
|
+
**Content Management:**
|
|
316
|
+
|
|
317
|
+
- `createParagraph()` - Add paragraph
|
|
318
|
+
- `createTable(rows, cols)` - Add table
|
|
319
|
+
- `createSection()` - Add section
|
|
320
|
+
- `getBodyElements()` - Get all body content
|
|
321
|
+
|
|
322
|
+
**Search & Replace:**
|
|
323
|
+
|
|
324
|
+
- `findText(pattern)` - Find text matches
|
|
325
|
+
- `replaceText(pattern, replacement)` - Replace text
|
|
326
|
+
- `findParagraphsByText(pattern)` - Find paragraphs containing text/regex
|
|
327
|
+
- `getParagraphsByStyle(styleId)` - Get paragraphs with specific style
|
|
328
|
+
- `getRunsByFont(fontName)` - Get runs using a specific font
|
|
329
|
+
- `getRunsByColor(color)` - Get runs with a specific color
|
|
330
|
+
|
|
331
|
+
**Bulk Formatting:**
|
|
332
|
+
|
|
333
|
+
- `setAllRunsFont(fontName)` - Apply font to all text
|
|
334
|
+
- `setAllRunsSize(size)` - Apply font size to all text
|
|
335
|
+
- `setAllRunsColor(color)` - Apply color to all text
|
|
336
|
+
- `getFormattingReport()` - Get document formatting statistics
|
|
337
|
+
|
|
338
|
+
**Hyperlinks:**
|
|
339
|
+
|
|
340
|
+
- `getHyperlinks()` - Get all hyperlinks
|
|
341
|
+
- `updateHyperlinkUrls(oldUrl, newUrl)` - Batch URL update
|
|
342
|
+
- `defragmentHyperlinks(options?)` - Fix fragmented links
|
|
343
|
+
- `collectAllReferencedHyperlinkIds()` - Comprehensive scan of all hyperlink relationship IDs (includes nested tables, headers/footers, footnotes/endnotes)
|
|
344
|
+
|
|
345
|
+
**Statistics:**
|
|
346
|
+
|
|
347
|
+
- `getWordCount()` - Count words
|
|
348
|
+
- `getCharacterCount(includeSpaces?)` - Count characters
|
|
349
|
+
- `estimateSize()` - Estimate file size
|
|
350
|
+
|
|
351
|
+
**Compatibility Mode:**
|
|
352
|
+
|
|
353
|
+
- `getCompatibilityMode()` - Get document's Word version mode (11/12/14/15)
|
|
354
|
+
- `isCompatibilityMode()` - Check if document targets a legacy Word version
|
|
355
|
+
- `getCompatibilityInfo()` - Get full parsed compat settings
|
|
356
|
+
- `upgradeToModernFormat()` - Upgrade to Word 2013+ mode (removes legacy flags)
|
|
357
|
+
|
|
358
|
+
**Footnotes & Endnotes:**
|
|
359
|
+
|
|
360
|
+
- `createFootnote(paragraph, text)` - Add footnote
|
|
361
|
+
- `createEndnote(paragraph, text)` - Add endnote
|
|
362
|
+
- `clearFootnotes()` / `clearEndnotes()` - Remove all notes
|
|
363
|
+
- `getFootnoteManager()` / `getEndnoteManager()` - Access note managers
|
|
364
|
+
|
|
365
|
+
**Numbering Cleanup:**
|
|
366
|
+
|
|
367
|
+
- `cleanupUnusedNumbering()` - Remove unused numbering definitions (scans body, headers, footers, footnotes, endnotes)
|
|
368
|
+
- `consolidateNumbering(options?)` - Merge duplicate abstract numbering definitions
|
|
369
|
+
- `validateNumberingReferences()` - Fix orphaned numId references
|
|
370
|
+
|
|
371
|
+
**Shading:**
|
|
372
|
+
|
|
373
|
+
- `getComputedCellShading(table, row, col)` - Resolve effective cell shading with inheritance
|
|
374
|
+
|
|
375
|
+
**Document Sanitization:**
|
|
376
|
+
|
|
377
|
+
- `flattenFieldCodes()` - Strip INCLUDEPICTURE field markup, preserving embedded images
|
|
378
|
+
- `stripOrphanRSIDs()` - Remove orphan RSIDs from settings.xml
|
|
379
|
+
- `clearDirectSpacingForStyles(styleIds)` - Remove direct spacing overrides from styled paragraphs
|
|
380
|
+
|
|
381
|
+
**Image Optimization:**
|
|
382
|
+
|
|
383
|
+
- `optimizeImages()` - Lossless PNG re-compression and BMP-to-PNG conversion (zero dependencies)
|
|
384
|
+
|
|
385
|
+
**Saving:**
|
|
386
|
+
|
|
387
|
+
- `save(filepath)` - Save to file
|
|
388
|
+
- `toBuffer()` - Save to Buffer
|
|
389
|
+
- `dispose()` - Free resources (important!)
|
|
390
|
+
|
|
391
|
+
### Paragraph Class
|
|
392
|
+
|
|
393
|
+
**Content:**
|
|
394
|
+
|
|
395
|
+
- `addText(text, formatting?)` - Add text run
|
|
396
|
+
- `addRun(run)` - Add custom run
|
|
397
|
+
- `addHyperlink(hyperlink)` - Add hyperlink
|
|
398
|
+
- `addImage(buffer, options)` - Add image
|
|
399
|
+
|
|
400
|
+
**Formatting:**
|
|
401
|
+
|
|
402
|
+
- `setAlignment(alignment)` - Left, center, right, justify
|
|
403
|
+
- `setIndentation(options)` - First line, hanging, left, right
|
|
404
|
+
- `setSpacing(options)` - Line spacing, before/after
|
|
405
|
+
- `setBorders(borders)` - Paragraph borders
|
|
406
|
+
- `setShading(shading)` - Background color
|
|
407
|
+
- `applyStyle(styleId)` - Apply paragraph style
|
|
408
|
+
|
|
409
|
+
**Properties:**
|
|
410
|
+
|
|
411
|
+
- `setKeepNext(value)` - Keep with next paragraph
|
|
412
|
+
- `setKeepLines(value)` - Keep lines together
|
|
413
|
+
- `setPageBreakBefore(value)` - Page break before
|
|
414
|
+
- `clearSpacing()` - Remove direct spacing (inherit from style)
|
|
415
|
+
|
|
416
|
+
**Numbering:**
|
|
417
|
+
|
|
418
|
+
- `setNumbering(numId, level)` - Apply list numbering
|
|
419
|
+
|
|
420
|
+
### Run Class
|
|
421
|
+
|
|
422
|
+
**Text:**
|
|
423
|
+
|
|
424
|
+
- `setText(text)` - Set run text
|
|
425
|
+
- `getText()` - Get run text
|
|
426
|
+
|
|
427
|
+
**Character Formatting:**
|
|
428
|
+
|
|
429
|
+
- `setBold(value)` - Bold text
|
|
430
|
+
- `setItalic(value)` - Italic text
|
|
431
|
+
- `setUnderline(style?)` - Underline
|
|
432
|
+
- `setStrikethrough(value)` - Strikethrough
|
|
433
|
+
- `setFont(name)` - Font family
|
|
434
|
+
- `setFontSize(size)` - Font size in points
|
|
435
|
+
- `setColor(color)` - Text color (hex)
|
|
436
|
+
- `setHighlight(color)` - Highlight color
|
|
437
|
+
|
|
438
|
+
**Advanced:**
|
|
439
|
+
|
|
440
|
+
- `setSubscript(value)` - Subscript
|
|
441
|
+
- `setSuperscript(value)` - Superscript
|
|
442
|
+
- `setSmallCaps(value)` - Small capitals
|
|
443
|
+
- `setAllCaps(value)` - All capitals
|
|
444
|
+
- `clearMatchingFormatting(styleFormatting)` - Remove formatting matching a style (for inheritance)
|
|
445
|
+
- `getPropertyChangeRevision()` - Get run property change revision (w:rPrChange)
|
|
446
|
+
- `setPropertyChangeRevision(propChange)` - Set run property change revision
|
|
447
|
+
|
|
448
|
+
### Table Class
|
|
449
|
+
|
|
450
|
+
**Structure:**
|
|
451
|
+
|
|
452
|
+
- `addRow()` - Add row
|
|
453
|
+
- `getRow(index)` - Get row by index
|
|
454
|
+
- `getCell(row, col)` - Get specific cell
|
|
455
|
+
|
|
456
|
+
**Formatting:**
|
|
457
|
+
|
|
458
|
+
- `setBorders(borders)` - Table borders
|
|
459
|
+
- `setAlignment(alignment)` - Table alignment
|
|
460
|
+
- `setWidth(width)` - Table width
|
|
461
|
+
- `setLayout(layout)` - Fixed or auto layout
|
|
462
|
+
|
|
463
|
+
**Style:**
|
|
464
|
+
|
|
465
|
+
- `applyStyle(styleId)` - Apply table style
|
|
466
|
+
|
|
467
|
+
### TableCell Class
|
|
468
|
+
|
|
469
|
+
**Content:**
|
|
470
|
+
|
|
471
|
+
- `addParagraph()` - Add paragraph to cell
|
|
472
|
+
- `getParagraphs()` - Get all paragraphs
|
|
473
|
+
|
|
474
|
+
**Formatting:**
|
|
475
|
+
|
|
476
|
+
- `setBorders(borders)` - Cell borders
|
|
477
|
+
- `setShading(color)` - Cell background
|
|
478
|
+
- `setVerticalAlignment(alignment)` - Top, center, bottom
|
|
479
|
+
- `setWidth(width)` - Cell width
|
|
480
|
+
|
|
481
|
+
**Spanning:**
|
|
482
|
+
|
|
483
|
+
- `setHorizontalMerge(mergeType)` - Horizontal merge
|
|
484
|
+
- `setVerticalMerge(mergeType)` - Vertical merge
|
|
485
|
+
|
|
486
|
+
**Convenience Methods:**
|
|
487
|
+
|
|
488
|
+
- `setTextAlignment(alignment)` - Set alignment for all paragraphs
|
|
489
|
+
- `setAllParagraphsStyle(styleId)` - Apply style to all paragraphs
|
|
490
|
+
- `setAllRunsFont(fontName)` - Apply font to all runs
|
|
491
|
+
- `setAllRunsSize(size)` - Apply font size to all runs
|
|
492
|
+
- `setAllRunsColor(color)` - Apply color to all runs
|
|
493
|
+
|
|
494
|
+
**Content Management:**
|
|
495
|
+
|
|
496
|
+
- `removeTrailingBlankParagraphs(options?)` - Remove trailing blank paragraphs from cell
|
|
497
|
+
- `removeParagraph(index)` - Remove paragraph at index (updates nested content positions)
|
|
498
|
+
- `addParagraphAt(index, paragraph)` - Insert paragraph at index (updates nested content positions)
|
|
499
|
+
|
|
500
|
+
### Document Class
|
|
501
|
+
|
|
502
|
+
**Table Style Shading:**
|
|
503
|
+
|
|
504
|
+
- `updateTableStyleShading(oldColor, newColor)` - Update shading colors in styles.xml
|
|
505
|
+
- `updateTableStyleShadingBulk(settings)` - Bulk update table style shading
|
|
506
|
+
- `removeTrailingBlanksInTableCells(options?)` - Remove trailing blanks from all table cells
|
|
507
|
+
|
|
508
|
+
### Table Class
|
|
509
|
+
|
|
510
|
+
**Sorting:**
|
|
511
|
+
|
|
512
|
+
- `sortRows(columnIndex, options?)` - Sort table rows by column
|
|
513
|
+
|
|
514
|
+
### Section Class
|
|
515
|
+
|
|
516
|
+
**Line Numbering:**
|
|
517
|
+
|
|
518
|
+
- `setLineNumbering(options)` - Enable line numbering
|
|
519
|
+
- `getLineNumbering()` - Get line numbering settings
|
|
520
|
+
- `clearLineNumbering()` - Disable line numbering
|
|
521
|
+
|
|
522
|
+
### Comment Class
|
|
523
|
+
|
|
524
|
+
**Resolution:**
|
|
525
|
+
|
|
526
|
+
- `resolve()` - Mark comment as resolved
|
|
527
|
+
- `unresolve()` - Mark comment as unresolved
|
|
528
|
+
- `isResolved()` - Check if comment is resolved
|
|
529
|
+
|
|
530
|
+
### CommentManager Class
|
|
531
|
+
|
|
532
|
+
**Filtering:**
|
|
533
|
+
|
|
534
|
+
- `getResolvedComments()` - Get all resolved comments
|
|
535
|
+
- `getUnresolvedComments()` - Get all unresolved comments
|
|
536
|
+
|
|
537
|
+
### Utilities
|
|
538
|
+
|
|
539
|
+
**Unit Conversions:**
|
|
540
|
+
|
|
541
|
+
```typescript
|
|
542
|
+
import { twipsToPoints, inchesToTwips, emusToPixels } from 'docxmlater';
|
|
543
|
+
|
|
544
|
+
const points = twipsToPoints(240); // 240 twips = 12 points
|
|
545
|
+
const twips = inchesToTwips(1); // 1 inch = 1440 twips
|
|
546
|
+
const pixels = emusToPixels(914400, 96); // 914400 EMUs = 96 pixels at 96 DPI
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
**Validation:**
|
|
550
|
+
|
|
551
|
+
```typescript
|
|
552
|
+
import { validateRunText, detectXmlInText, cleanXmlFromText } from 'docxmlater';
|
|
553
|
+
|
|
554
|
+
// Detect XML patterns in text
|
|
555
|
+
const result = validateRunText('Some <w:t>text</w:t>');
|
|
556
|
+
if (result.hasXml) {
|
|
557
|
+
console.warn(result.message);
|
|
558
|
+
const cleaned = cleanXmlFromText(result.text);
|
|
559
|
+
}
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
**Corruption Detection:**
|
|
563
|
+
|
|
564
|
+
```typescript
|
|
565
|
+
import { detectCorruptionInDocument } from 'docxmlater';
|
|
566
|
+
|
|
567
|
+
const doc = await Document.load('suspect.docx');
|
|
568
|
+
const report = detectCorruptionInDocument(doc);
|
|
569
|
+
|
|
570
|
+
if (report.isCorrupted) {
|
|
571
|
+
console.log(`Found ${report.locations.length} corruption issues`);
|
|
572
|
+
report.locations.forEach((loc) => {
|
|
573
|
+
console.log(`Line ${loc.lineNumber}: ${loc.issue}`);
|
|
574
|
+
console.log(`Suggested fix: ${loc.suggestedFix}`);
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
## TypeScript Support
|
|
580
|
+
|
|
581
|
+
Full TypeScript definitions included:
|
|
582
|
+
|
|
583
|
+
```typescript
|
|
584
|
+
import {
|
|
585
|
+
Document,
|
|
586
|
+
Paragraph,
|
|
587
|
+
Run,
|
|
588
|
+
Table,
|
|
589
|
+
RunFormatting,
|
|
590
|
+
ParagraphFormatting,
|
|
591
|
+
DocumentProperties,
|
|
592
|
+
} from 'docxmlater';
|
|
593
|
+
|
|
594
|
+
// Type-safe formatting
|
|
595
|
+
const formatting: RunFormatting = {
|
|
596
|
+
bold: true,
|
|
597
|
+
fontSize: 12,
|
|
598
|
+
color: 'FF0000',
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
// Type-safe document properties
|
|
602
|
+
const properties: DocumentProperties = {
|
|
603
|
+
title: 'My Document',
|
|
604
|
+
author: 'John Doe',
|
|
605
|
+
created: new Date(),
|
|
606
|
+
};
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
## Version History
|
|
610
|
+
|
|
611
|
+
**Current Version: 10.0.4**
|
|
612
|
+
|
|
613
|
+
See [CHANGELOG.md](CHANGELOG.md) for detailed version history.
|
|
614
|
+
|
|
615
|
+
## Testing
|
|
616
|
+
|
|
617
|
+
The framework includes comprehensive test coverage:
|
|
618
|
+
|
|
619
|
+
- **2,823 test cases** across 129 test suites
|
|
620
|
+
- Tests cover all phases of implementation
|
|
621
|
+
- Integration tests for complex scenarios
|
|
622
|
+
- Performance benchmarks
|
|
623
|
+
- Edge case validation
|
|
624
|
+
|
|
625
|
+
Run tests:
|
|
626
|
+
|
|
627
|
+
```bash
|
|
628
|
+
npm test # Run all tests
|
|
629
|
+
npm run test:watch # Watch mode
|
|
630
|
+
npm run test:coverage # Coverage report
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
## Performance Considerations
|
|
634
|
+
|
|
635
|
+
- Use `dispose()` to free resources after document operations
|
|
636
|
+
- Buffer-based operations are faster than file I/O
|
|
637
|
+
- Batch hyperlink updates are 30-50% faster than manual iteration
|
|
638
|
+
- Large documents (1000+ pages) supported with memory management
|
|
639
|
+
- Streaming support for very large files
|
|
640
|
+
|
|
641
|
+
## Architecture
|
|
642
|
+
|
|
643
|
+
The framework follows a modular architecture:
|
|
644
|
+
|
|
645
|
+
```
|
|
646
|
+
src/
|
|
647
|
+
├── core/ # Document, Parser, Generator, Validator
|
|
648
|
+
├── elements/ # Paragraph, Run, Table, Image, etc.
|
|
649
|
+
├── formatting/ # Style, Numbering managers
|
|
650
|
+
├── managers/ # Drawing, Image, Relationship managers
|
|
651
|
+
├── constants/ # Compatibility mode constants, limits
|
|
652
|
+
├── types/ # Type definitions (compatibility, formatting, lists)
|
|
653
|
+
├── tracking/ # Change tracking context
|
|
654
|
+
├── validation/ # Revision validation rules
|
|
655
|
+
├── helpers/ # Cleanup utilities
|
|
656
|
+
├── xml/ # XML generation and parsing
|
|
657
|
+
├── zip/ # ZIP archive handling
|
|
658
|
+
└── utils/ # Validation, units, error handling
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
Key design principles:
|
|
662
|
+
|
|
663
|
+
- KISS (Keep It Simple, Stupid) - no over-engineering
|
|
664
|
+
- Position-based XML parsing (ReDoS-safe)
|
|
665
|
+
- Defensive programming with comprehensive validation
|
|
666
|
+
- Memory-efficient with explicit disposal pattern
|
|
667
|
+
- Full ECMA-376 (OpenXML) compliance
|
|
668
|
+
|
|
669
|
+
## Security
|
|
670
|
+
|
|
671
|
+
docXMLater includes multiple security measures to protect against common attack vectors:
|
|
672
|
+
|
|
673
|
+
### ReDoS Prevention
|
|
674
|
+
|
|
675
|
+
The XML parser uses position-based parsing instead of regular expressions, preventing catastrophic backtracking attacks that can cause denial of service.
|
|
676
|
+
|
|
677
|
+
### Input Validation
|
|
678
|
+
|
|
679
|
+
**Size Limits:**
|
|
680
|
+
|
|
681
|
+
- Default document size limit: 150 MB (configurable)
|
|
682
|
+
- Warning threshold: 50 MB
|
|
683
|
+
- XML content size validation before parsing
|
|
684
|
+
|
|
685
|
+
```typescript
|
|
686
|
+
// Configure size limits
|
|
687
|
+
const doc = await Document.load('large.docx', {
|
|
688
|
+
sizeLimits: {
|
|
689
|
+
warningSizeMB: 100,
|
|
690
|
+
maxSizeMB: 500,
|
|
691
|
+
},
|
|
692
|
+
});
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
**Nesting Depth:**
|
|
696
|
+
|
|
697
|
+
- Maximum XML nesting depth: 256 (configurable)
|
|
698
|
+
- Prevents stack overflow attacks
|
|
699
|
+
|
|
700
|
+
```typescript
|
|
701
|
+
import { XMLParser } from 'docxmlater';
|
|
702
|
+
|
|
703
|
+
// Parse with custom depth limit
|
|
704
|
+
const obj = XMLParser.parseToObject(xml, {
|
|
705
|
+
maxNestingDepth: 512, // Increase if needed
|
|
706
|
+
});
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
### Path Traversal Prevention
|
|
710
|
+
|
|
711
|
+
File paths within DOCX archives are validated to prevent directory traversal attacks:
|
|
712
|
+
|
|
713
|
+
- Blocks `../` path sequences
|
|
714
|
+
- Blocks absolute paths
|
|
715
|
+
- Validates URL-encoded path components
|
|
716
|
+
|
|
717
|
+
### XML Injection Prevention
|
|
718
|
+
|
|
719
|
+
All text content is properly escaped using:
|
|
720
|
+
|
|
721
|
+
- `XMLBuilder.escapeXmlText()` for element content
|
|
722
|
+
- `XMLBuilder.escapeXmlAttribute()` for attribute values
|
|
723
|
+
|
|
724
|
+
This prevents injection of malicious XML elements through user-provided text content.
|
|
725
|
+
|
|
726
|
+
### UTF-8 Encoding
|
|
727
|
+
|
|
728
|
+
All text files are explicitly UTF-8 encoded per ECMA-376 specification, preventing encoding-related vulnerabilities.
|
|
729
|
+
|
|
730
|
+
## Requirements
|
|
731
|
+
|
|
732
|
+
- Node.js 18.0.0 or higher
|
|
733
|
+
- TypeScript 5.0+ (for development)
|
|
734
|
+
|
|
735
|
+
## Dependencies
|
|
736
|
+
|
|
737
|
+
- `jszip` - ZIP archive handling
|
|
738
|
+
|
|
739
|
+
## License
|
|
740
|
+
|
|
741
|
+
MIT
|
|
742
|
+
|
|
743
|
+
## Contributing
|
|
744
|
+
|
|
745
|
+
Contributions welcome! Please:
|
|
746
|
+
|
|
747
|
+
1. Fork the repository
|
|
748
|
+
2. Create a feature branch
|
|
749
|
+
3. Add tests for new features
|
|
750
|
+
4. Ensure all tests pass
|
|
751
|
+
5. Submit a pull request
|
|
752
|
+
|
|
753
|
+
## Support
|
|
754
|
+
|
|
755
|
+
- GitHub Issues: https://github.com/ItMeDiaTech/docXMLater/issues
|
|
756
|
+
|
|
757
|
+
## Acknowledgments
|
|
758
|
+
|
|
759
|
+
Built with careful attention to the ECMA-376 Office Open XML specification. Special thanks to the OpenXML community for comprehensive documentation and examples.
|