docxmlater 10.1.4 → 10.1.6
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 +51 -50
- package/dist/core/Document.d.ts.map +1 -1
- package/dist/core/Document.js +486 -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 +1 -0
- package/dist/formatting/NumberingManager.d.ts.map +1 -1
- package/dist/formatting/NumberingManager.js +27 -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 +1010 -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 +875 -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/dist/core/Document.js
CHANGED
|
@@ -95,7 +95,9 @@ class Document {
|
|
|
95
95
|
this.numberingManager = NumberingManager_1.NumberingManager.create();
|
|
96
96
|
this.section = new Section_1.Section();
|
|
97
97
|
this.imageManager = ImageManager_1.ImageManager.create();
|
|
98
|
-
this.relationshipManager = initDefaults
|
|
98
|
+
this.relationshipManager = initDefaults
|
|
99
|
+
? RelationshipManager_1.RelationshipManager.createForDocument()
|
|
100
|
+
: RelationshipManager_1.RelationshipManager.create();
|
|
99
101
|
this.headerFooterManager = HeaderFooterManager_1.HeaderFooterManager.create();
|
|
100
102
|
this.bookmarkManager = BookmarkManager_1.BookmarkManager.create();
|
|
101
103
|
this.revisionManager = RevisionManager_1.RevisionManager.create();
|
|
@@ -270,8 +272,11 @@ class Document {
|
|
|
270
272
|
else if (revisionHandling === 'preserve') {
|
|
271
273
|
if (!useInMemoryAccept) {
|
|
272
274
|
const documentXml = zipHandler.getFileAsString('word/document.xml');
|
|
273
|
-
if (documentXml &&
|
|
274
|
-
documentXml.includes('<w:
|
|
275
|
+
if (documentXml &&
|
|
276
|
+
(documentXml.includes('<w:ins') ||
|
|
277
|
+
documentXml.includes('<w:del') ||
|
|
278
|
+
documentXml.includes('<w:moveFrom') ||
|
|
279
|
+
documentXml.includes('<w:moveTo'))) {
|
|
275
280
|
logger.warn('Document contains tracked changes in preserve mode');
|
|
276
281
|
}
|
|
277
282
|
}
|
|
@@ -308,7 +313,7 @@ class Document {
|
|
|
308
313
|
if (parseWarnings.length > 0) {
|
|
309
314
|
logger.warn('Document loaded with parse warnings', {
|
|
310
315
|
warningCount: parseWarnings.length,
|
|
311
|
-
elements: parseWarnings.map(w => w.element).join(', '),
|
|
316
|
+
elements: parseWarnings.map((w) => w.element).join(', '),
|
|
312
317
|
});
|
|
313
318
|
}
|
|
314
319
|
if (useInMemoryAccept) {
|
|
@@ -539,7 +544,7 @@ class Document {
|
|
|
539
544
|
}
|
|
540
545
|
catch (headerFooterError) {
|
|
541
546
|
const logger = getLogger();
|
|
542
|
-
logger.warn(
|
|
547
|
+
logger.warn('Failed to parse headers/footers - document will load without them', {
|
|
543
548
|
error: headerFooterError instanceof Error
|
|
544
549
|
? headerFooterError.message
|
|
545
550
|
: String(headerFooterError),
|
|
@@ -565,7 +570,11 @@ class Document {
|
|
|
565
570
|
return;
|
|
566
571
|
}
|
|
567
572
|
this._originalCommentsXml = commentsXml;
|
|
568
|
-
for (const path of [
|
|
573
|
+
for (const path of [
|
|
574
|
+
types_1.DOCX_PATHS.COMMENTS_EXTENDED,
|
|
575
|
+
types_1.DOCX_PATHS.COMMENTS_IDS,
|
|
576
|
+
types_1.DOCX_PATHS.COMMENTS_EXTENSIBLE,
|
|
577
|
+
]) {
|
|
569
578
|
const content = this.zipHandler.getFileAsString(path);
|
|
570
579
|
if (content) {
|
|
571
580
|
this._originalCommentCompanionFiles.set(path, content);
|
|
@@ -651,10 +660,10 @@ class Document {
|
|
|
651
660
|
this.zipHandler.addFile(types_1.DOCX_PATHS.CONTENT_TYPES, this.generator.generateContentTypes());
|
|
652
661
|
this.zipHandler.addFile(types_1.DOCX_PATHS.RELS, this.generator.generateRels());
|
|
653
662
|
this.zipHandler.addFile(types_1.DOCX_PATHS.DOCUMENT, this.generator.generateDocumentXml(this.bodyElements, this.section, this.namespaces, this._documentBackground));
|
|
654
|
-
this.zipHandler.addFile(
|
|
663
|
+
this.zipHandler.addFile('word/_rels/document.xml.rels', this.relationshipManager.generateXml());
|
|
655
664
|
this.zipHandler.addFile(types_1.DOCX_PATHS.STYLES, this.stylesManager.generateStylesXml());
|
|
656
665
|
this.zipHandler.addFile(types_1.DOCX_PATHS.NUMBERING, this.numberingManager.generateNumberingXml());
|
|
657
|
-
this.zipHandler.addFile(
|
|
666
|
+
this.zipHandler.addFile('word/fontTable.xml', this.generator.generateFontTable());
|
|
658
667
|
this.zipHandler.addFile(types_1.DOCX_PATHS.WEB_SETTINGS, this.generator.generateWebSettings());
|
|
659
668
|
this.zipHandler.addFile(types_1.DOCX_PATHS.SETTINGS, this.generator.generateSettings({
|
|
660
669
|
trackChangesEnabled: this.trackChangesEnabled,
|
|
@@ -669,14 +678,30 @@ class Document {
|
|
|
669
678
|
isLegacyMode: false,
|
|
670
679
|
compatSettings: [
|
|
671
680
|
{ name: 'compatibilityMode', uri: 'http://schemas.microsoft.com/office/word', val: '15' },
|
|
672
|
-
{
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
681
|
+
{
|
|
682
|
+
name: 'overrideTableStyleFontSizeAndJustification',
|
|
683
|
+
uri: 'http://schemas.microsoft.com/office/word',
|
|
684
|
+
val: '1',
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
name: 'enableOpenTypeFeatures',
|
|
688
|
+
uri: 'http://schemas.microsoft.com/office/word',
|
|
689
|
+
val: '1',
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
name: 'doNotFlipMirrorIndents',
|
|
693
|
+
uri: 'http://schemas.microsoft.com/office/word',
|
|
694
|
+
val: '1',
|
|
695
|
+
},
|
|
696
|
+
{
|
|
697
|
+
name: 'differentiateMultirowTableHeaders',
|
|
698
|
+
uri: 'http://schemas.microsoft.com/office/word',
|
|
699
|
+
val: '1',
|
|
700
|
+
},
|
|
676
701
|
],
|
|
677
702
|
legacyFlags: [],
|
|
678
703
|
};
|
|
679
|
-
this.zipHandler.addFile(
|
|
704
|
+
this.zipHandler.addFile('word/theme/theme1.xml', this.generator.generateTheme());
|
|
680
705
|
this.zipHandler.addFile(types_1.DOCX_PATHS.CORE_PROPS, this.generator.generateCoreProps(this.properties));
|
|
681
706
|
this.zipHandler.addFile(types_1.DOCX_PATHS.APP_PROPS, this.generator.generateAppProps(this.properties));
|
|
682
707
|
}
|
|
@@ -786,9 +811,7 @@ class Document {
|
|
|
786
811
|
getNextParagraph(paragraph) {
|
|
787
812
|
const paragraphs = this.bodyElements.filter((el) => el instanceof Paragraph_1.Paragraph);
|
|
788
813
|
const index = paragraphs.indexOf(paragraph);
|
|
789
|
-
return index >= 0 && index < paragraphs.length - 1
|
|
790
|
-
? paragraphs[index + 1]
|
|
791
|
-
: undefined;
|
|
814
|
+
return index >= 0 && index < paragraphs.length - 1 ? paragraphs[index + 1] : undefined;
|
|
792
815
|
}
|
|
793
816
|
getPreviousParagraph(paragraph) {
|
|
794
817
|
const paragraphs = this.bodyElements.filter((el) => el instanceof Paragraph_1.Paragraph);
|
|
@@ -833,7 +856,7 @@ class Document {
|
|
|
833
856
|
return { ...this.properties };
|
|
834
857
|
}
|
|
835
858
|
setProperty(key, value) {
|
|
836
|
-
|
|
859
|
+
this.properties[key] = value;
|
|
837
860
|
return this;
|
|
838
861
|
}
|
|
839
862
|
setTitle(title) {
|
|
@@ -971,7 +994,7 @@ class Document {
|
|
|
971
994
|
if (this.autoPopulateTOCs) {
|
|
972
995
|
await this.populateTOCsInFile(tempPath);
|
|
973
996
|
}
|
|
974
|
-
const { promises: fs } = await Promise.resolve().then(() => __importStar(require(
|
|
997
|
+
const { promises: fs } = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
975
998
|
await fs.rename(tempPath, filePath);
|
|
976
999
|
saveSucceeded = true;
|
|
977
1000
|
this.clearSaveStateSnapshot();
|
|
@@ -980,7 +1003,7 @@ class Document {
|
|
|
980
1003
|
catch (error) {
|
|
981
1004
|
this.restoreSaveStateSnapshot();
|
|
982
1005
|
try {
|
|
983
|
-
const { promises: fs } = await Promise.resolve().then(() => __importStar(require(
|
|
1006
|
+
const { promises: fs } = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
984
1007
|
await fs.unlink(tempPath);
|
|
985
1008
|
}
|
|
986
1009
|
catch (cleanupErr) {
|
|
@@ -1002,11 +1025,11 @@ class Document {
|
|
|
1002
1025
|
try {
|
|
1003
1026
|
await this.prepareSave();
|
|
1004
1027
|
if (this.autoPopulateTOCs) {
|
|
1005
|
-
const docXml = this.zipHandler.getFileAsString(
|
|
1028
|
+
const docXml = this.zipHandler.getFileAsString('word/document.xml');
|
|
1006
1029
|
if (docXml) {
|
|
1007
1030
|
const populatedXml = this.populateAllTOCsInXML(docXml);
|
|
1008
1031
|
if (populatedXml !== docXml) {
|
|
1009
|
-
this.zipHandler.updateFile(
|
|
1032
|
+
this.zipHandler.updateFile('word/document.xml', populatedXml);
|
|
1010
1033
|
}
|
|
1011
1034
|
}
|
|
1012
1035
|
}
|
|
@@ -1032,7 +1055,9 @@ class Document {
|
|
|
1032
1055
|
this.zipHandler.updateFile(types_1.DOCX_PATHS.DOCUMENT, xml);
|
|
1033
1056
|
}
|
|
1034
1057
|
_postProcessDocumentXml() {
|
|
1035
|
-
if (!this._flattenIncludePictureFields &&
|
|
1058
|
+
if (!this._flattenIncludePictureFields &&
|
|
1059
|
+
!this._stripOrphanRSIDs &&
|
|
1060
|
+
!this._clearDirectSpacingStyles) {
|
|
1036
1061
|
return;
|
|
1037
1062
|
}
|
|
1038
1063
|
let docXml = this.zipHandler.getFileAsString(types_1.DOCX_PATHS.DOCUMENT);
|
|
@@ -1094,7 +1119,9 @@ class Document {
|
|
|
1094
1119
|
});
|
|
1095
1120
|
const stackTop = fieldStack[fieldStack.length - 1];
|
|
1096
1121
|
const nextFldCharIdx = i + 1 < fieldTokens.length ? fieldTokens[i + 1].runStart : Infinity;
|
|
1097
|
-
while (instrTokenIdx < instrTokens.length &&
|
|
1122
|
+
while (instrTokenIdx < instrTokens.length &&
|
|
1123
|
+
instrTokens[instrTokenIdx].runStart < nextFldCharIdx &&
|
|
1124
|
+
instrTokens[instrTokenIdx].runStart > token.runStart) {
|
|
1098
1125
|
const instr = instrTokens[instrTokenIdx];
|
|
1099
1126
|
stackTop.instrRuns.push({ start: instr.runStart, end: instr.runEnd });
|
|
1100
1127
|
if (/^\s*INCLUDEPICTURE\b/i.test(instr.text)) {
|
|
@@ -1143,7 +1170,7 @@ class Document {
|
|
|
1143
1170
|
runsToRemove.sort((a, b) => b.start - a.start);
|
|
1144
1171
|
const uniqueRuns = [];
|
|
1145
1172
|
for (const run of runsToRemove) {
|
|
1146
|
-
const isDuplicate = uniqueRuns.some(u => u.start === run.start && u.end === run.end);
|
|
1173
|
+
const isDuplicate = uniqueRuns.some((u) => u.start === run.start && u.end === run.end);
|
|
1147
1174
|
if (!isDuplicate) {
|
|
1148
1175
|
uniqueRuns.push(run);
|
|
1149
1176
|
}
|
|
@@ -1273,7 +1300,8 @@ class Document {
|
|
|
1273
1300
|
}
|
|
1274
1301
|
}
|
|
1275
1302
|
updateCoreProps() {
|
|
1276
|
-
if (this._removedParts.has(types_1.DOCX_PATHS.CORE_PROPS) ||
|
|
1303
|
+
if (this._removedParts.has(types_1.DOCX_PATHS.CORE_PROPS) ||
|
|
1304
|
+
this._removedParts.has('docProps/core.xml'))
|
|
1277
1305
|
return;
|
|
1278
1306
|
const xml = this.generator.generateCoreProps(this.properties);
|
|
1279
1307
|
this.zipHandler.updateFile(types_1.DOCX_PATHS.CORE_PROPS, xml);
|
|
@@ -1508,8 +1536,10 @@ class Document {
|
|
|
1508
1536
|
const modifiedNumIds = this.numberingManager.getModifiedNumIds();
|
|
1509
1537
|
const removedAbstractNumIds = this.numberingManager.getRemovedAbstractNumIds();
|
|
1510
1538
|
const removedNumIds = this.numberingManager.getRemovedNumIds();
|
|
1511
|
-
if (modifiedAbstractNumIds.size === 0 &&
|
|
1512
|
-
|
|
1539
|
+
if (modifiedAbstractNumIds.size === 0 &&
|
|
1540
|
+
modifiedNumIds.size === 0 &&
|
|
1541
|
+
removedAbstractNumIds.size === 0 &&
|
|
1542
|
+
removedNumIds.size === 0) {
|
|
1513
1543
|
return this._originalNumberingXml;
|
|
1514
1544
|
}
|
|
1515
1545
|
let resultXml = this._originalNumberingXml;
|
|
@@ -1767,7 +1797,7 @@ class Document {
|
|
|
1767
1797
|
preElements.push('<w:hideGrammaticalErrors/>');
|
|
1768
1798
|
}
|
|
1769
1799
|
if (preElements.length > 0) {
|
|
1770
|
-
const preBlock = preElements.map(e => '\n ' + e).join('');
|
|
1800
|
+
const preBlock = preElements.map((e) => '\n ' + e).join('');
|
|
1771
1801
|
if (/<w:defaultTabStop\b/.test(xml)) {
|
|
1772
1802
|
xml = xml.replace(/<w:defaultTabStop\b/, preBlock + '\n <w:defaultTabStop');
|
|
1773
1803
|
}
|
|
@@ -1796,7 +1826,7 @@ class Document {
|
|
|
1796
1826
|
postElements.push('<w:evenAndOddHeaders/>');
|
|
1797
1827
|
}
|
|
1798
1828
|
if (postElements.length > 0) {
|
|
1799
|
-
const postBlock = postElements.map(e => '\n ' + e).join('');
|
|
1829
|
+
const postBlock = postElements.map((e) => '\n ' + e).join('');
|
|
1800
1830
|
if (/<w:characterSpacingControl\b/.test(xml)) {
|
|
1801
1831
|
xml = xml.replace(/<w:characterSpacingControl\b/, postBlock + '\n <w:characterSpacingControl');
|
|
1802
1832
|
}
|
|
@@ -2054,12 +2084,12 @@ class Document {
|
|
|
2054
2084
|
console.warn('DEPRECATION WARNING: fixTODHyperlinks() is deprecated. ' +
|
|
2055
2085
|
'Use Template_UI WordDocumentProcessor.fixExistingTopHyperlinks() instead.');
|
|
2056
2086
|
let count = 0;
|
|
2057
|
-
if (!this.hasBookmark(
|
|
2087
|
+
if (!this.hasBookmark('_top')) {
|
|
2058
2088
|
const paragraphs = this.getAllParagraphs();
|
|
2059
2089
|
if (paragraphs.length > 0) {
|
|
2060
2090
|
const firstPara = paragraphs[0];
|
|
2061
2091
|
if (firstPara) {
|
|
2062
|
-
const bookmark = new Bookmark_1.Bookmark({ name:
|
|
2092
|
+
const bookmark = new Bookmark_1.Bookmark({ name: '_top' });
|
|
2063
2093
|
const registered = this.bookmarkManager.register(bookmark);
|
|
2064
2094
|
firstPara.addBookmark(registered);
|
|
2065
2095
|
}
|
|
@@ -2068,16 +2098,16 @@ class Document {
|
|
|
2068
2098
|
const hyperlinks = this.getHyperlinks();
|
|
2069
2099
|
for (const { hyperlink, paragraph } of hyperlinks) {
|
|
2070
2100
|
const text = hyperlink.getText().toLowerCase();
|
|
2071
|
-
if (text.includes(
|
|
2072
|
-
hyperlink.setText(
|
|
2101
|
+
if (text.includes('top') && text.includes('document')) {
|
|
2102
|
+
hyperlink.setText('Top of the Document');
|
|
2073
2103
|
hyperlink.setFormatting({
|
|
2074
|
-
font:
|
|
2104
|
+
font: 'Verdana',
|
|
2075
2105
|
size: 12,
|
|
2076
|
-
underline:
|
|
2077
|
-
color:
|
|
2106
|
+
underline: 'single',
|
|
2107
|
+
color: '0000FF',
|
|
2078
2108
|
});
|
|
2079
|
-
hyperlink.setAnchor(
|
|
2080
|
-
paragraph.setAlignment(
|
|
2109
|
+
hyperlink.setAnchor('_top');
|
|
2110
|
+
paragraph.setAlignment('right');
|
|
2081
2111
|
count++;
|
|
2082
2112
|
}
|
|
2083
2113
|
}
|
|
@@ -2097,7 +2127,7 @@ class Document {
|
|
|
2097
2127
|
const firstCell = cells[0];
|
|
2098
2128
|
if (firstCell) {
|
|
2099
2129
|
const text = firstCell.getText().toLowerCase();
|
|
2100
|
-
if (text.includes(
|
|
2130
|
+
if (text.includes('if')) {
|
|
2101
2131
|
hasIfColumn = true;
|
|
2102
2132
|
break;
|
|
2103
2133
|
}
|
|
@@ -2120,7 +2150,7 @@ class Document {
|
|
|
2120
2150
|
}
|
|
2121
2151
|
applyStandardTableFormatting(colorOrOptions, multiCellColor) {
|
|
2122
2152
|
let options;
|
|
2123
|
-
if (typeof colorOrOptions ===
|
|
2153
|
+
if (typeof colorOrOptions === 'string') {
|
|
2124
2154
|
if (multiCellColor) {
|
|
2125
2155
|
options = {
|
|
2126
2156
|
singleCellShading: colorOrOptions,
|
|
@@ -2135,13 +2165,13 @@ class Document {
|
|
|
2135
2165
|
options = colorOrOptions;
|
|
2136
2166
|
}
|
|
2137
2167
|
const singleCellShading = options?.singleCellShading?.toUpperCase();
|
|
2138
|
-
const headerRowShading = (options?.headerRowShading ||
|
|
2168
|
+
const headerRowShading = (options?.headerRowShading || 'E9E9E9').toUpperCase();
|
|
2139
2169
|
const headerRowFormatting = {
|
|
2140
2170
|
bold: options?.headerRowFormatting?.bold !== false,
|
|
2141
|
-
alignment: options?.headerRowFormatting?.alignment ||
|
|
2142
|
-
font: options?.headerRowFormatting?.font ||
|
|
2171
|
+
alignment: options?.headerRowFormatting?.alignment || 'center',
|
|
2172
|
+
font: options?.headerRowFormatting?.font || 'Verdana',
|
|
2143
2173
|
size: options?.headerRowFormatting?.size || 12,
|
|
2144
|
-
color: options?.headerRowFormatting?.color ||
|
|
2174
|
+
color: options?.headerRowFormatting?.color || '000000',
|
|
2145
2175
|
spacingBefore: options?.headerRowFormatting?.spacingBefore ?? 60,
|
|
2146
2176
|
spacingAfter: options?.headerRowFormatting?.spacingAfter ?? 60,
|
|
2147
2177
|
};
|
|
@@ -2161,12 +2191,12 @@ class Document {
|
|
|
2161
2191
|
const rowCount = table.getRowCount();
|
|
2162
2192
|
const columnCount = table.getColumnCount();
|
|
2163
2193
|
table.setAllBorders({
|
|
2164
|
-
style:
|
|
2194
|
+
style: 'single',
|
|
2165
2195
|
size: 4,
|
|
2166
|
-
color:
|
|
2196
|
+
color: '000000',
|
|
2167
2197
|
});
|
|
2168
|
-
table.setLayout(
|
|
2169
|
-
table.setWidthType(
|
|
2198
|
+
table.setLayout('auto');
|
|
2199
|
+
table.setWidthType('pct');
|
|
2170
2200
|
table.setWidth(5000);
|
|
2171
2201
|
const is1x1Table = rowCount === 1 && columnCount === 1;
|
|
2172
2202
|
if (is1x1Table) {
|
|
@@ -2187,8 +2217,7 @@ class Document {
|
|
|
2187
2217
|
cell.setMargins(cellMargins);
|
|
2188
2218
|
for (const para of cell.getParagraphs()) {
|
|
2189
2219
|
const numPr = para.getFormatting().numbering;
|
|
2190
|
-
if (numPr &&
|
|
2191
|
-
(numPr.level !== undefined || numPr.numId !== undefined)) {
|
|
2220
|
+
if (numPr && (numPr.level !== undefined || numPr.numId !== undefined)) {
|
|
2192
2221
|
continue;
|
|
2193
2222
|
}
|
|
2194
2223
|
para.setAlignment(headerRowFormatting.alignment);
|
|
@@ -2216,22 +2245,21 @@ class Document {
|
|
|
2216
2245
|
const currentShading = cell.getShading();
|
|
2217
2246
|
const currentColor = currentShading?.fill?.toUpperCase();
|
|
2218
2247
|
const currentPattern = currentShading?.pattern?.toLowerCase();
|
|
2219
|
-
const isValidHexColor = /^[0-9A-F]{6}$/i.test(currentColor ||
|
|
2220
|
-
const hasHexFillShading = currentColor && currentColor !==
|
|
2248
|
+
const isValidHexColor = /^[0-9A-F]{6}$/i.test(currentColor || '');
|
|
2249
|
+
const hasHexFillShading = currentColor && currentColor !== 'FFFFFF' && isValidHexColor;
|
|
2221
2250
|
const hasPatternShading = currentPattern &&
|
|
2222
|
-
currentPattern !==
|
|
2223
|
-
currentPattern !==
|
|
2224
|
-
currentPattern !==
|
|
2251
|
+
currentPattern !== 'clear' &&
|
|
2252
|
+
currentPattern !== 'nil' &&
|
|
2253
|
+
currentPattern !== 'auto';
|
|
2225
2254
|
if (hasHexFillShading || hasPatternShading) {
|
|
2226
2255
|
cell.setShading({ fill: headerRowShading });
|
|
2227
2256
|
cellsRecolored++;
|
|
2228
2257
|
for (const para of cell.getParagraphs()) {
|
|
2229
2258
|
const numPr = para.getFormatting().numbering;
|
|
2230
|
-
if (numPr &&
|
|
2231
|
-
(numPr.level !== undefined || numPr.numId !== undefined)) {
|
|
2259
|
+
if (numPr && (numPr.level !== undefined || numPr.numId !== undefined)) {
|
|
2232
2260
|
continue;
|
|
2233
2261
|
}
|
|
2234
|
-
para.setAlignment(
|
|
2262
|
+
para.setAlignment('center');
|
|
2235
2263
|
para.setSpaceBefore(60);
|
|
2236
2264
|
para.setSpaceAfter(60);
|
|
2237
2265
|
for (const run of para.getRuns()) {
|
|
@@ -2239,10 +2267,10 @@ class Document {
|
|
|
2239
2267
|
continue;
|
|
2240
2268
|
}
|
|
2241
2269
|
run.setBold(true);
|
|
2242
|
-
run.setFont(
|
|
2270
|
+
run.setFont('Verdana', 12);
|
|
2243
2271
|
const currentColor = run.getColor()?.toUpperCase();
|
|
2244
2272
|
if (currentColor !== 'FFFFFF') {
|
|
2245
|
-
run.setColor(
|
|
2273
|
+
run.setColor('000000');
|
|
2246
2274
|
}
|
|
2247
2275
|
}
|
|
2248
2276
|
}
|
|
@@ -2282,7 +2310,7 @@ class Document {
|
|
|
2282
2310
|
const relId = image.getRelationshipId();
|
|
2283
2311
|
if (relId && largeImageIds.has(relId)) {
|
|
2284
2312
|
paragraph.formatting.indentation = undefined;
|
|
2285
|
-
paragraph.setAlignment(
|
|
2313
|
+
paragraph.setAlignment('center');
|
|
2286
2314
|
count++;
|
|
2287
2315
|
break;
|
|
2288
2316
|
}
|
|
@@ -2331,7 +2359,7 @@ class Document {
|
|
|
2331
2359
|
}
|
|
2332
2360
|
if (hasLargeImage) {
|
|
2333
2361
|
paragraph.formatting.indentation = undefined;
|
|
2334
|
-
paragraph.setAlignment(
|
|
2362
|
+
paragraph.setAlignment('center');
|
|
2335
2363
|
count++;
|
|
2336
2364
|
}
|
|
2337
2365
|
}
|
|
@@ -2342,7 +2370,7 @@ class Document {
|
|
|
2342
2370
|
for (const paragraph of this.getAllParagraphs()) {
|
|
2343
2371
|
const numbering = paragraph.getNumbering();
|
|
2344
2372
|
if (numbering) {
|
|
2345
|
-
paragraph.setLineSpacing(spacingTwips,
|
|
2373
|
+
paragraph.setLineSpacing(spacingTwips, 'auto');
|
|
2346
2374
|
count++;
|
|
2347
2375
|
}
|
|
2348
2376
|
}
|
|
@@ -2351,9 +2379,9 @@ class Document {
|
|
|
2351
2379
|
normalizeNumberedLists() {
|
|
2352
2380
|
let count = 0;
|
|
2353
2381
|
const standardNumId = this.numberingManager.createNumberedList(3, [
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2382
|
+
'decimal',
|
|
2383
|
+
'lowerLetter',
|
|
2384
|
+
'lowerRoman',
|
|
2357
2385
|
]);
|
|
2358
2386
|
const paragraphs = this.getAllParagraphs();
|
|
2359
2387
|
const numberedParas = [];
|
|
@@ -2371,7 +2399,7 @@ class Document {
|
|
|
2371
2399
|
if (!level0)
|
|
2372
2400
|
continue;
|
|
2373
2401
|
const format = level0.getFormat();
|
|
2374
|
-
if (format !==
|
|
2402
|
+
if (format !== 'bullet') {
|
|
2375
2403
|
numberedParas.push({ para, level: numbering.level });
|
|
2376
2404
|
}
|
|
2377
2405
|
}
|
|
@@ -2384,11 +2412,7 @@ class Document {
|
|
|
2384
2412
|
}
|
|
2385
2413
|
normalizeBulletLists() {
|
|
2386
2414
|
let count = 0;
|
|
2387
|
-
const standardNumId = this.numberingManager.createBulletList(3, [
|
|
2388
|
-
"•",
|
|
2389
|
-
"○",
|
|
2390
|
-
"■",
|
|
2391
|
-
]);
|
|
2415
|
+
const standardNumId = this.numberingManager.createBulletList(3, ['•', '○', '■']);
|
|
2392
2416
|
const paragraphs = this.getAllParagraphs();
|
|
2393
2417
|
const bulletParas = [];
|
|
2394
2418
|
for (const para of paragraphs) {
|
|
@@ -2405,7 +2429,7 @@ class Document {
|
|
|
2405
2429
|
if (!level0)
|
|
2406
2430
|
continue;
|
|
2407
2431
|
const format = level0.getFormat();
|
|
2408
|
-
if (format ===
|
|
2432
|
+
if (format === 'bullet') {
|
|
2409
2433
|
bulletParas.push({ para, level: numbering.level });
|
|
2410
2434
|
}
|
|
2411
2435
|
}
|
|
@@ -2435,8 +2459,8 @@ class Document {
|
|
|
2435
2459
|
}
|
|
2436
2460
|
}
|
|
2437
2461
|
}
|
|
2438
|
-
this.collectNumIdsFromElements(this.headerFooterManager.getAllHeaders().flatMap(entry => entry.header.getElements()), usedNumIds);
|
|
2439
|
-
this.collectNumIdsFromElements(this.headerFooterManager.getAllFooters().flatMap(entry => entry.footer.getElements()), usedNumIds);
|
|
2462
|
+
this.collectNumIdsFromElements(this.headerFooterManager.getAllHeaders().flatMap((entry) => entry.header.getElements()), usedNumIds);
|
|
2463
|
+
this.collectNumIdsFromElements(this.headerFooterManager.getAllFooters().flatMap((entry) => entry.footer.getElements()), usedNumIds);
|
|
2440
2464
|
for (const footnote of this.footnoteManager.getAllFootnotes()) {
|
|
2441
2465
|
this.collectNumIdsFromParagraphs(footnote.getParagraphs(), usedNumIds);
|
|
2442
2466
|
}
|
|
@@ -2711,7 +2735,7 @@ class Document {
|
|
|
2711
2735
|
nextElement.getContent().length === 0;
|
|
2712
2736
|
if (!alreadyHasBlank) {
|
|
2713
2737
|
const blankPara = new Paragraph_1.Paragraph();
|
|
2714
|
-
blankPara.setStyle(
|
|
2738
|
+
blankPara.setStyle('Normal');
|
|
2715
2739
|
this.bodyElements.splice(i + 1, 0, blankPara);
|
|
2716
2740
|
insertedCount++;
|
|
2717
2741
|
}
|
|
@@ -2724,8 +2748,8 @@ class Document {
|
|
|
2724
2748
|
}
|
|
2725
2749
|
removeAllHeadersFooters() {
|
|
2726
2750
|
let totalCount = 0;
|
|
2727
|
-
const headerRels = this.relationshipManager.getRelationshipsByType(
|
|
2728
|
-
const footerRels = this.relationshipManager.getRelationshipsByType(
|
|
2751
|
+
const headerRels = this.relationshipManager.getRelationshipsByType('http://schemas.openxmlformats.org/officeDocument/2006/relationships/header');
|
|
2752
|
+
const footerRels = this.relationshipManager.getRelationshipsByType('http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer');
|
|
2729
2753
|
for (const rel of [...headerRels, ...footerRels]) {
|
|
2730
2754
|
this.relationshipManager.removeRelationship(rel.getId());
|
|
2731
2755
|
totalCount++;
|
|
@@ -2796,6 +2820,9 @@ class Document {
|
|
|
2796
2820
|
createMultiLevelList() {
|
|
2797
2821
|
return this.numberingManager.createMultiLevelList();
|
|
2798
2822
|
}
|
|
2823
|
+
restartNumbering(numId, level, startValue) {
|
|
2824
|
+
return this.numberingManager.restartNumbering(numId, level, startValue);
|
|
2825
|
+
}
|
|
2799
2826
|
getStandardIndentation(level) {
|
|
2800
2827
|
return this.numberingManager.getStandardIndentation(level);
|
|
2801
2828
|
}
|
|
@@ -2815,15 +2842,15 @@ class Document {
|
|
|
2815
2842
|
if (!abstractNum)
|
|
2816
2843
|
continue;
|
|
2817
2844
|
const level0 = abstractNum.getLevel(0);
|
|
2818
|
-
if (level0?.getFormat() !==
|
|
2845
|
+
if (level0?.getFormat() !== 'bullet')
|
|
2819
2846
|
continue;
|
|
2820
2847
|
for (let levelIndex = 0; levelIndex < 9; levelIndex++) {
|
|
2821
2848
|
const numLevel = abstractNum.getLevel(levelIndex);
|
|
2822
2849
|
if (!numLevel)
|
|
2823
2850
|
continue;
|
|
2824
|
-
const bullet = levelIndex % 2 === 0 ?
|
|
2851
|
+
const bullet = levelIndex % 2 === 0 ? '•' : '○';
|
|
2825
2852
|
numLevel.setText(bullet);
|
|
2826
|
-
numLevel.setFont(
|
|
2853
|
+
numLevel.setFont('Arial');
|
|
2827
2854
|
numLevel.setFontSize(24);
|
|
2828
2855
|
numLevel.setLeftIndent(720 * (levelIndex + 1));
|
|
2829
2856
|
numLevel.setHangingIndent(360);
|
|
@@ -2842,17 +2869,17 @@ class Document {
|
|
|
2842
2869
|
if (!abstractNum)
|
|
2843
2870
|
continue;
|
|
2844
2871
|
const level0 = abstractNum.getLevel(0);
|
|
2845
|
-
if (!level0 || level0.getFormat() ===
|
|
2872
|
+
if (!level0 || level0.getFormat() === 'bullet')
|
|
2846
2873
|
continue;
|
|
2847
2874
|
for (let levelIndex = 0; levelIndex < 9; levelIndex++) {
|
|
2848
2875
|
const numLevel = abstractNum.getLevel(levelIndex);
|
|
2849
2876
|
if (!numLevel)
|
|
2850
2877
|
continue;
|
|
2851
|
-
numLevel.setFont(
|
|
2878
|
+
numLevel.setFont('Verdana');
|
|
2852
2879
|
numLevel.setFontSize(24);
|
|
2853
2880
|
numLevel.setLeftIndent(720 * (levelIndex + 1));
|
|
2854
2881
|
numLevel.setHangingIndent(360);
|
|
2855
|
-
numLevel.setAlignment(
|
|
2882
|
+
numLevel.setAlignment('left');
|
|
2856
2883
|
}
|
|
2857
2884
|
this.applyFormattingToListParagraphs(instance.getNumId());
|
|
2858
2885
|
count++;
|
|
@@ -2866,7 +2893,7 @@ class Document {
|
|
|
2866
2893
|
if (numbering?.numId === numId) {
|
|
2867
2894
|
const runs = para.getRuns();
|
|
2868
2895
|
for (const run of runs) {
|
|
2869
|
-
run.setFont(
|
|
2896
|
+
run.setFont('Verdana', 12);
|
|
2870
2897
|
}
|
|
2871
2898
|
para.setSpaceBefore(0);
|
|
2872
2899
|
para.setSpaceAfter(60);
|
|
@@ -2894,12 +2921,12 @@ class Document {
|
|
|
2894
2921
|
wrapParagraphInTable(para, options) {
|
|
2895
2922
|
const paraIndex = this.bodyElements.indexOf(para);
|
|
2896
2923
|
if (paraIndex === -1) {
|
|
2897
|
-
throw new Error(
|
|
2924
|
+
throw new Error('Paragraph not found in document body elements');
|
|
2898
2925
|
}
|
|
2899
2926
|
const table = new Table_1.Table(1, 1);
|
|
2900
2927
|
const cell = table.getCell(0, 0);
|
|
2901
2928
|
if (!cell) {
|
|
2902
|
-
throw new Error(
|
|
2929
|
+
throw new Error('Failed to get cell from newly created table');
|
|
2903
2930
|
}
|
|
2904
2931
|
this.bodyElements.splice(paraIndex, 1);
|
|
2905
2932
|
cell.addParagraph(para);
|
|
@@ -2919,36 +2946,36 @@ class Document {
|
|
|
2919
2946
|
}
|
|
2920
2947
|
if (options.tableWidthPercent !== undefined) {
|
|
2921
2948
|
table.setWidth(options.tableWidthPercent);
|
|
2922
|
-
table.setWidthType(
|
|
2949
|
+
table.setWidthType('pct');
|
|
2923
2950
|
}
|
|
2924
2951
|
this.bodyElements.splice(paraIndex, 0, table);
|
|
2925
2952
|
return table;
|
|
2926
2953
|
}
|
|
2927
2954
|
static DEFAULT_HEADING1_CONFIG = {
|
|
2928
2955
|
run: {
|
|
2929
|
-
font:
|
|
2956
|
+
font: 'Verdana',
|
|
2930
2957
|
size: 18,
|
|
2931
2958
|
bold: true,
|
|
2932
|
-
color:
|
|
2959
|
+
color: '000000',
|
|
2933
2960
|
},
|
|
2934
2961
|
paragraph: {
|
|
2935
|
-
alignment:
|
|
2936
|
-
spacing: { before: 0, after: 240, line: 240, lineRule:
|
|
2962
|
+
alignment: 'left',
|
|
2963
|
+
spacing: { before: 0, after: 240, line: 240, lineRule: 'auto' },
|
|
2937
2964
|
},
|
|
2938
2965
|
};
|
|
2939
2966
|
static DEFAULT_HEADING2_CONFIG = {
|
|
2940
2967
|
run: {
|
|
2941
|
-
font:
|
|
2968
|
+
font: 'Verdana',
|
|
2942
2969
|
size: 14,
|
|
2943
2970
|
bold: true,
|
|
2944
|
-
color:
|
|
2971
|
+
color: '000000',
|
|
2945
2972
|
},
|
|
2946
2973
|
paragraph: {
|
|
2947
|
-
alignment:
|
|
2948
|
-
spacing: { before: 120, after: 120, line: 240, lineRule:
|
|
2974
|
+
alignment: 'left',
|
|
2975
|
+
spacing: { before: 120, after: 120, line: 240, lineRule: 'auto' },
|
|
2949
2976
|
},
|
|
2950
2977
|
tableOptions: {
|
|
2951
|
-
shading:
|
|
2978
|
+
shading: 'BFBFBF',
|
|
2952
2979
|
marginTop: 0,
|
|
2953
2980
|
marginBottom: 0,
|
|
2954
2981
|
marginLeft: 115,
|
|
@@ -2958,36 +2985,36 @@ class Document {
|
|
|
2958
2985
|
};
|
|
2959
2986
|
static DEFAULT_HEADING3_CONFIG = {
|
|
2960
2987
|
run: {
|
|
2961
|
-
font:
|
|
2988
|
+
font: 'Verdana',
|
|
2962
2989
|
size: 12,
|
|
2963
2990
|
bold: true,
|
|
2964
|
-
color:
|
|
2991
|
+
color: '000000',
|
|
2965
2992
|
},
|
|
2966
2993
|
paragraph: {
|
|
2967
|
-
alignment:
|
|
2968
|
-
spacing: { before: 60, after: 60, line: 240, lineRule:
|
|
2994
|
+
alignment: 'left',
|
|
2995
|
+
spacing: { before: 60, after: 60, line: 240, lineRule: 'auto' },
|
|
2969
2996
|
},
|
|
2970
2997
|
};
|
|
2971
2998
|
static DEFAULT_NORMAL_CONFIG = {
|
|
2972
2999
|
run: {
|
|
2973
|
-
font:
|
|
3000
|
+
font: 'Verdana',
|
|
2974
3001
|
size: 12,
|
|
2975
|
-
color:
|
|
3002
|
+
color: '000000',
|
|
2976
3003
|
},
|
|
2977
3004
|
paragraph: {
|
|
2978
|
-
alignment:
|
|
2979
|
-
spacing: { before: 60, after: 60, line: 240, lineRule:
|
|
3005
|
+
alignment: 'left',
|
|
3006
|
+
spacing: { before: 60, after: 60, line: 240, lineRule: 'auto' },
|
|
2980
3007
|
},
|
|
2981
3008
|
};
|
|
2982
3009
|
static DEFAULT_LIST_PARAGRAPH_CONFIG = {
|
|
2983
3010
|
run: {
|
|
2984
|
-
font:
|
|
3011
|
+
font: 'Verdana',
|
|
2985
3012
|
size: 12,
|
|
2986
|
-
color:
|
|
3013
|
+
color: '000000',
|
|
2987
3014
|
},
|
|
2988
3015
|
paragraph: {
|
|
2989
|
-
alignment:
|
|
2990
|
-
spacing: { before: 0, after: 60, line: 240, lineRule:
|
|
3016
|
+
alignment: 'left',
|
|
3017
|
+
spacing: { before: 0, after: 60, line: 240, lineRule: 'auto' },
|
|
2991
3018
|
indentation: { left: 360, hanging: 360 },
|
|
2992
3019
|
contextualSpacing: true,
|
|
2993
3020
|
},
|
|
@@ -3018,32 +3045,28 @@ class Document {
|
|
|
3018
3045
|
normal: false,
|
|
3019
3046
|
listParagraph: false,
|
|
3020
3047
|
};
|
|
3021
|
-
const heading1 = this.stylesManager.getStyle(
|
|
3022
|
-
const heading2 = this.stylesManager.getStyle(
|
|
3023
|
-
const heading3 = this.stylesManager.getStyle(
|
|
3024
|
-
const normal = this.stylesManager.getStyle(
|
|
3025
|
-
const listParagraph = this.stylesManager.getStyle(
|
|
3048
|
+
const heading1 = this.stylesManager.getStyle('Heading1');
|
|
3049
|
+
const heading2 = this.stylesManager.getStyle('Heading2');
|
|
3050
|
+
const heading3 = this.stylesManager.getStyle('Heading3');
|
|
3051
|
+
const normal = this.stylesManager.getStyle('Normal');
|
|
3052
|
+
const listParagraph = this.stylesManager.getStyle('ListParagraph');
|
|
3026
3053
|
const h1Config = {
|
|
3027
3054
|
run: {
|
|
3028
|
-
...(heading1?.getRunFormatting() ||
|
|
3029
|
-
Document.DEFAULT_HEADING1_CONFIG.run),
|
|
3055
|
+
...(heading1?.getRunFormatting() || Document.DEFAULT_HEADING1_CONFIG.run),
|
|
3030
3056
|
...options?.heading1?.run,
|
|
3031
3057
|
},
|
|
3032
3058
|
paragraph: {
|
|
3033
|
-
...(heading1?.getParagraphFormatting() ||
|
|
3034
|
-
Document.DEFAULT_HEADING1_CONFIG.paragraph),
|
|
3059
|
+
...(heading1?.getParagraphFormatting() || Document.DEFAULT_HEADING1_CONFIG.paragraph),
|
|
3035
3060
|
...options?.heading1?.paragraph,
|
|
3036
3061
|
},
|
|
3037
3062
|
};
|
|
3038
3063
|
const h2Config = {
|
|
3039
3064
|
run: {
|
|
3040
|
-
...(heading2?.getRunFormatting() ||
|
|
3041
|
-
Document.DEFAULT_HEADING2_CONFIG.run),
|
|
3065
|
+
...(heading2?.getRunFormatting() || Document.DEFAULT_HEADING2_CONFIG.run),
|
|
3042
3066
|
...options?.heading2?.run,
|
|
3043
3067
|
},
|
|
3044
3068
|
paragraph: {
|
|
3045
|
-
...(heading2?.getParagraphFormatting() ||
|
|
3046
|
-
Document.DEFAULT_HEADING2_CONFIG.paragraph),
|
|
3069
|
+
...(heading2?.getParagraphFormatting() || Document.DEFAULT_HEADING2_CONFIG.paragraph),
|
|
3047
3070
|
...options?.heading2?.paragraph,
|
|
3048
3071
|
},
|
|
3049
3072
|
tableOptions: {
|
|
@@ -3053,13 +3076,11 @@ class Document {
|
|
|
3053
3076
|
};
|
|
3054
3077
|
const h3Config = {
|
|
3055
3078
|
run: {
|
|
3056
|
-
...(heading3?.getRunFormatting() ||
|
|
3057
|
-
Document.DEFAULT_HEADING3_CONFIG.run),
|
|
3079
|
+
...(heading3?.getRunFormatting() || Document.DEFAULT_HEADING3_CONFIG.run),
|
|
3058
3080
|
...options?.heading3?.run,
|
|
3059
3081
|
},
|
|
3060
3082
|
paragraph: {
|
|
3061
|
-
...(heading3?.getParagraphFormatting() ||
|
|
3062
|
-
Document.DEFAULT_HEADING3_CONFIG.paragraph),
|
|
3083
|
+
...(heading3?.getParagraphFormatting() || Document.DEFAULT_HEADING3_CONFIG.paragraph),
|
|
3063
3084
|
...options?.heading3?.paragraph,
|
|
3064
3085
|
},
|
|
3065
3086
|
};
|
|
@@ -3069,15 +3090,13 @@ class Document {
|
|
|
3069
3090
|
...options?.normal?.run,
|
|
3070
3091
|
},
|
|
3071
3092
|
paragraph: {
|
|
3072
|
-
...(normal?.getParagraphFormatting() ||
|
|
3073
|
-
Document.DEFAULT_NORMAL_CONFIG.paragraph),
|
|
3093
|
+
...(normal?.getParagraphFormatting() || Document.DEFAULT_NORMAL_CONFIG.paragraph),
|
|
3074
3094
|
...options?.normal?.paragraph,
|
|
3075
3095
|
},
|
|
3076
3096
|
};
|
|
3077
3097
|
const listParaConfig = {
|
|
3078
3098
|
run: {
|
|
3079
|
-
...(listParagraph?.getRunFormatting() ||
|
|
3080
|
-
Document.DEFAULT_LIST_PARAGRAPH_CONFIG.run),
|
|
3099
|
+
...(listParagraph?.getRunFormatting() || Document.DEFAULT_LIST_PARAGRAPH_CONFIG.run),
|
|
3081
3100
|
...options?.listParagraph?.run,
|
|
3082
3101
|
},
|
|
3083
3102
|
paragraph: {
|
|
@@ -3119,7 +3138,7 @@ class Document {
|
|
|
3119
3138
|
this.addStyle(normal);
|
|
3120
3139
|
const shouldLinkNormalWeb = options?.linkNormalWebToNormal !== false;
|
|
3121
3140
|
if (shouldLinkNormalWeb) {
|
|
3122
|
-
const normalWeb = this.stylesManager.getStyle(
|
|
3141
|
+
const normalWeb = this.stylesManager.getStyle('NormalWeb');
|
|
3123
3142
|
if (normalWeb) {
|
|
3124
3143
|
if (normalConfig.run)
|
|
3125
3144
|
normalWeb.setRunFormatting(normalConfig.run);
|
|
@@ -3180,10 +3199,10 @@ class Document {
|
|
|
3180
3199
|
continue;
|
|
3181
3200
|
}
|
|
3182
3201
|
const styleId = para.getStyle();
|
|
3183
|
-
if (styleId ===
|
|
3202
|
+
if (styleId === 'Heading1' && heading1) {
|
|
3184
3203
|
const allRuns = this.getAllRunsFromParagraph(para);
|
|
3185
3204
|
const whiteFontRuns = new Set(options?.preserveWhiteFont
|
|
3186
|
-
? allRuns.filter(run => run.getColor()?.toUpperCase() === 'FFFFFF')
|
|
3205
|
+
? allRuns.filter((run) => run.getColor()?.toUpperCase() === 'FFFFFF')
|
|
3187
3206
|
: []);
|
|
3188
3207
|
para.clearDirectFormattingConflicts(heading1);
|
|
3189
3208
|
for (const run of allRuns) {
|
|
@@ -3197,7 +3216,7 @@ class Document {
|
|
|
3197
3216
|
run.setItalic(h1Config.run?.italic ?? false);
|
|
3198
3217
|
}
|
|
3199
3218
|
if (!h1Preserve.underline) {
|
|
3200
|
-
run.setUnderline(h1Config.run?.underline ?
|
|
3219
|
+
run.setUnderline(h1Config.run?.underline ? 'single' : false);
|
|
3201
3220
|
}
|
|
3202
3221
|
if (h1Config.run?.font) {
|
|
3203
3222
|
run.setFont(h1Config.run.font);
|
|
@@ -3216,19 +3235,13 @@ class Document {
|
|
|
3216
3235
|
}
|
|
3217
3236
|
if (para.formatting.paragraphMarkRunProperties) {
|
|
3218
3237
|
const markProps = para.formatting.paragraphMarkRunProperties;
|
|
3219
|
-
if (!h1Preserve.bold &&
|
|
3220
|
-
h1Config.run?.bold === false &&
|
|
3221
|
-
markProps.bold) {
|
|
3238
|
+
if (!h1Preserve.bold && h1Config.run?.bold === false && markProps.bold) {
|
|
3222
3239
|
delete markProps.bold;
|
|
3223
3240
|
}
|
|
3224
|
-
if (!h1Preserve.italic &&
|
|
3225
|
-
h1Config.run?.italic === false &&
|
|
3226
|
-
markProps.italic) {
|
|
3241
|
+
if (!h1Preserve.italic && h1Config.run?.italic === false && markProps.italic) {
|
|
3227
3242
|
delete markProps.italic;
|
|
3228
3243
|
}
|
|
3229
|
-
if (!h1Preserve.underline &&
|
|
3230
|
-
h1Config.run?.underline === false &&
|
|
3231
|
-
markProps.underline) {
|
|
3244
|
+
if (!h1Preserve.underline && h1Config.run?.underline === false && markProps.underline) {
|
|
3232
3245
|
delete markProps.underline;
|
|
3233
3246
|
}
|
|
3234
3247
|
if (h1Config.run?.font) {
|
|
@@ -3243,9 +3256,8 @@ class Document {
|
|
|
3243
3256
|
}
|
|
3244
3257
|
processedParagraphs.add(para);
|
|
3245
3258
|
}
|
|
3246
|
-
else if (styleId ===
|
|
3247
|
-
const hasContent = this.getAllRunsFromParagraph(para)
|
|
3248
|
-
.some((run) => run.getText().trim().length > 0);
|
|
3259
|
+
else if (styleId === 'Heading2' && heading2) {
|
|
3260
|
+
const hasContent = this.getAllRunsFromParagraph(para).some((run) => run.getText().trim().length > 0);
|
|
3249
3261
|
if (!hasContent) {
|
|
3250
3262
|
processedParagraphs.add(para);
|
|
3251
3263
|
continue;
|
|
@@ -3267,8 +3279,7 @@ class Document {
|
|
|
3267
3279
|
const colCount = table.getColumnCount();
|
|
3268
3280
|
const isMultiCellTable = !(rowCount === 1 && colCount === 1);
|
|
3269
3281
|
const cellFormatting = cell.getFormatting();
|
|
3270
|
-
const cellHasShading = !!(cellFormatting?.shading?.fill ||
|
|
3271
|
-
cellFormatting?.shading?.pattern);
|
|
3282
|
+
const cellHasShading = !!(cellFormatting?.shading?.fill || cellFormatting?.shading?.pattern);
|
|
3272
3283
|
if (isMultiCellTable && cellHasShading && para.formatting.alignment) {
|
|
3273
3284
|
preservedAlignment = para.formatting.alignment;
|
|
3274
3285
|
}
|
|
@@ -3276,7 +3287,7 @@ class Document {
|
|
|
3276
3287
|
}
|
|
3277
3288
|
const allRuns = this.getAllRunsFromParagraph(para);
|
|
3278
3289
|
const whiteFontRuns = new Set(options?.preserveWhiteFont
|
|
3279
|
-
? allRuns.filter(run => run.getColor()?.toUpperCase() === 'FFFFFF')
|
|
3290
|
+
? allRuns.filter((run) => run.getColor()?.toUpperCase() === 'FFFFFF')
|
|
3280
3291
|
: []);
|
|
3281
3292
|
para.clearDirectFormattingConflicts(heading2);
|
|
3282
3293
|
if (preservedAlignment) {
|
|
@@ -3293,7 +3304,7 @@ class Document {
|
|
|
3293
3304
|
run.setItalic(h2Config.run?.italic ?? false);
|
|
3294
3305
|
}
|
|
3295
3306
|
if (!h2Preserve.underline) {
|
|
3296
|
-
run.setUnderline(h2Config.run?.underline ?
|
|
3307
|
+
run.setUnderline(h2Config.run?.underline ? 'single' : false);
|
|
3297
3308
|
}
|
|
3298
3309
|
if (h2Config.run?.font) {
|
|
3299
3310
|
run.setFont(h2Config.run.font);
|
|
@@ -3312,19 +3323,13 @@ class Document {
|
|
|
3312
3323
|
}
|
|
3313
3324
|
if (para.formatting.paragraphMarkRunProperties) {
|
|
3314
3325
|
const markProps = para.formatting.paragraphMarkRunProperties;
|
|
3315
|
-
if (!h2Preserve.bold &&
|
|
3316
|
-
h2Config.run?.bold === false &&
|
|
3317
|
-
markProps.bold) {
|
|
3326
|
+
if (!h2Preserve.bold && h2Config.run?.bold === false && markProps.bold) {
|
|
3318
3327
|
delete markProps.bold;
|
|
3319
3328
|
}
|
|
3320
|
-
if (!h2Preserve.italic &&
|
|
3321
|
-
h2Config.run?.italic === false &&
|
|
3322
|
-
markProps.italic) {
|
|
3329
|
+
if (!h2Preserve.italic && h2Config.run?.italic === false && markProps.italic) {
|
|
3323
3330
|
delete markProps.italic;
|
|
3324
3331
|
}
|
|
3325
|
-
if (!h2Preserve.underline &&
|
|
3326
|
-
h2Config.run?.underline === false &&
|
|
3327
|
-
markProps.underline) {
|
|
3332
|
+
if (!h2Preserve.underline && h2Config.run?.underline === false && markProps.underline) {
|
|
3328
3333
|
delete markProps.underline;
|
|
3329
3334
|
}
|
|
3330
3335
|
if (h2Config.run?.font) {
|
|
@@ -3364,13 +3369,13 @@ class Document {
|
|
|
3364
3369
|
});
|
|
3365
3370
|
if (table) {
|
|
3366
3371
|
table.setWidth(h2Config.tableOptions.tableWidthPercent);
|
|
3367
|
-
table.setWidthType(
|
|
3372
|
+
table.setWidthType('pct');
|
|
3368
3373
|
}
|
|
3369
3374
|
}
|
|
3370
3375
|
}
|
|
3371
3376
|
else {
|
|
3372
3377
|
const table = this.wrapParagraphInTable(para, {
|
|
3373
|
-
shading: h2Config.tableOptions?.shading ??
|
|
3378
|
+
shading: h2Config.tableOptions?.shading ?? 'BFBFBF',
|
|
3374
3379
|
marginTop: h2Config.tableOptions?.marginTop ?? 0,
|
|
3375
3380
|
marginBottom: h2Config.tableOptions?.marginBottom ?? 0,
|
|
3376
3381
|
marginLeft: h2Config.tableOptions?.marginLeft ?? 115,
|
|
@@ -3392,7 +3397,7 @@ class Document {
|
|
|
3392
3397
|
}
|
|
3393
3398
|
if (item.getText) {
|
|
3394
3399
|
const text = item.getText().trim();
|
|
3395
|
-
if (text !==
|
|
3400
|
+
if (text !== '')
|
|
3396
3401
|
return false;
|
|
3397
3402
|
}
|
|
3398
3403
|
}
|
|
@@ -3410,10 +3415,10 @@ class Document {
|
|
|
3410
3415
|
}
|
|
3411
3416
|
processedParagraphs.add(para);
|
|
3412
3417
|
}
|
|
3413
|
-
else if (styleId ===
|
|
3418
|
+
else if (styleId === 'Heading3' && heading3) {
|
|
3414
3419
|
const allRuns = this.getAllRunsFromParagraph(para);
|
|
3415
3420
|
const whiteFontRuns = new Set(options?.preserveWhiteFont
|
|
3416
|
-
? allRuns.filter(run => run.getColor()?.toUpperCase() === 'FFFFFF')
|
|
3421
|
+
? allRuns.filter((run) => run.getColor()?.toUpperCase() === 'FFFFFF')
|
|
3417
3422
|
: []);
|
|
3418
3423
|
para.clearDirectFormattingConflicts(heading3);
|
|
3419
3424
|
for (const run of allRuns) {
|
|
@@ -3427,7 +3432,7 @@ class Document {
|
|
|
3427
3432
|
run.setItalic(h3Config.run?.italic ?? false);
|
|
3428
3433
|
}
|
|
3429
3434
|
if (!h3Preserve.underline) {
|
|
3430
|
-
run.setUnderline(h3Config.run?.underline ?
|
|
3435
|
+
run.setUnderline(h3Config.run?.underline ? 'single' : false);
|
|
3431
3436
|
}
|
|
3432
3437
|
if (h3Config.run?.font) {
|
|
3433
3438
|
run.setFont(h3Config.run.font);
|
|
@@ -3446,19 +3451,13 @@ class Document {
|
|
|
3446
3451
|
}
|
|
3447
3452
|
if (para.formatting.paragraphMarkRunProperties) {
|
|
3448
3453
|
const markProps = para.formatting.paragraphMarkRunProperties;
|
|
3449
|
-
if (!h3Preserve.bold &&
|
|
3450
|
-
h3Config.run?.bold === false &&
|
|
3451
|
-
markProps.bold) {
|
|
3454
|
+
if (!h3Preserve.bold && h3Config.run?.bold === false && markProps.bold) {
|
|
3452
3455
|
delete markProps.bold;
|
|
3453
3456
|
}
|
|
3454
|
-
if (!h3Preserve.italic &&
|
|
3455
|
-
h3Config.run?.italic === false &&
|
|
3456
|
-
markProps.italic) {
|
|
3457
|
+
if (!h3Preserve.italic && h3Config.run?.italic === false && markProps.italic) {
|
|
3457
3458
|
delete markProps.italic;
|
|
3458
3459
|
}
|
|
3459
|
-
if (!h3Preserve.underline &&
|
|
3460
|
-
h3Config.run?.underline === false &&
|
|
3461
|
-
markProps.underline) {
|
|
3460
|
+
if (!h3Preserve.underline && h3Config.run?.underline === false && markProps.underline) {
|
|
3462
3461
|
delete markProps.underline;
|
|
3463
3462
|
}
|
|
3464
3463
|
if (h3Config.run?.font) {
|
|
@@ -3473,11 +3472,11 @@ class Document {
|
|
|
3473
3472
|
}
|
|
3474
3473
|
processedParagraphs.add(para);
|
|
3475
3474
|
}
|
|
3476
|
-
else if (styleId ===
|
|
3475
|
+
else if (styleId === 'ListParagraph' && listParagraph) {
|
|
3477
3476
|
const paraIndentation = para.getFormatting().indentation;
|
|
3478
3477
|
const hasNumbering = para.getNumbering();
|
|
3479
3478
|
if (paraIndentation?.left === 0 && !hasNumbering) {
|
|
3480
|
-
para.setStyle(
|
|
3479
|
+
para.setStyle('Normal');
|
|
3481
3480
|
const allRuns = this.getAllRunsFromParagraph(para);
|
|
3482
3481
|
const preservedBold = allRuns.map((run) => ({
|
|
3483
3482
|
run,
|
|
@@ -3547,7 +3546,7 @@ class Document {
|
|
|
3547
3546
|
run.setItalic(listParaConfig.run?.italic ?? false);
|
|
3548
3547
|
}
|
|
3549
3548
|
if (!listParaPreserve.underline) {
|
|
3550
|
-
run.setUnderline(listParaConfig.run?.underline ?
|
|
3549
|
+
run.setUnderline(listParaConfig.run?.underline ? 'single' : false);
|
|
3551
3550
|
}
|
|
3552
3551
|
if (listParaConfig.run?.font) {
|
|
3553
3552
|
run.setFont(listParaConfig.run.font);
|
|
@@ -3566,9 +3565,7 @@ class Document {
|
|
|
3566
3565
|
}
|
|
3567
3566
|
if (para.formatting.paragraphMarkRunProperties) {
|
|
3568
3567
|
const markProps = para.formatting.paragraphMarkRunProperties;
|
|
3569
|
-
if (!listParaPreserve.bold &&
|
|
3570
|
-
listParaConfig.run?.bold === false &&
|
|
3571
|
-
markProps.bold) {
|
|
3568
|
+
if (!listParaPreserve.bold && listParaConfig.run?.bold === false && markProps.bold) {
|
|
3572
3569
|
delete markProps.bold;
|
|
3573
3570
|
}
|
|
3574
3571
|
if (!listParaPreserve.italic &&
|
|
@@ -3593,7 +3590,10 @@ class Document {
|
|
|
3593
3590
|
}
|
|
3594
3591
|
processedParagraphs.add(para);
|
|
3595
3592
|
}
|
|
3596
|
-
else if ((styleId ===
|
|
3593
|
+
else if ((styleId === 'Normal' ||
|
|
3594
|
+
styleId === undefined ||
|
|
3595
|
+
(styleId === 'NormalWeb' && options?.linkNormalWebToNormal !== false)) &&
|
|
3596
|
+
normal) {
|
|
3597
3597
|
const allRuns = this.getAllRunsFromParagraph(para);
|
|
3598
3598
|
const preservedFormatting = allRuns.map((run) => {
|
|
3599
3599
|
const fmt = run.getFormatting();
|
|
@@ -3605,8 +3605,7 @@ class Document {
|
|
|
3605
3605
|
isWhiteFont: options?.preserveWhiteFont && fmt.color?.toUpperCase() === 'FFFFFF',
|
|
3606
3606
|
};
|
|
3607
3607
|
});
|
|
3608
|
-
const savedCenterAlignment = options?.normal?.preserveCenterAlignment &&
|
|
3609
|
-
para.getAlignment() === 'center';
|
|
3608
|
+
const savedCenterAlignment = options?.normal?.preserveCenterAlignment && para.getAlignment() === 'center';
|
|
3610
3609
|
para.clearDirectFormattingConflicts(normal);
|
|
3611
3610
|
if (savedCenterAlignment) {
|
|
3612
3611
|
para.setAlignment('center');
|
|
@@ -3634,7 +3633,7 @@ class Document {
|
|
|
3634
3633
|
run.setItalic(normalConfig.run?.italic ?? false);
|
|
3635
3634
|
}
|
|
3636
3635
|
if (!normalPreserve.underline) {
|
|
3637
|
-
run.setUnderline(normalConfig.run?.underline ?
|
|
3636
|
+
run.setUnderline(normalConfig.run?.underline ? 'single' : false);
|
|
3638
3637
|
}
|
|
3639
3638
|
if (normalConfig.run?.font) {
|
|
3640
3639
|
run.setFont(normalConfig.run.font);
|
|
@@ -3653,14 +3652,10 @@ class Document {
|
|
|
3653
3652
|
}
|
|
3654
3653
|
if (para.formatting.paragraphMarkRunProperties) {
|
|
3655
3654
|
const markProps = para.formatting.paragraphMarkRunProperties;
|
|
3656
|
-
if (!normalPreserve.bold &&
|
|
3657
|
-
normalConfig.run?.bold === false &&
|
|
3658
|
-
markProps.bold) {
|
|
3655
|
+
if (!normalPreserve.bold && normalConfig.run?.bold === false && markProps.bold) {
|
|
3659
3656
|
delete markProps.bold;
|
|
3660
3657
|
}
|
|
3661
|
-
if (!normalPreserve.italic &&
|
|
3662
|
-
normalConfig.run?.italic === false &&
|
|
3663
|
-
markProps.italic) {
|
|
3658
|
+
if (!normalPreserve.italic && normalConfig.run?.italic === false && markProps.italic) {
|
|
3664
3659
|
delete markProps.italic;
|
|
3665
3660
|
}
|
|
3666
3661
|
if (!normalPreserve.underline &&
|
|
@@ -3684,8 +3679,7 @@ class Document {
|
|
|
3684
3679
|
return results;
|
|
3685
3680
|
}
|
|
3686
3681
|
formatTOCStyles(options) {
|
|
3687
|
-
const validLevels = (options.levels ?? [1, 2, 3, 4, 5, 6, 7, 8, 9])
|
|
3688
|
-
.filter((l) => l >= 1 && l <= 9);
|
|
3682
|
+
const validLevels = (options.levels ?? [1, 2, 3, 4, 5, 6, 7, 8, 9]).filter((l) => l >= 1 && l <= 9);
|
|
3689
3683
|
const levels = [...new Set(validLevels)].sort((a, b) => a - b);
|
|
3690
3684
|
const formatted = [];
|
|
3691
3685
|
for (let i = 0; i < levels.length; i++) {
|
|
@@ -3726,32 +3720,32 @@ class Document {
|
|
|
3726
3720
|
for (const style of styles) {
|
|
3727
3721
|
const styleId = style.getStyleId();
|
|
3728
3722
|
switch (styleId) {
|
|
3729
|
-
case
|
|
3723
|
+
case 'Heading1':
|
|
3730
3724
|
options.heading1 = {
|
|
3731
3725
|
run: style.getRunFormatting(),
|
|
3732
3726
|
paragraph: style.getParagraphFormatting(),
|
|
3733
3727
|
};
|
|
3734
3728
|
break;
|
|
3735
|
-
case
|
|
3729
|
+
case 'Heading2':
|
|
3736
3730
|
options.heading2 = {
|
|
3737
3731
|
run: style.getRunFormatting(),
|
|
3738
3732
|
paragraph: style.getParagraphFormatting(),
|
|
3739
3733
|
tableOptions: style.getHeading2TableOptions(),
|
|
3740
3734
|
};
|
|
3741
3735
|
break;
|
|
3742
|
-
case
|
|
3736
|
+
case 'Heading3':
|
|
3743
3737
|
options.heading3 = {
|
|
3744
3738
|
run: style.getRunFormatting(),
|
|
3745
3739
|
paragraph: style.getParagraphFormatting(),
|
|
3746
3740
|
};
|
|
3747
3741
|
break;
|
|
3748
|
-
case
|
|
3742
|
+
case 'Normal':
|
|
3749
3743
|
options.normal = {
|
|
3750
3744
|
run: style.getRunFormatting(),
|
|
3751
3745
|
paragraph: style.getParagraphFormatting(),
|
|
3752
3746
|
};
|
|
3753
3747
|
break;
|
|
3754
|
-
case
|
|
3748
|
+
case 'ListParagraph':
|
|
3755
3749
|
options.listParagraph = {
|
|
3756
3750
|
run: style.getRunFormatting(),
|
|
3757
3751
|
paragraph: style.getParagraphFormatting(),
|
|
@@ -3764,8 +3758,8 @@ class Document {
|
|
|
3764
3758
|
return this.applyStyles(options);
|
|
3765
3759
|
}
|
|
3766
3760
|
updateTableStyleShading(oldColor, newColor) {
|
|
3767
|
-
const normalizedOld = oldColor.replace(
|
|
3768
|
-
const normalizedNew = newColor.replace(
|
|
3761
|
+
const normalizedOld = oldColor.replace('#', '').toUpperCase();
|
|
3762
|
+
const normalizedNew = newColor.replace('#', '').toUpperCase();
|
|
3769
3763
|
if (normalizedOld === normalizedNew) {
|
|
3770
3764
|
return 0;
|
|
3771
3765
|
}
|
|
@@ -3774,12 +3768,12 @@ class Document {
|
|
|
3774
3768
|
return 0;
|
|
3775
3769
|
}
|
|
3776
3770
|
let updateCount = 0;
|
|
3777
|
-
const fillPattern = new RegExp(`(w:fill=["'])${normalizedOld}(["'])`,
|
|
3771
|
+
const fillPattern = new RegExp(`(w:fill=["'])${normalizedOld}(["'])`, 'gi');
|
|
3778
3772
|
stylesXml = stylesXml.replace(fillPattern, (match, prefix, suffix) => {
|
|
3779
3773
|
updateCount++;
|
|
3780
3774
|
return `${prefix}${normalizedNew}${suffix}`;
|
|
3781
3775
|
});
|
|
3782
|
-
const colorPattern = new RegExp(`(<w:shd[^>]*w:color=["'])${normalizedOld}(["'])`,
|
|
3776
|
+
const colorPattern = new RegExp(`(<w:shd[^>]*w:color=["'])${normalizedOld}(["'])`, 'gi');
|
|
3783
3777
|
stylesXml = stylesXml.replace(colorPattern, (match, prefix, suffix) => {
|
|
3784
3778
|
updateCount++;
|
|
3785
3779
|
return `${prefix}${normalizedNew}${suffix}`;
|
|
@@ -3791,7 +3785,7 @@ class Document {
|
|
|
3791
3785
|
}
|
|
3792
3786
|
updateTableStyleShadingBulk(settings) {
|
|
3793
3787
|
let totalUpdated = 0;
|
|
3794
|
-
const defaultReplaceColors = [
|
|
3788
|
+
const defaultReplaceColors = ['A5A5A5', 'C0C0C0', 'D9D9D9', 'E7E6E6'];
|
|
3795
3789
|
const colorsToReplace = settings.replaceColors || defaultReplaceColors;
|
|
3796
3790
|
if (settings.headerShading) {
|
|
3797
3791
|
for (const oldColor of colorsToReplace) {
|
|
@@ -3799,7 +3793,7 @@ class Document {
|
|
|
3799
3793
|
}
|
|
3800
3794
|
}
|
|
3801
3795
|
if (settings.dataShading && settings.dataShading !== settings.headerShading) {
|
|
3802
|
-
const dataColors = [
|
|
3796
|
+
const dataColors = ['D9D9D9', 'E7E6E6', 'F2F2F2'];
|
|
3803
3797
|
for (const oldColor of dataColors) {
|
|
3804
3798
|
totalUpdated += this.updateTableStyleShading(oldColor, settings.dataShading);
|
|
3805
3799
|
}
|
|
@@ -3822,7 +3816,7 @@ class Document {
|
|
|
3822
3816
|
}
|
|
3823
3817
|
}
|
|
3824
3818
|
standardizeBulletSymbols(options) {
|
|
3825
|
-
const { bold = false, fontSize = 24, color =
|
|
3819
|
+
const { bold = false, fontSize = 24, color = '000000', font = 'Arial', } = options || {};
|
|
3826
3820
|
let listsUpdated = 0;
|
|
3827
3821
|
let levelsModified = 0;
|
|
3828
3822
|
const instances = this.numberingManager.getAllInstances();
|
|
@@ -3832,7 +3826,7 @@ class Document {
|
|
|
3832
3826
|
if (!abstractNum)
|
|
3833
3827
|
continue;
|
|
3834
3828
|
const level0 = abstractNum.getLevel(0);
|
|
3835
|
-
if (level0?.getFormat() !==
|
|
3829
|
+
if (level0?.getFormat() !== 'bullet')
|
|
3836
3830
|
continue;
|
|
3837
3831
|
for (let levelIndex = 0; levelIndex < 9; levelIndex++) {
|
|
3838
3832
|
const numLevel = abstractNum.getLevel(levelIndex);
|
|
@@ -3849,7 +3843,7 @@ class Document {
|
|
|
3849
3843
|
return { listsUpdated, levelsModified };
|
|
3850
3844
|
}
|
|
3851
3845
|
standardizeNumberedListPrefixes(options) {
|
|
3852
|
-
const { bold = false, fontSize = 24, color =
|
|
3846
|
+
const { bold = false, fontSize = 24, color = '000000', font = 'Verdana', } = options || {};
|
|
3853
3847
|
let listsUpdated = 0;
|
|
3854
3848
|
let levelsModified = 0;
|
|
3855
3849
|
const instances = this.numberingManager.getAllInstances();
|
|
@@ -3859,7 +3853,7 @@ class Document {
|
|
|
3859
3853
|
if (!abstractNum)
|
|
3860
3854
|
continue;
|
|
3861
3855
|
const level0 = abstractNum.getLevel(0);
|
|
3862
|
-
if (!level0 || level0.getFormat() ===
|
|
3856
|
+
if (!level0 || level0.getFormat() === 'bullet')
|
|
3863
3857
|
continue;
|
|
3864
3858
|
for (let levelIndex = 0; levelIndex < 9; levelIndex++) {
|
|
3865
3859
|
const numLevel = abstractNum.getLevel(levelIndex);
|
|
@@ -3876,39 +3870,38 @@ class Document {
|
|
|
3876
3870
|
return { listsUpdated, levelsModified };
|
|
3877
3871
|
}
|
|
3878
3872
|
standardizeAllHyperlinks(options) {
|
|
3879
|
-
const { font =
|
|
3873
|
+
const { font = 'Verdana', size = 12, color = '0000FF', underline = true } = options || {};
|
|
3880
3874
|
const hyperlinks = this.getHyperlinks();
|
|
3881
3875
|
for (const { hyperlink } of hyperlinks) {
|
|
3882
3876
|
hyperlink.setFormatting({
|
|
3883
3877
|
font: font,
|
|
3884
3878
|
size: size,
|
|
3885
3879
|
color: color,
|
|
3886
|
-
underline: underline ?
|
|
3880
|
+
underline: underline ? 'single' : false,
|
|
3887
3881
|
});
|
|
3888
3882
|
}
|
|
3889
3883
|
return hyperlinks.length;
|
|
3890
3884
|
}
|
|
3891
3885
|
applyH1(options) {
|
|
3892
|
-
return this.applyStyleToMatching(
|
|
3886
|
+
return this.applyStyleToMatching('Heading1', options, (style) => /^(heading\s*1|header\s*1|h1)$/i.test(style));
|
|
3893
3887
|
}
|
|
3894
3888
|
applyH2(options) {
|
|
3895
|
-
return this.applyStyleToMatching(
|
|
3889
|
+
return this.applyStyleToMatching('Heading2', options, (style) => /^(heading\s*2|header\s*2|h2)$/i.test(style));
|
|
3896
3890
|
}
|
|
3897
3891
|
applyH3(options) {
|
|
3898
|
-
return this.applyStyleToMatching(
|
|
3892
|
+
return this.applyStyleToMatching('Heading3', options, (style) => /^(heading\s*3|header\s*3|h3)$/i.test(style));
|
|
3899
3893
|
}
|
|
3900
3894
|
applyNormal(options) {
|
|
3901
3895
|
const targets = options?.paragraphs ||
|
|
3902
3896
|
this.getAllParagraphs().filter((p) => {
|
|
3903
3897
|
const style = p.getStyle();
|
|
3904
|
-
return
|
|
3905
|
-
!/^(heading|header|h\d|list|toc|tod|caution|table)/i.test(style));
|
|
3898
|
+
return !style || !/^(heading|header|h\d|list|toc|tod|caution|table)/i.test(style);
|
|
3906
3899
|
});
|
|
3907
3900
|
let count = 0;
|
|
3908
3901
|
for (const para of targets) {
|
|
3909
3902
|
if (para.isPreserved())
|
|
3910
3903
|
continue;
|
|
3911
|
-
para.setStyle(
|
|
3904
|
+
para.setStyle('Normal');
|
|
3912
3905
|
if (options?.keepProperties && options.keepProperties.length > 0) {
|
|
3913
3906
|
this.clearFormattingExcept(para, options.keepProperties);
|
|
3914
3907
|
}
|
|
@@ -3923,19 +3916,19 @@ class Document {
|
|
|
3923
3916
|
return count;
|
|
3924
3917
|
}
|
|
3925
3918
|
applyNumList(options) {
|
|
3926
|
-
return this.applyStyleToMatching(
|
|
3919
|
+
return this.applyStyleToMatching('ListParagraph', options, (style) => /^(list\s*number|numbered\s*list|list\s*paragraph)$/i.test(style));
|
|
3927
3920
|
}
|
|
3928
3921
|
applyBulletList(options) {
|
|
3929
|
-
return this.applyStyleToMatching(
|
|
3922
|
+
return this.applyStyleToMatching('ListParagraph', options, (style) => /^(list\s*bullet|bullet\s*list|list\s*paragraph)$/i.test(style));
|
|
3930
3923
|
}
|
|
3931
3924
|
applyTOC(options) {
|
|
3932
|
-
return this.applyStyleToMatching(
|
|
3925
|
+
return this.applyStyleToMatching('TOC', options, (style) => /^(toc|table\s*of\s*contents|toc\s*heading)$/i.test(style));
|
|
3933
3926
|
}
|
|
3934
3927
|
applyTOD(options) {
|
|
3935
|
-
return this.applyStyleToMatching(
|
|
3928
|
+
return this.applyStyleToMatching('TopOfDocument', options, (style) => /^(tod|top\s*of\s*document|document\s*top)$/i.test(style));
|
|
3936
3929
|
}
|
|
3937
3930
|
applyCaution(options) {
|
|
3938
|
-
return this.applyStyleToMatching(
|
|
3931
|
+
return this.applyStyleToMatching('Caution', options, (style) => /^(caution|warning|important|alert)$/i.test(style));
|
|
3939
3932
|
}
|
|
3940
3933
|
applyCellHeader(options) {
|
|
3941
3934
|
let count = 0;
|
|
@@ -3948,7 +3941,7 @@ class Document {
|
|
|
3948
3941
|
for (const para of cell.getParagraphs()) {
|
|
3949
3942
|
if (para.isPreserved())
|
|
3950
3943
|
continue;
|
|
3951
|
-
para.setStyle(
|
|
3944
|
+
para.setStyle('TableHeader');
|
|
3952
3945
|
if (options?.keepProperties && options.keepProperties.length > 0) {
|
|
3953
3946
|
this.clearFormattingExcept(para, options.keepProperties);
|
|
3954
3947
|
}
|
|
@@ -3984,12 +3977,12 @@ class Document {
|
|
|
3984
3977
|
run.setColor(options.color);
|
|
3985
3978
|
if (options.emphasis) {
|
|
3986
3979
|
options.emphasis.forEach((emp) => {
|
|
3987
|
-
if (emp ===
|
|
3980
|
+
if (emp === 'bold')
|
|
3988
3981
|
run.setBold(true);
|
|
3989
|
-
if (emp ===
|
|
3982
|
+
if (emp === 'italic')
|
|
3990
3983
|
run.setItalic(true);
|
|
3991
|
-
if (emp ===
|
|
3992
|
-
run.setUnderline(
|
|
3984
|
+
if (emp === 'underline')
|
|
3985
|
+
run.setUnderline('single');
|
|
3993
3986
|
});
|
|
3994
3987
|
}
|
|
3995
3988
|
}
|
|
@@ -4136,7 +4129,7 @@ class Document {
|
|
|
4136
4129
|
const tMatches = [...normalizedText.matchAll(tSwitchRegex)];
|
|
4137
4130
|
for (const match of tMatches) {
|
|
4138
4131
|
hasTableSwitch = true;
|
|
4139
|
-
const content = (match[1] ||
|
|
4132
|
+
const content = (match[1] || '').trim();
|
|
4140
4133
|
if (!content)
|
|
4141
4134
|
continue;
|
|
4142
4135
|
const rangeMatch = /^(\d+)-(\d+)$/.exec(content);
|
|
@@ -4150,7 +4143,7 @@ class Document {
|
|
|
4150
4143
|
continue;
|
|
4151
4144
|
}
|
|
4152
4145
|
const parts = content
|
|
4153
|
-
.split(
|
|
4146
|
+
.split(',')
|
|
4154
4147
|
.map((p) => p.trim())
|
|
4155
4148
|
.filter(Boolean);
|
|
4156
4149
|
for (let i = 0; i < parts.length; i += 2) {
|
|
@@ -4188,22 +4181,22 @@ class Document {
|
|
|
4188
4181
|
if (!match?.[1])
|
|
4189
4182
|
continue;
|
|
4190
4183
|
const fieldInstruction = match[1]
|
|
4191
|
-
.replace(/&/g,
|
|
4192
|
-
.replace(/</g,
|
|
4193
|
-
.replace(/>/g,
|
|
4184
|
+
.replace(/&/g, '&')
|
|
4185
|
+
.replace(/</g, '<')
|
|
4186
|
+
.replace(/>/g, '>')
|
|
4194
4187
|
.replace(/"/g, '"')
|
|
4195
4188
|
.replace(/'/g, "'");
|
|
4196
|
-
if (!fieldInstruction.includes(
|
|
4189
|
+
if (!fieldInstruction.includes('\\t')) {
|
|
4197
4190
|
continue;
|
|
4198
4191
|
}
|
|
4199
4192
|
const updatedInstruction = this.updateTOCStyleNames(fieldInstruction);
|
|
4200
4193
|
if (updatedInstruction !== fieldInstruction) {
|
|
4201
4194
|
const encodedInstruction = updatedInstruction
|
|
4202
|
-
.replace(/&/g,
|
|
4203
|
-
.replace(/</g,
|
|
4204
|
-
.replace(/>/g,
|
|
4205
|
-
.replace(/"/g,
|
|
4206
|
-
.replace(/'/g,
|
|
4195
|
+
.replace(/&/g, '&')
|
|
4196
|
+
.replace(/</g, '<')
|
|
4197
|
+
.replace(/>/g, '>')
|
|
4198
|
+
.replace(/"/g, '"')
|
|
4199
|
+
.replace(/'/g, ''');
|
|
4207
4200
|
const updatedInstrXml = `<w:instrText xml:space="preserve">${encodedInstruction}</w:instrText>`;
|
|
4208
4201
|
modifiedXml = modifiedXml.replace(match[0], updatedInstrXml);
|
|
4209
4202
|
this.logger.info(`Synced TOC field instruction: "${fieldInstruction.substring(0, 50)}..." → "${updatedInstruction.substring(0, 50)}..."`);
|
|
@@ -4216,7 +4209,7 @@ class Document {
|
|
|
4216
4209
|
return modifiedXml;
|
|
4217
4210
|
}
|
|
4218
4211
|
catch (error) {
|
|
4219
|
-
this.logger.error(
|
|
4212
|
+
this.logger.error('Error syncing TOC field instructions - document will save with original instructions', error instanceof Error
|
|
4220
4213
|
? { message: error.message, stack: error.stack }
|
|
4221
4214
|
: { error: String(error) });
|
|
4222
4215
|
return documentXml;
|
|
@@ -4228,12 +4221,12 @@ class Document {
|
|
|
4228
4221
|
return { xml, changed: false };
|
|
4229
4222
|
}
|
|
4230
4223
|
const fieldInstruction = instrMatch[1]
|
|
4231
|
-
.replace(/&/g,
|
|
4232
|
-
.replace(/</g,
|
|
4233
|
-
.replace(/>/g,
|
|
4224
|
+
.replace(/&/g, '&')
|
|
4225
|
+
.replace(/</g, '<')
|
|
4226
|
+
.replace(/>/g, '>')
|
|
4234
4227
|
.replace(/"/g, '"')
|
|
4235
4228
|
.replace(/'/g, "'");
|
|
4236
|
-
if (!fieldInstruction.includes(
|
|
4229
|
+
if (!fieldInstruction.includes('\\t')) {
|
|
4237
4230
|
return { xml, changed: false };
|
|
4238
4231
|
}
|
|
4239
4232
|
const updatedInstruction = this.updateTOCStyleNames(fieldInstruction);
|
|
@@ -4241,11 +4234,11 @@ class Document {
|
|
|
4241
4234
|
return { xml, changed: false };
|
|
4242
4235
|
}
|
|
4243
4236
|
const encodedInstruction = updatedInstruction
|
|
4244
|
-
.replace(/&/g,
|
|
4245
|
-
.replace(/</g,
|
|
4246
|
-
.replace(/>/g,
|
|
4247
|
-
.replace(/"/g,
|
|
4248
|
-
.replace(/'/g,
|
|
4237
|
+
.replace(/&/g, '&')
|
|
4238
|
+
.replace(/</g, '<')
|
|
4239
|
+
.replace(/>/g, '>')
|
|
4240
|
+
.replace(/"/g, '"')
|
|
4241
|
+
.replace(/'/g, ''');
|
|
4249
4242
|
const updatedXml = xml.replace(/<w:instrText[^>]*>[\s\S]*?<\/w:instrText>/, `<w:instrText xml:space="preserve">${encodedInstruction}</w:instrText>`);
|
|
4250
4243
|
return { xml: updatedXml, changed: true };
|
|
4251
4244
|
}
|
|
@@ -4259,7 +4252,10 @@ class Document {
|
|
|
4259
4252
|
const content = match[1];
|
|
4260
4253
|
if (!content)
|
|
4261
4254
|
continue;
|
|
4262
|
-
const parts = content
|
|
4255
|
+
const parts = content
|
|
4256
|
+
.split(',')
|
|
4257
|
+
.map((p) => p.trim())
|
|
4258
|
+
.filter(Boolean);
|
|
4263
4259
|
const updatedParts = [];
|
|
4264
4260
|
for (let i = 0; i < parts.length; i += 2) {
|
|
4265
4261
|
const styleName = parts[i];
|
|
@@ -4365,20 +4361,20 @@ class Document {
|
|
|
4365
4361
|
const levelSet = new Set(levels);
|
|
4366
4362
|
try {
|
|
4367
4363
|
const parsed = XMLParser_1.XMLParser.parseToObject(docXml, { trimValues: false });
|
|
4368
|
-
const document = parsed[
|
|
4364
|
+
const document = parsed['w:document'];
|
|
4369
4365
|
if (!document) {
|
|
4370
4366
|
return headings;
|
|
4371
4367
|
}
|
|
4372
|
-
const body = document[
|
|
4368
|
+
const body = document['w:body'];
|
|
4373
4369
|
if (!body) {
|
|
4374
4370
|
return headings;
|
|
4375
4371
|
}
|
|
4376
4372
|
const extractHeading = (para) => {
|
|
4377
|
-
const pPr = para[
|
|
4378
|
-
if (!pPr?.[
|
|
4373
|
+
const pPr = para['w:pPr'];
|
|
4374
|
+
if (!pPr?.['w:pStyle']) {
|
|
4379
4375
|
return;
|
|
4380
4376
|
}
|
|
4381
|
-
const styleVal = pPr[
|
|
4377
|
+
const styleVal = pPr['w:pStyle']['@_w:val'];
|
|
4382
4378
|
if (!styleVal) {
|
|
4383
4379
|
return;
|
|
4384
4380
|
}
|
|
@@ -4390,39 +4386,38 @@ class Document {
|
|
|
4390
4386
|
if (!levelSet.has(headingLevel)) {
|
|
4391
4387
|
return;
|
|
4392
4388
|
}
|
|
4393
|
-
let bookmark =
|
|
4394
|
-
const bookmarkStart = para[
|
|
4389
|
+
let bookmark = '';
|
|
4390
|
+
const bookmarkStart = para['w:bookmarkStart'];
|
|
4395
4391
|
if (bookmarkStart) {
|
|
4396
|
-
const bookmarkArray = Array.isArray(bookmarkStart)
|
|
4397
|
-
? bookmarkStart
|
|
4398
|
-
: [bookmarkStart];
|
|
4392
|
+
const bookmarkArray = Array.isArray(bookmarkStart) ? bookmarkStart : [bookmarkStart];
|
|
4399
4393
|
for (const bm of bookmarkArray) {
|
|
4400
|
-
const bmName = bm[
|
|
4401
|
-
if (bmName &&
|
|
4394
|
+
const bmName = bm['@_w:name'];
|
|
4395
|
+
if (bmName &&
|
|
4396
|
+
(bmName.toLowerCase().includes('_heading') || bmName.toLowerCase().includes('_toc'))) {
|
|
4402
4397
|
bookmark = bmName;
|
|
4403
4398
|
break;
|
|
4404
4399
|
}
|
|
4405
4400
|
}
|
|
4406
4401
|
if (!bookmark && bookmarkArray.length > 0) {
|
|
4407
4402
|
const firstBm = bookmarkArray[0];
|
|
4408
|
-
const bmName = firstBm[
|
|
4403
|
+
const bmName = firstBm['@_w:name'];
|
|
4409
4404
|
if (bmName) {
|
|
4410
4405
|
bookmark = bmName;
|
|
4411
4406
|
}
|
|
4412
4407
|
}
|
|
4413
4408
|
}
|
|
4414
|
-
let text =
|
|
4415
|
-
const runs = para[
|
|
4409
|
+
let text = '';
|
|
4410
|
+
const runs = para['w:r'];
|
|
4416
4411
|
if (runs) {
|
|
4417
4412
|
const runArray = Array.isArray(runs) ? runs : [runs];
|
|
4418
4413
|
for (const run of runArray) {
|
|
4419
|
-
const textElement = run[
|
|
4414
|
+
const textElement = run['w:t'];
|
|
4420
4415
|
if (textElement) {
|
|
4421
|
-
if (typeof textElement ===
|
|
4416
|
+
if (typeof textElement === 'string') {
|
|
4422
4417
|
text += textElement;
|
|
4423
4418
|
}
|
|
4424
|
-
else if (textElement[
|
|
4425
|
-
text += textElement[
|
|
4419
|
+
else if (textElement['#text']) {
|
|
4420
|
+
text += textElement['#text'];
|
|
4426
4421
|
}
|
|
4427
4422
|
}
|
|
4428
4423
|
}
|
|
@@ -4440,33 +4435,31 @@ class Document {
|
|
|
4440
4435
|
bookmark: bookmark,
|
|
4441
4436
|
});
|
|
4442
4437
|
};
|
|
4443
|
-
const paragraphs = body[
|
|
4438
|
+
const paragraphs = body['w:p'];
|
|
4444
4439
|
if (paragraphs) {
|
|
4445
4440
|
const paraArray = Array.isArray(paragraphs) ? paragraphs : [paragraphs];
|
|
4446
4441
|
for (const para of paraArray) {
|
|
4447
4442
|
extractHeading(para);
|
|
4448
4443
|
}
|
|
4449
4444
|
}
|
|
4450
|
-
const tables = body[
|
|
4445
|
+
const tables = body['w:tbl'];
|
|
4451
4446
|
if (tables) {
|
|
4452
4447
|
const tableArray = Array.isArray(tables) ? tables : [tables];
|
|
4453
4448
|
for (const table of tableArray) {
|
|
4454
|
-
const rows = table[
|
|
4449
|
+
const rows = table['w:tr'];
|
|
4455
4450
|
if (!rows)
|
|
4456
4451
|
continue;
|
|
4457
4452
|
const rowArray = Array.isArray(rows) ? rows : [rows];
|
|
4458
4453
|
for (const row of rowArray) {
|
|
4459
|
-
const cells = row[
|
|
4454
|
+
const cells = row['w:tc'];
|
|
4460
4455
|
if (!cells)
|
|
4461
4456
|
continue;
|
|
4462
4457
|
const cellArray = Array.isArray(cells) ? cells : [cells];
|
|
4463
4458
|
for (const cell of cellArray) {
|
|
4464
|
-
const cellParas = cell[
|
|
4459
|
+
const cellParas = cell['w:p'];
|
|
4465
4460
|
if (!cellParas)
|
|
4466
4461
|
continue;
|
|
4467
|
-
const cellParaArray = Array.isArray(cellParas)
|
|
4468
|
-
? cellParas
|
|
4469
|
-
: [cellParas];
|
|
4462
|
+
const cellParaArray = Array.isArray(cellParas) ? cellParas : [cellParas];
|
|
4470
4463
|
for (const para of cellParaArray) {
|
|
4471
4464
|
extractHeading(para);
|
|
4472
4465
|
}
|
|
@@ -4476,7 +4469,7 @@ class Document {
|
|
|
4476
4469
|
}
|
|
4477
4470
|
}
|
|
4478
4471
|
catch (error) {
|
|
4479
|
-
logger_1.defaultLogger.error(
|
|
4472
|
+
logger_1.defaultLogger.error('Error parsing document.xml for headings:', error instanceof Error
|
|
4480
4473
|
? { message: error.message, stack: error.stack }
|
|
4481
4474
|
: { error: String(error) });
|
|
4482
4475
|
}
|
|
@@ -4512,99 +4505,95 @@ class Document {
|
|
|
4512
4505
|
}
|
|
4513
4506
|
generateTOCXML(headings, originalInstrText) {
|
|
4514
4507
|
const sdtId = Math.floor(Math.random() * 2000000000) - 1000000000;
|
|
4515
|
-
let tocXml =
|
|
4516
|
-
tocXml +=
|
|
4508
|
+
let tocXml = '<w:sdt>';
|
|
4509
|
+
tocXml += '<w:sdtPr>';
|
|
4517
4510
|
tocXml += `<w:id w:val="${sdtId}"/>`;
|
|
4518
|
-
tocXml +=
|
|
4511
|
+
tocXml += '<w:docPartObj>';
|
|
4519
4512
|
tocXml += '<w:docPartGallery w:val="Table of Contents"/>';
|
|
4520
4513
|
tocXml += '<w:docPartUnique w:val="1"/>';
|
|
4521
|
-
tocXml +=
|
|
4522
|
-
tocXml +=
|
|
4523
|
-
tocXml +=
|
|
4514
|
+
tocXml += '</w:docPartObj>';
|
|
4515
|
+
tocXml += '</w:sdtPr>';
|
|
4516
|
+
tocXml += '<w:sdtContent>';
|
|
4524
4517
|
const minLevel = headings.length > 0 ? Math.min(...headings.map((h) => h.level)) : 1;
|
|
4525
|
-
tocXml +=
|
|
4526
|
-
tocXml +=
|
|
4527
|
-
tocXml +=
|
|
4528
|
-
'<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
|
|
4518
|
+
tocXml += '<w:p>';
|
|
4519
|
+
tocXml += '<w:pPr>';
|
|
4520
|
+
tocXml += '<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
|
|
4529
4521
|
if (headings.length > 0 && headings[0]) {
|
|
4530
4522
|
const firstIndent = (headings[0].level - minLevel) * 360;
|
|
4531
4523
|
if (firstIndent > 0) {
|
|
4532
4524
|
tocXml += `<w:ind w:left="${firstIndent}"/>`;
|
|
4533
4525
|
}
|
|
4534
4526
|
}
|
|
4535
|
-
tocXml +=
|
|
4527
|
+
tocXml += '</w:pPr>';
|
|
4536
4528
|
tocXml += '<w:r><w:fldChar w:fldCharType="begin"/></w:r>';
|
|
4537
|
-
tocXml +=
|
|
4529
|
+
tocXml += '<w:r>';
|
|
4538
4530
|
tocXml += `<w:instrText xml:space="preserve">${this.escapeXml(originalInstrText)}</w:instrText>`;
|
|
4539
|
-
tocXml +=
|
|
4531
|
+
tocXml += '</w:r>';
|
|
4540
4532
|
tocXml += '<w:r><w:fldChar w:fldCharType="separate"/></w:r>';
|
|
4541
4533
|
if (headings.length > 0 && headings[0]) {
|
|
4542
4534
|
tocXml += this.buildTOCEntryXML(headings[0]);
|
|
4543
4535
|
}
|
|
4544
|
-
tocXml +=
|
|
4536
|
+
tocXml += '</w:p>';
|
|
4545
4537
|
for (let i = 1; i < headings.length; i++) {
|
|
4546
4538
|
const heading = headings[i];
|
|
4547
4539
|
if (!heading)
|
|
4548
4540
|
continue;
|
|
4549
|
-
tocXml +=
|
|
4550
|
-
tocXml +=
|
|
4551
|
-
tocXml +=
|
|
4552
|
-
'<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
|
|
4541
|
+
tocXml += '<w:p>';
|
|
4542
|
+
tocXml += '<w:pPr>';
|
|
4543
|
+
tocXml += '<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
|
|
4553
4544
|
const indent = (heading.level - minLevel) * 360;
|
|
4554
4545
|
if (indent > 0) {
|
|
4555
4546
|
tocXml += `<w:ind w:left="${indent}"/>`;
|
|
4556
4547
|
}
|
|
4557
|
-
tocXml +=
|
|
4548
|
+
tocXml += '</w:pPr>';
|
|
4558
4549
|
tocXml += this.buildTOCEntryXML(heading);
|
|
4559
|
-
tocXml +=
|
|
4550
|
+
tocXml += '</w:p>';
|
|
4560
4551
|
}
|
|
4561
|
-
tocXml +=
|
|
4562
|
-
tocXml +=
|
|
4563
|
-
tocXml +=
|
|
4564
|
-
|
|
4565
|
-
tocXml += "</w:pPr>";
|
|
4552
|
+
tocXml += '<w:p>';
|
|
4553
|
+
tocXml += '<w:pPr>';
|
|
4554
|
+
tocXml += '<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
|
|
4555
|
+
tocXml += '</w:pPr>';
|
|
4566
4556
|
tocXml += '<w:r><w:fldChar w:fldCharType="end"/></w:r>';
|
|
4567
|
-
tocXml +=
|
|
4568
|
-
tocXml +=
|
|
4569
|
-
tocXml +=
|
|
4557
|
+
tocXml += '</w:p>';
|
|
4558
|
+
tocXml += '</w:sdtContent>';
|
|
4559
|
+
tocXml += '</w:sdt>';
|
|
4570
4560
|
return tocXml;
|
|
4571
4561
|
}
|
|
4572
4562
|
buildTOCEntryXML(heading) {
|
|
4573
4563
|
const escapedText = this.escapeXml(heading.text);
|
|
4574
|
-
let xml =
|
|
4564
|
+
let xml = '';
|
|
4575
4565
|
xml += `<w:hyperlink w:anchor="${this.escapeXml(heading.bookmark)}">`;
|
|
4576
|
-
xml +=
|
|
4577
|
-
xml +=
|
|
4578
|
-
xml +=
|
|
4579
|
-
'<w:rFonts w:ascii="Verdana" w:hAnsi="Verdana" w:cs="Verdana" w:eastAsia="Verdana"/>';
|
|
4566
|
+
xml += '<w:r>';
|
|
4567
|
+
xml += '<w:rPr>';
|
|
4568
|
+
xml += '<w:rFonts w:ascii="Verdana" w:hAnsi="Verdana" w:cs="Verdana" w:eastAsia="Verdana"/>';
|
|
4580
4569
|
xml += '<w:color w:val="0000FF"/>';
|
|
4581
4570
|
xml += '<w:sz w:val="24"/>';
|
|
4582
4571
|
xml += '<w:szCs w:val="24"/>';
|
|
4583
4572
|
xml += '<w:u w:val="single"/>';
|
|
4584
|
-
xml +=
|
|
4573
|
+
xml += '</w:rPr>';
|
|
4585
4574
|
xml += `<w:t xml:space="preserve">${escapedText}</w:t>`;
|
|
4586
|
-
xml +=
|
|
4587
|
-
xml +=
|
|
4575
|
+
xml += '</w:r>';
|
|
4576
|
+
xml += '</w:hyperlink>';
|
|
4588
4577
|
return xml;
|
|
4589
4578
|
}
|
|
4590
4579
|
escapeXml(text) {
|
|
4591
4580
|
return text
|
|
4592
|
-
.replace(/&/g,
|
|
4593
|
-
.replace(/</g,
|
|
4594
|
-
.replace(/>/g,
|
|
4595
|
-
.replace(/"/g,
|
|
4596
|
-
.replace(/'/g,
|
|
4581
|
+
.replace(/&/g, '&')
|
|
4582
|
+
.replace(/</g, '<')
|
|
4583
|
+
.replace(/>/g, '>')
|
|
4584
|
+
.replace(/"/g, '"')
|
|
4585
|
+
.replace(/'/g, ''');
|
|
4597
4586
|
}
|
|
4598
4587
|
async populateTOCsInFile(filePath) {
|
|
4599
4588
|
const handler = new ZipHandler_1.ZipHandler();
|
|
4600
4589
|
await handler.load(filePath);
|
|
4601
|
-
const docXml = handler.getFileAsString(
|
|
4590
|
+
const docXml = handler.getFileAsString('word/document.xml');
|
|
4602
4591
|
if (!docXml) {
|
|
4603
4592
|
return 0;
|
|
4604
4593
|
}
|
|
4605
4594
|
const modifiedXml = this.populateAllTOCsInXML(docXml);
|
|
4606
4595
|
if (modifiedXml !== docXml) {
|
|
4607
|
-
handler.updateFile(
|
|
4596
|
+
handler.updateFile('word/document.xml', modifiedXml);
|
|
4608
4597
|
await handler.save(filePath);
|
|
4609
4598
|
const tocRegex = /<w:sdt>[\s\S]*?<w:docPartGallery w:val="Table of Contents"[\s\S]*?<\/w:sdt>/g;
|
|
4610
4599
|
const matches = Array.from(docXml.matchAll(tocRegex));
|
|
@@ -4624,9 +4613,9 @@ class Document {
|
|
|
4624
4613
|
if (!instrMatch?.[1])
|
|
4625
4614
|
continue;
|
|
4626
4615
|
const fieldInstruction = instrMatch[1]
|
|
4627
|
-
.replace(/&/g,
|
|
4628
|
-
.replace(/</g,
|
|
4629
|
-
.replace(/>/g,
|
|
4616
|
+
.replace(/&/g, '&')
|
|
4617
|
+
.replace(/</g, '<')
|
|
4618
|
+
.replace(/>/g, '>')
|
|
4630
4619
|
.replace(/"/g, '"')
|
|
4631
4620
|
.replace(/'/g, "'");
|
|
4632
4621
|
const levels = this.parseTOCFieldInstruction(fieldInstruction);
|
|
@@ -4637,7 +4626,7 @@ class Document {
|
|
|
4637
4626
|
modifiedXml = modifiedXml.replace(tocXml, newTocXml);
|
|
4638
4627
|
}
|
|
4639
4628
|
catch (error) {
|
|
4640
|
-
this.logger.error(
|
|
4629
|
+
this.logger.error('Error populating SDT TOC', error instanceof Error
|
|
4641
4630
|
? { message: error.message, stack: error.stack }
|
|
4642
4631
|
: { error: String(error) });
|
|
4643
4632
|
continue;
|
|
@@ -4654,9 +4643,9 @@ class Document {
|
|
|
4654
4643
|
if (!instrText)
|
|
4655
4644
|
continue;
|
|
4656
4645
|
const fieldInstruction = instrText
|
|
4657
|
-
.replace(/&/g,
|
|
4658
|
-
.replace(/</g,
|
|
4659
|
-
.replace(/>/g,
|
|
4646
|
+
.replace(/&/g, '&')
|
|
4647
|
+
.replace(/</g, '<')
|
|
4648
|
+
.replace(/>/g, '>')
|
|
4660
4649
|
.replace(/"/g, '"')
|
|
4661
4650
|
.replace(/'/g, "'");
|
|
4662
4651
|
const levels = this.parseTOCFieldInstruction(fieldInstruction);
|
|
@@ -4676,7 +4665,7 @@ class Document {
|
|
|
4676
4665
|
this.logger.info(`Populated simple TOC with ${headings.length} heading entries`);
|
|
4677
4666
|
}
|
|
4678
4667
|
catch (error) {
|
|
4679
|
-
this.logger.error(
|
|
4668
|
+
this.logger.error('Error populating simple TOC', error instanceof Error
|
|
4680
4669
|
? { message: error.message, stack: error.stack }
|
|
4681
4670
|
: { error: String(error) });
|
|
4682
4671
|
continue;
|
|
@@ -4690,10 +4679,10 @@ class Document {
|
|
|
4690
4679
|
for (const heading of headings) {
|
|
4691
4680
|
const tocStyle = `TOC${heading.level}`;
|
|
4692
4681
|
const escapedText = heading.text
|
|
4693
|
-
.replace(/&/g,
|
|
4694
|
-
.replace(/</g,
|
|
4695
|
-
.replace(/>/g,
|
|
4696
|
-
.replace(/"/g,
|
|
4682
|
+
.replace(/&/g, '&')
|
|
4683
|
+
.replace(/</g, '<')
|
|
4684
|
+
.replace(/>/g, '>')
|
|
4685
|
+
.replace(/"/g, '"');
|
|
4697
4686
|
entries.push(`<w:p>` +
|
|
4698
4687
|
`<w:pPr><w:pStyle w:val="${tocStyle}"/></w:pPr>` +
|
|
4699
4688
|
`<w:hyperlink w:anchor="${heading.bookmark}" w:history="1">` +
|
|
@@ -4703,17 +4692,17 @@ class Document {
|
|
|
4703
4692
|
`</w:p>`);
|
|
4704
4693
|
}
|
|
4705
4694
|
const escapedInstruction = fieldInstruction
|
|
4706
|
-
.replace(/&/g,
|
|
4707
|
-
.replace(/</g,
|
|
4708
|
-
.replace(/>/g,
|
|
4709
|
-
.replace(/"/g,
|
|
4695
|
+
.replace(/&/g, '&')
|
|
4696
|
+
.replace(/</g, '<')
|
|
4697
|
+
.replace(/>/g, '>')
|
|
4698
|
+
.replace(/"/g, '"');
|
|
4710
4699
|
return (`<w:p>` +
|
|
4711
4700
|
`<w:pPr><w:pStyle w:val="TOC2"/></w:pPr>` +
|
|
4712
4701
|
`<w:r><w:fldChar w:fldCharType="begin"/></w:r>` +
|
|
4713
4702
|
`<w:r><w:instrText xml:space="preserve">${escapedInstruction}</w:instrText></w:r>` +
|
|
4714
4703
|
`<w:r><w:fldChar w:fldCharType="separate"/></w:r>` +
|
|
4715
4704
|
`</w:p>` +
|
|
4716
|
-
entries.join(
|
|
4705
|
+
entries.join('') +
|
|
4717
4706
|
`<w:p>` +
|
|
4718
4707
|
`<w:pPr><w:pStyle w:val="TOC2"/></w:pPr>` +
|
|
4719
4708
|
`<w:r><w:fldChar w:fldCharType="end"/></w:r>` +
|
|
@@ -4744,39 +4733,39 @@ class Document {
|
|
|
4744
4733
|
setHeader(header) {
|
|
4745
4734
|
const relationship = this.relationshipManager.addHeader(`${header.getFilename(1)}`);
|
|
4746
4735
|
this.headerFooterManager.registerHeader(header, relationship.getId());
|
|
4747
|
-
this.section.setHeaderReference(
|
|
4736
|
+
this.section.setHeaderReference('default', relationship.getId());
|
|
4748
4737
|
return this;
|
|
4749
4738
|
}
|
|
4750
4739
|
setFirstPageHeader(header) {
|
|
4751
4740
|
this.section.setTitlePage(true);
|
|
4752
4741
|
const relationship = this.relationshipManager.addHeader(`${header.getFilename(this.headerFooterManager.getHeaderCount() + 1)}`);
|
|
4753
4742
|
this.headerFooterManager.registerHeader(header, relationship.getId());
|
|
4754
|
-
this.section.setHeaderReference(
|
|
4743
|
+
this.section.setHeaderReference('first', relationship.getId());
|
|
4755
4744
|
return this;
|
|
4756
4745
|
}
|
|
4757
4746
|
setEvenPageHeader(header) {
|
|
4758
4747
|
const relationship = this.relationshipManager.addHeader(`${header.getFilename(this.headerFooterManager.getHeaderCount() + 1)}`);
|
|
4759
4748
|
this.headerFooterManager.registerHeader(header, relationship.getId());
|
|
4760
|
-
this.section.setHeaderReference(
|
|
4749
|
+
this.section.setHeaderReference('even', relationship.getId());
|
|
4761
4750
|
return this;
|
|
4762
4751
|
}
|
|
4763
4752
|
setFooter(footer) {
|
|
4764
4753
|
const relationship = this.relationshipManager.addFooter(`${footer.getFilename(1)}`);
|
|
4765
4754
|
this.headerFooterManager.registerFooter(footer, relationship.getId());
|
|
4766
|
-
this.section.setFooterReference(
|
|
4755
|
+
this.section.setFooterReference('default', relationship.getId());
|
|
4767
4756
|
return this;
|
|
4768
4757
|
}
|
|
4769
4758
|
setFirstPageFooter(footer) {
|
|
4770
4759
|
this.section.setTitlePage(true);
|
|
4771
4760
|
const relationship = this.relationshipManager.addFooter(`${footer.getFilename(this.headerFooterManager.getFooterCount() + 1)}`);
|
|
4772
4761
|
this.headerFooterManager.registerFooter(footer, relationship.getId());
|
|
4773
|
-
this.section.setFooterReference(
|
|
4762
|
+
this.section.setFooterReference('first', relationship.getId());
|
|
4774
4763
|
return this;
|
|
4775
4764
|
}
|
|
4776
4765
|
setEvenPageFooter(footer) {
|
|
4777
4766
|
const relationship = this.relationshipManager.addFooter(`${footer.getFilename(this.headerFooterManager.getFooterCount() + 1)}`);
|
|
4778
4767
|
this.headerFooterManager.registerFooter(footer, relationship.getId());
|
|
4779
|
-
this.section.setFooterReference(
|
|
4768
|
+
this.section.setFooterReference('even', relationship.getId());
|
|
4780
4769
|
return this;
|
|
4781
4770
|
}
|
|
4782
4771
|
getHeaderFooterManager() {
|
|
@@ -4900,20 +4889,20 @@ class Document {
|
|
|
4900
4889
|
}
|
|
4901
4890
|
updateRelationships() {
|
|
4902
4891
|
const xml = this.relationshipManager.generateXml();
|
|
4903
|
-
this.zipHandler.updateFile(
|
|
4892
|
+
this.zipHandler.updateFile('word/_rels/document.xml.rels', xml);
|
|
4904
4893
|
}
|
|
4905
4894
|
saveComments() {
|
|
4906
4895
|
if (this._commentsModified) {
|
|
4907
4896
|
if (this.commentManager.getCount() > 0) {
|
|
4908
4897
|
const xml = this.commentManager.generateCommentsXml();
|
|
4909
|
-
this.zipHandler.addFile(
|
|
4898
|
+
this.zipHandler.addFile('word/comments.xml', xml);
|
|
4910
4899
|
const existingRels = this.relationshipManager.getRelationshipsByType(Relationship_1.RelationshipType.COMMENTS);
|
|
4911
4900
|
if (existingRels.length === 0) {
|
|
4912
4901
|
this.relationshipManager.addComments();
|
|
4913
4902
|
}
|
|
4914
4903
|
}
|
|
4915
4904
|
else {
|
|
4916
|
-
this.zipHandler.removeFile(
|
|
4905
|
+
this.zipHandler.removeFile('word/comments.xml');
|
|
4917
4906
|
const existingRels = this.relationshipManager.getRelationshipsByType(Relationship_1.RelationshipType.COMMENTS);
|
|
4918
4907
|
for (const rel of existingRels) {
|
|
4919
4908
|
this.relationshipManager.removeRelationship(rel.getId());
|
|
@@ -4922,7 +4911,7 @@ class Document {
|
|
|
4922
4911
|
this.removeCommentCompanionFiles();
|
|
4923
4912
|
}
|
|
4924
4913
|
else if (this._originalCommentsXml) {
|
|
4925
|
-
this.zipHandler.addFile(
|
|
4914
|
+
this.zipHandler.addFile('word/comments.xml', this._originalCommentsXml);
|
|
4926
4915
|
for (const [path, content] of this._originalCommentCompanionFiles) {
|
|
4927
4916
|
this.zipHandler.addFile(path, content);
|
|
4928
4917
|
}
|
|
@@ -4933,7 +4922,7 @@ class Document {
|
|
|
4933
4922
|
}
|
|
4934
4923
|
else if (this.commentManager.getCount() > 0) {
|
|
4935
4924
|
const xml = this.commentManager.generateCommentsXml();
|
|
4936
|
-
this.zipHandler.addFile(
|
|
4925
|
+
this.zipHandler.addFile('word/comments.xml', xml);
|
|
4937
4926
|
const existingRels = this.relationshipManager.getRelationshipsByType(Relationship_1.RelationshipType.COMMENTS);
|
|
4938
4927
|
if (existingRels.length === 0) {
|
|
4939
4928
|
this.relationshipManager.addComments();
|
|
@@ -4941,7 +4930,11 @@ class Document {
|
|
|
4941
4930
|
}
|
|
4942
4931
|
}
|
|
4943
4932
|
removeCommentCompanionFiles() {
|
|
4944
|
-
const companionPaths = [
|
|
4933
|
+
const companionPaths = [
|
|
4934
|
+
types_1.DOCX_PATHS.COMMENTS_EXTENDED,
|
|
4935
|
+
types_1.DOCX_PATHS.COMMENTS_IDS,
|
|
4936
|
+
types_1.DOCX_PATHS.COMMENTS_EXTENSIBLE,
|
|
4937
|
+
];
|
|
4945
4938
|
for (const filePath of companionPaths) {
|
|
4946
4939
|
this.zipHandler.removeFile(filePath);
|
|
4947
4940
|
const fileName = filePath.replace('word/', '');
|
|
@@ -4960,7 +4953,7 @@ class Document {
|
|
|
4960
4953
|
if (existingRels.length === 0) {
|
|
4961
4954
|
this.relationshipManager.addFootnotes();
|
|
4962
4955
|
}
|
|
4963
|
-
this.generatePartLevelHyperlinkRels(this.footnoteManager.getAllFootnotes().flatMap(fn => fn.getParagraphs()), 'word/_rels/footnotes.xml.rels');
|
|
4956
|
+
this.generatePartLevelHyperlinkRels(this.footnoteManager.getAllFootnotes().flatMap((fn) => fn.getParagraphs()), 'word/_rels/footnotes.xml.rels');
|
|
4964
4957
|
}
|
|
4965
4958
|
else if (this._originalFootnotesXml) {
|
|
4966
4959
|
this.zipHandler.addFile(types_1.DOCX_PATHS.FOOTNOTES, this._originalFootnotesXml);
|
|
@@ -4978,7 +4971,7 @@ class Document {
|
|
|
4978
4971
|
if (existingRels.length === 0) {
|
|
4979
4972
|
this.relationshipManager.addEndnotes();
|
|
4980
4973
|
}
|
|
4981
|
-
this.generatePartLevelHyperlinkRels(this.endnoteManager.getAllEndnotes().flatMap(en => en.getParagraphs()), 'word/_rels/endnotes.xml.rels');
|
|
4974
|
+
this.generatePartLevelHyperlinkRels(this.endnoteManager.getAllEndnotes().flatMap((en) => en.getParagraphs()), 'word/_rels/endnotes.xml.rels');
|
|
4982
4975
|
}
|
|
4983
4976
|
else if (this._originalEndnotesXml) {
|
|
4984
4977
|
this.zipHandler.addFile(types_1.DOCX_PATHS.ENDNOTES, this._originalEndnotesXml);
|
|
@@ -5030,7 +5023,8 @@ class Document {
|
|
|
5030
5023
|
}
|
|
5031
5024
|
if (hyperlinkRels.length > 0) {
|
|
5032
5025
|
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
|
|
5033
|
-
xml +=
|
|
5026
|
+
xml +=
|
|
5027
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">\n';
|
|
5034
5028
|
for (const rel of hyperlinkRels) {
|
|
5035
5029
|
const escapedId = XMLBuilder_1.XMLBuilder.escapeXmlAttribute(rel.id);
|
|
5036
5030
|
const escapedUrl = XMLBuilder_1.XMLBuilder.escapeXmlAttribute(rel.url);
|
|
@@ -5087,10 +5081,16 @@ class Document {
|
|
|
5087
5081
|
}
|
|
5088
5082
|
if (missingAuthors.length === 0)
|
|
5089
5083
|
return;
|
|
5090
|
-
const personElements = missingAuthors
|
|
5091
|
-
|
|
5084
|
+
const personElements = missingAuthors
|
|
5085
|
+
.map((author) => {
|
|
5086
|
+
const escapedAuthor = author
|
|
5087
|
+
.replace(/&/g, '&')
|
|
5088
|
+
.replace(/"/g, '"')
|
|
5089
|
+
.replace(/</g, '<')
|
|
5090
|
+
.replace(/>/g, '>');
|
|
5092
5091
|
return `<w15:person w15:author="${escapedAuthor}"><w15:presenceInfo w15:providerId="None" w15:userId="${escapedAuthor}"/></w15:person>`;
|
|
5093
|
-
})
|
|
5092
|
+
})
|
|
5093
|
+
.join('');
|
|
5094
5094
|
if (existingPeopleXml) {
|
|
5095
5095
|
const updatedXml = existingPeopleXml.replace('</w15:people>', `${personElements}</w15:people>`);
|
|
5096
5096
|
this.zipHandler.updateFile('word/people.xml', updatedXml);
|
|
@@ -5104,7 +5104,10 @@ class Document {
|
|
|
5104
5104
|
if (existingPeopleRels.length === 0) {
|
|
5105
5105
|
this.relationshipManager.addPeople();
|
|
5106
5106
|
}
|
|
5107
|
-
this.logger.info('Updated people.xml with missing authors', {
|
|
5107
|
+
this.logger.info('Updated people.xml with missing authors', {
|
|
5108
|
+
added: missingAuthors.length,
|
|
5109
|
+
authors: missingAuthors,
|
|
5110
|
+
});
|
|
5108
5111
|
}
|
|
5109
5112
|
collectAuthorsFromTable(table, authors) {
|
|
5110
5113
|
for (let r = 0; r < table.getRowCount(); r++) {
|
|
@@ -5141,7 +5144,7 @@ class Document {
|
|
|
5141
5144
|
Object.keys(this.properties.customProperties).length > 0) {
|
|
5142
5145
|
const customXml = this.generator.generateCustomProps(this.properties.customProperties);
|
|
5143
5146
|
if (customXml) {
|
|
5144
|
-
this.zipHandler.addFile(
|
|
5147
|
+
this.zipHandler.addFile('docProps/custom.xml', customXml);
|
|
5145
5148
|
}
|
|
5146
5149
|
}
|
|
5147
5150
|
}
|
|
@@ -5159,8 +5162,7 @@ class Document {
|
|
|
5159
5162
|
return { defaults, overrides };
|
|
5160
5163
|
}
|
|
5161
5164
|
updateContentTypesWithImagesHeadersFootersAndComments() {
|
|
5162
|
-
const hasCustomProps = this.properties.customProperties &&
|
|
5163
|
-
Object.keys(this.properties.customProperties).length > 0;
|
|
5165
|
+
const hasCustomProps = this.properties.customProperties && Object.keys(this.properties.customProperties).length > 0;
|
|
5164
5166
|
const contentTypes = this.generator.generateContentTypesWithImagesHeadersFootersAndComments(this.imageManager, this.headerFooterManager, this.commentManager, this.zipHandler, undefined, hasCustomProps, this._originalContentTypes, this.footnoteManager, this.endnoteManager);
|
|
5165
5167
|
this.zipHandler.updateFile(types_1.DOCX_PATHS.CONTENT_TYPES, contentTypes);
|
|
5166
5168
|
}
|
|
@@ -5180,14 +5182,12 @@ class Document {
|
|
|
5180
5182
|
return this.bookmarkManager.hasBookmark(name);
|
|
5181
5183
|
}
|
|
5182
5184
|
addBookmarkToParagraph(paragraph, bookmarkOrName) {
|
|
5183
|
-
const bookmark = typeof bookmarkOrName ===
|
|
5184
|
-
? this.createBookmark(bookmarkOrName)
|
|
5185
|
-
: bookmarkOrName;
|
|
5185
|
+
const bookmark = typeof bookmarkOrName === 'string' ? this.createBookmark(bookmarkOrName) : bookmarkOrName;
|
|
5186
5186
|
paragraph.addBookmark(bookmark);
|
|
5187
5187
|
return bookmark;
|
|
5188
5188
|
}
|
|
5189
5189
|
addTopBookmark() {
|
|
5190
|
-
const BOOKMARK_NAME =
|
|
5190
|
+
const BOOKMARK_NAME = '_top';
|
|
5191
5191
|
let bookmark = this.getBookmark(BOOKMARK_NAME);
|
|
5192
5192
|
if (!bookmark) {
|
|
5193
5193
|
bookmark = new Bookmark_1.Bookmark({
|
|
@@ -5268,7 +5268,7 @@ class Document {
|
|
|
5268
5268
|
return location;
|
|
5269
5269
|
}
|
|
5270
5270
|
trackInsertion(paragraph, author, text, date) {
|
|
5271
|
-
const revision = this.createRevisionFromText(
|
|
5271
|
+
const revision = this.createRevisionFromText('insert', author, text, date);
|
|
5272
5272
|
const location = this.createRevisionLocation(paragraph);
|
|
5273
5273
|
if (location) {
|
|
5274
5274
|
location.runIndex = paragraph.getRuns().length;
|
|
@@ -5278,7 +5278,7 @@ class Document {
|
|
|
5278
5278
|
return revision;
|
|
5279
5279
|
}
|
|
5280
5280
|
trackDeletion(paragraph, author, text, date) {
|
|
5281
|
-
const revision = this.createRevisionFromText(
|
|
5281
|
+
const revision = this.createRevisionFromText('delete', author, text, date);
|
|
5282
5282
|
const location = this.createRevisionLocation(paragraph);
|
|
5283
5283
|
if (location) {
|
|
5284
5284
|
location.runIndex = paragraph.getRuns().length;
|
|
@@ -5335,15 +5335,13 @@ class Document {
|
|
|
5335
5335
|
this.trackFormatting = options.trackFormatting;
|
|
5336
5336
|
}
|
|
5337
5337
|
if (options.showInsertionsAndDeletions !== undefined) {
|
|
5338
|
-
this.revisionViewSettings.showInsertionsAndDeletions =
|
|
5339
|
-
options.showInsertionsAndDeletions;
|
|
5338
|
+
this.revisionViewSettings.showInsertionsAndDeletions = options.showInsertionsAndDeletions;
|
|
5340
5339
|
}
|
|
5341
5340
|
if (options.showFormatting !== undefined) {
|
|
5342
5341
|
this.revisionViewSettings.showFormatting = options.showFormatting;
|
|
5343
5342
|
}
|
|
5344
5343
|
if (options.showInkAnnotations !== undefined) {
|
|
5345
|
-
this.revisionViewSettings.showInkAnnotations =
|
|
5346
|
-
options.showInkAnnotations;
|
|
5344
|
+
this.revisionViewSettings.showInkAnnotations = options.showInkAnnotations;
|
|
5347
5345
|
}
|
|
5348
5346
|
}
|
|
5349
5347
|
this.trackingContext.enable({
|
|
@@ -5386,6 +5384,31 @@ class Document {
|
|
|
5386
5384
|
this.bindTrackingToElement(element);
|
|
5387
5385
|
}
|
|
5388
5386
|
this.bindTrackingToElement(this.section);
|
|
5387
|
+
for (const entry of this.headerFooterManager.getAllHeaders()) {
|
|
5388
|
+
for (const element of entry.header.getElements()) {
|
|
5389
|
+
this.bindTrackingToElement(element);
|
|
5390
|
+
}
|
|
5391
|
+
}
|
|
5392
|
+
for (const entry of this.headerFooterManager.getAllFooters()) {
|
|
5393
|
+
for (const element of entry.footer.getElements()) {
|
|
5394
|
+
this.bindTrackingToElement(element);
|
|
5395
|
+
}
|
|
5396
|
+
}
|
|
5397
|
+
for (const footnote of this.footnoteManager.getAllFootnotes()) {
|
|
5398
|
+
for (const para of footnote.getParagraphs()) {
|
|
5399
|
+
this.bindTrackingToElement(para);
|
|
5400
|
+
}
|
|
5401
|
+
}
|
|
5402
|
+
for (const endnote of this.endnoteManager.getAllEndnotes()) {
|
|
5403
|
+
for (const para of endnote.getParagraphs()) {
|
|
5404
|
+
this.bindTrackingToElement(para);
|
|
5405
|
+
}
|
|
5406
|
+
}
|
|
5407
|
+
for (const comment of this.commentManager.getAllCommentsWithReplies()) {
|
|
5408
|
+
for (const run of comment.getRuns()) {
|
|
5409
|
+
this.bindTrackingToElement(run);
|
|
5410
|
+
}
|
|
5411
|
+
}
|
|
5389
5412
|
}
|
|
5390
5413
|
bindTrackingToElement(element) {
|
|
5391
5414
|
if (element && typeof element._setTrackingContext === 'function') {
|
|
@@ -5419,7 +5442,7 @@ class Document {
|
|
|
5419
5442
|
}
|
|
5420
5443
|
setRsidRoot(rsidRoot) {
|
|
5421
5444
|
if (!/^[0-9A-Fa-f]{8}$/.test(rsidRoot)) {
|
|
5422
|
-
throw new Error(
|
|
5445
|
+
throw new Error('RSID must be an 8-character hexadecimal value');
|
|
5423
5446
|
}
|
|
5424
5447
|
this.rsidRoot = rsidRoot.toUpperCase();
|
|
5425
5448
|
this.rsids.add(this.rsidRoot);
|
|
@@ -5428,7 +5451,7 @@ class Document {
|
|
|
5428
5451
|
}
|
|
5429
5452
|
addRsid(rsid) {
|
|
5430
5453
|
if (!/^[0-9A-Fa-f]{8}$/.test(rsid)) {
|
|
5431
|
-
throw new Error(
|
|
5454
|
+
throw new Error('RSID must be an 8-character hexadecimal value');
|
|
5432
5455
|
}
|
|
5433
5456
|
this.rsids.add(rsid.toUpperCase());
|
|
5434
5457
|
this._settingsModified = true;
|
|
@@ -5438,7 +5461,7 @@ class Document {
|
|
|
5438
5461
|
const rsid = Math.floor(Math.random() * 0xffffffff)
|
|
5439
5462
|
.toString(16)
|
|
5440
5463
|
.toUpperCase()
|
|
5441
|
-
.padStart(8,
|
|
5464
|
+
.padStart(8, '0');
|
|
5442
5465
|
this.rsids.add(rsid);
|
|
5443
5466
|
this._settingsModified = true;
|
|
5444
5467
|
return rsid;
|
|
@@ -5461,11 +5484,11 @@ class Document {
|
|
|
5461
5484
|
};
|
|
5462
5485
|
this._settingsModified = true;
|
|
5463
5486
|
if (protection.password) {
|
|
5464
|
-
const crypto = require(
|
|
5465
|
-
const salt = crypto.randomBytes(16).toString(
|
|
5487
|
+
const crypto = require('crypto');
|
|
5488
|
+
const salt = crypto.randomBytes(16).toString('base64');
|
|
5466
5489
|
const hash = crypto
|
|
5467
|
-
.pbkdf2Sync(protection.password, salt, protection.cryptSpinCount || 100000, 32,
|
|
5468
|
-
.toString(
|
|
5490
|
+
.pbkdf2Sync(protection.password, salt, protection.cryptSpinCount || 100000, 32, 'sha512')
|
|
5491
|
+
.toString('base64');
|
|
5469
5492
|
this.documentProtection.hash = hash;
|
|
5470
5493
|
this.documentProtection.salt = salt;
|
|
5471
5494
|
}
|
|
@@ -5588,12 +5611,12 @@ class Document {
|
|
|
5588
5611
|
return this._compatInfo?.isLegacyMode ?? true;
|
|
5589
5612
|
}
|
|
5590
5613
|
getCompatibilityInfo() {
|
|
5591
|
-
return this._compatInfo ?? {
|
|
5614
|
+
return (this._compatInfo ?? {
|
|
5592
5615
|
mode: compatibility_types_1.CompatibilityMode.Word2007,
|
|
5593
5616
|
isLegacyMode: true,
|
|
5594
5617
|
compatSettings: [],
|
|
5595
5618
|
legacyFlags: [],
|
|
5596
|
-
};
|
|
5619
|
+
});
|
|
5597
5620
|
}
|
|
5598
5621
|
upgradeToModernFormat() {
|
|
5599
5622
|
const currentMode = this.getCompatibilityMode();
|
|
@@ -5635,7 +5658,7 @@ class Document {
|
|
|
5635
5658
|
previousMode: currentMode,
|
|
5636
5659
|
newMode: 15,
|
|
5637
5660
|
removedFlags: [],
|
|
5638
|
-
addedSettings: legacyCompatFlags_1.MODERN_COMPAT_SETTINGS.map(s => s.name),
|
|
5661
|
+
addedSettings: legacyCompatFlags_1.MODERN_COMPAT_SETTINGS.map((s) => s.name),
|
|
5639
5662
|
namespacesExpanded: nsResult.expanded,
|
|
5640
5663
|
changed: currentMode !== compatibility_types_1.CompatibilityMode.Word2013Plus,
|
|
5641
5664
|
};
|
|
@@ -5661,9 +5684,7 @@ class Document {
|
|
|
5661
5684
|
return this.revisionManager.register(revision);
|
|
5662
5685
|
}
|
|
5663
5686
|
trackMove(author, content, date) {
|
|
5664
|
-
const moveId = `move${Date.now()}_${Math.random()
|
|
5665
|
-
.toString(36)
|
|
5666
|
-
.substr(2, 9)}`;
|
|
5687
|
+
const moveId = `move${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
5667
5688
|
const moveName = `move${Date.now()}`;
|
|
5668
5689
|
const rangeIdStart = this.revisionManager.getStats().nextId;
|
|
5669
5690
|
const moveFromRangeStart = RangeMarker_1.RangeMarker.createMoveFromStart(rangeIdStart, moveName, author, date);
|
|
@@ -5738,7 +5759,7 @@ class Document {
|
|
|
5738
5759
|
this._endnotesModified = true;
|
|
5739
5760
|
}
|
|
5740
5761
|
addCommentToParagraph(paragraph, commentOrAuthor, content, initials) {
|
|
5741
|
-
const comment = typeof commentOrAuthor ===
|
|
5762
|
+
const comment = typeof commentOrAuthor === 'string'
|
|
5742
5763
|
? this.createComment(commentOrAuthor, content, initials)
|
|
5743
5764
|
: commentOrAuthor;
|
|
5744
5765
|
paragraph.addComment(comment);
|
|
@@ -5916,7 +5937,7 @@ class Document {
|
|
|
5916
5937
|
const revisions = para.getRevisions();
|
|
5917
5938
|
if (revisions.length > 0) {
|
|
5918
5939
|
const content = para.getContent();
|
|
5919
|
-
const nonRevisionContent = content.filter(item => !(item instanceof Revision_1.Revision));
|
|
5940
|
+
const nonRevisionContent = content.filter((item) => !(item instanceof Revision_1.Revision));
|
|
5920
5941
|
para.clearContent();
|
|
5921
5942
|
for (const item of nonRevisionContent) {
|
|
5922
5943
|
if (item instanceof Run_1.Run || item instanceof ImageRun_1.ImageRun) {
|
|
@@ -6074,7 +6095,7 @@ class Document {
|
|
|
6074
6095
|
}
|
|
6075
6096
|
let content = file.content;
|
|
6076
6097
|
if (!file.isBinary && Buffer.isBuffer(file.content)) {
|
|
6077
|
-
content = file.content.toString(
|
|
6098
|
+
content = file.content.toString('utf-8');
|
|
6078
6099
|
}
|
|
6079
6100
|
return {
|
|
6080
6101
|
name: partName,
|
|
@@ -6104,13 +6125,13 @@ class Document {
|
|
|
6104
6125
|
}
|
|
6105
6126
|
}
|
|
6106
6127
|
}
|
|
6107
|
-
const relsXml = this.zipHandler.getFileAsString(
|
|
6128
|
+
const relsXml = this.zipHandler.getFileAsString('_rels/.rels');
|
|
6108
6129
|
if (relsXml) {
|
|
6109
6130
|
const target = partName.replace(/^\//, '');
|
|
6110
6131
|
const relPattern = new RegExp(`\\s*<Relationship[^>]*Target="${target.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"[^>]*/?>`, 'g');
|
|
6111
6132
|
const cleaned = relsXml.replace(relPattern, '');
|
|
6112
6133
|
if (cleaned !== relsXml) {
|
|
6113
|
-
this.zipHandler.updateFile(
|
|
6134
|
+
this.zipHandler.updateFile('_rels/.rels', cleaned);
|
|
6114
6135
|
}
|
|
6115
6136
|
}
|
|
6116
6137
|
this._removedParts.add(partName);
|
|
@@ -6126,7 +6147,7 @@ class Document {
|
|
|
6126
6147
|
async getContentTypes() {
|
|
6127
6148
|
const contentTypes = new Map();
|
|
6128
6149
|
try {
|
|
6129
|
-
const contentTypesXml = this.zipHandler.getFileAsString(
|
|
6150
|
+
const contentTypesXml = this.zipHandler.getFileAsString('[Content_Types].xml');
|
|
6130
6151
|
if (!contentTypesXml) {
|
|
6131
6152
|
return contentTypes;
|
|
6132
6153
|
}
|
|
@@ -6154,11 +6175,11 @@ class Document {
|
|
|
6154
6175
|
if (!part) {
|
|
6155
6176
|
return null;
|
|
6156
6177
|
}
|
|
6157
|
-
if (typeof part.content ===
|
|
6178
|
+
if (typeof part.content === 'string') {
|
|
6158
6179
|
return part.content;
|
|
6159
6180
|
}
|
|
6160
6181
|
if (Buffer.isBuffer(part.content)) {
|
|
6161
|
-
return part.content.toString(
|
|
6182
|
+
return part.content.toString('utf8');
|
|
6162
6183
|
}
|
|
6163
6184
|
return null;
|
|
6164
6185
|
}
|
|
@@ -6185,41 +6206,41 @@ class Document {
|
|
|
6185
6206
|
return xmlMap;
|
|
6186
6207
|
}
|
|
6187
6208
|
async setRawXml(partName, xmlContent) {
|
|
6188
|
-
if (typeof xmlContent !==
|
|
6189
|
-
throw new Error(
|
|
6209
|
+
if (typeof xmlContent !== 'string') {
|
|
6210
|
+
throw new Error('XML content must be a string');
|
|
6190
6211
|
}
|
|
6191
6212
|
await this.setPart(partName, xmlContent);
|
|
6192
6213
|
}
|
|
6193
6214
|
async addContentType(partNameOrExtension, contentType) {
|
|
6194
6215
|
try {
|
|
6195
|
-
let contentTypesXml = this.zipHandler.getFileAsString(
|
|
6216
|
+
let contentTypesXml = this.zipHandler.getFileAsString('[Content_Types].xml');
|
|
6196
6217
|
if (!contentTypesXml) {
|
|
6197
6218
|
return false;
|
|
6198
6219
|
}
|
|
6199
|
-
const isExtension = partNameOrExtension.startsWith(
|
|
6220
|
+
const isExtension = partNameOrExtension.startsWith('.');
|
|
6200
6221
|
if (isExtension) {
|
|
6201
6222
|
const extension = partNameOrExtension.substring(1);
|
|
6202
|
-
const existingPattern = new RegExp(`<Default\\s+Extension="${extension}"\\s+ContentType="[^"]+"/?>`,
|
|
6223
|
+
const existingPattern = new RegExp(`<Default\\s+Extension="${extension}"\\s+ContentType="[^"]+"/?>`, 'g');
|
|
6203
6224
|
if (existingPattern.test(contentTypesXml)) {
|
|
6204
6225
|
contentTypesXml = contentTypesXml.replace(existingPattern, `<Default Extension="${extension}" ContentType="${contentType}"/>`);
|
|
6205
6226
|
}
|
|
6206
6227
|
else {
|
|
6207
|
-
contentTypesXml = contentTypesXml.replace(
|
|
6228
|
+
contentTypesXml = contentTypesXml.replace('</Types>', ` <Default Extension="${extension}" ContentType="${contentType}"/>\n</Types>`);
|
|
6208
6229
|
}
|
|
6209
6230
|
}
|
|
6210
6231
|
else {
|
|
6211
|
-
const partName = partNameOrExtension.startsWith(
|
|
6232
|
+
const partName = partNameOrExtension.startsWith('/')
|
|
6212
6233
|
? partNameOrExtension
|
|
6213
6234
|
: `/${partNameOrExtension}`;
|
|
6214
|
-
const existingPattern = new RegExp(`<Override\\s+PartName="${partName.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6235
|
+
const existingPattern = new RegExp(`<Override\\s+PartName="${partName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"\\s+ContentType="[^"]+"/?>`, 'g');
|
|
6215
6236
|
if (existingPattern.test(contentTypesXml)) {
|
|
6216
6237
|
contentTypesXml = contentTypesXml.replace(existingPattern, `<Override PartName="${partName}" ContentType="${contentType}"/>`);
|
|
6217
6238
|
}
|
|
6218
6239
|
else {
|
|
6219
|
-
contentTypesXml = contentTypesXml.replace(
|
|
6240
|
+
contentTypesXml = contentTypesXml.replace('</Types>', ` <Override PartName="${partName}" ContentType="${contentType}"/>\n</Types>`);
|
|
6220
6241
|
}
|
|
6221
6242
|
}
|
|
6222
|
-
this.zipHandler.updateFile(
|
|
6243
|
+
this.zipHandler.updateFile('[Content_Types].xml', contentTypesXml);
|
|
6223
6244
|
return true;
|
|
6224
6245
|
}
|
|
6225
6246
|
catch (error) {
|
|
@@ -6229,20 +6250,18 @@ class Document {
|
|
|
6229
6250
|
async getAllRelationships() {
|
|
6230
6251
|
const relationships = new Map();
|
|
6231
6252
|
try {
|
|
6232
|
-
const relsPaths = this.zipHandler
|
|
6233
|
-
.getFilePaths()
|
|
6234
|
-
.filter((path) => path.endsWith(".rels"));
|
|
6253
|
+
const relsPaths = this.zipHandler.getFilePaths().filter((path) => path.endsWith('.rels'));
|
|
6235
6254
|
for (const relsPath of relsPaths) {
|
|
6236
6255
|
const relsContent = this.zipHandler.getFileAsString(relsPath);
|
|
6237
6256
|
if (relsContent) {
|
|
6238
6257
|
const rels = [];
|
|
6239
|
-
const relationshipElements = XMLParser_1.XMLParser.extractElements(relsContent,
|
|
6258
|
+
const relationshipElements = XMLParser_1.XMLParser.extractElements(relsContent, 'Relationship');
|
|
6240
6259
|
for (const relElement of relationshipElements) {
|
|
6241
6260
|
const rel = {};
|
|
6242
|
-
const id = XMLParser_1.XMLParser.extractAttribute(relElement,
|
|
6243
|
-
const type = XMLParser_1.XMLParser.extractAttribute(relElement,
|
|
6244
|
-
const target = XMLParser_1.XMLParser.extractAttribute(relElement,
|
|
6245
|
-
const targetMode = XMLParser_1.XMLParser.extractAttribute(relElement,
|
|
6261
|
+
const id = XMLParser_1.XMLParser.extractAttribute(relElement, 'Id');
|
|
6262
|
+
const type = XMLParser_1.XMLParser.extractAttribute(relElement, 'Type');
|
|
6263
|
+
const target = XMLParser_1.XMLParser.extractAttribute(relElement, 'Target');
|
|
6264
|
+
const targetMode = XMLParser_1.XMLParser.extractAttribute(relElement, 'TargetMode');
|
|
6246
6265
|
if (id)
|
|
6247
6266
|
rel.id = id;
|
|
6248
6267
|
if (type)
|
|
@@ -6263,7 +6282,7 @@ class Document {
|
|
|
6263
6282
|
}
|
|
6264
6283
|
async getRelationships(partName) {
|
|
6265
6284
|
try {
|
|
6266
|
-
const lastSlash = partName.lastIndexOf(
|
|
6285
|
+
const lastSlash = partName.lastIndexOf('/');
|
|
6267
6286
|
const relsPath = lastSlash === -1
|
|
6268
6287
|
? `_rels/${partName}.rels`
|
|
6269
6288
|
: `${partName.substring(0, lastSlash)}/_rels/${partName.substring(lastSlash + 1)}.rels`;
|
|
@@ -6272,13 +6291,13 @@ class Document {
|
|
|
6272
6291
|
return [];
|
|
6273
6292
|
}
|
|
6274
6293
|
const relationships = [];
|
|
6275
|
-
const relationshipElements = XMLParser_1.XMLParser.extractElements(relsContent,
|
|
6294
|
+
const relationshipElements = XMLParser_1.XMLParser.extractElements(relsContent, 'Relationship');
|
|
6276
6295
|
for (const relElement of relationshipElements) {
|
|
6277
6296
|
const rel = {};
|
|
6278
|
-
const id = XMLParser_1.XMLParser.extractAttribute(relElement,
|
|
6279
|
-
const type = XMLParser_1.XMLParser.extractAttribute(relElement,
|
|
6280
|
-
const target = XMLParser_1.XMLParser.extractAttribute(relElement,
|
|
6281
|
-
const targetMode = XMLParser_1.XMLParser.extractAttribute(relElement,
|
|
6297
|
+
const id = XMLParser_1.XMLParser.extractAttribute(relElement, 'Id');
|
|
6298
|
+
const type = XMLParser_1.XMLParser.extractAttribute(relElement, 'Type');
|
|
6299
|
+
const target = XMLParser_1.XMLParser.extractAttribute(relElement, 'Target');
|
|
6300
|
+
const targetMode = XMLParser_1.XMLParser.extractAttribute(relElement, 'TargetMode');
|
|
6282
6301
|
if (id)
|
|
6283
6302
|
rel.id = id;
|
|
6284
6303
|
if (type)
|
|
@@ -6297,18 +6316,18 @@ class Document {
|
|
|
6297
6316
|
}
|
|
6298
6317
|
getContentTypeForPart(partName) {
|
|
6299
6318
|
try {
|
|
6300
|
-
const contentTypesXml = this.zipHandler.getFileAsString(
|
|
6319
|
+
const contentTypesXml = this.zipHandler.getFileAsString('[Content_Types].xml');
|
|
6301
6320
|
if (!contentTypesXml) {
|
|
6302
6321
|
return undefined;
|
|
6303
6322
|
}
|
|
6304
|
-
const overridePattern = new RegExp(`<Override\\s+PartName="${partName.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6323
|
+
const overridePattern = new RegExp(`<Override\\s+PartName="${partName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"\\s+ContentType="([^"]+)"`, 'i');
|
|
6305
6324
|
const overrideMatch = contentTypesXml.match(overridePattern);
|
|
6306
6325
|
if (overrideMatch) {
|
|
6307
6326
|
return overrideMatch[1];
|
|
6308
6327
|
}
|
|
6309
|
-
const ext = partName.substring(partName.lastIndexOf(
|
|
6328
|
+
const ext = partName.substring(partName.lastIndexOf('.'));
|
|
6310
6329
|
if (ext) {
|
|
6311
|
-
const defaultPattern = new RegExp(`<Default\\s+Extension="${ext.substring(1)}"\\s+ContentType="([^"]+)"`,
|
|
6330
|
+
const defaultPattern = new RegExp(`<Default\\s+Extension="${ext.substring(1)}"\\s+ContentType="([^"]+)"`, 'i');
|
|
6312
6331
|
const defaultMatch = contentTypesXml.match(defaultPattern);
|
|
6313
6332
|
if (defaultMatch) {
|
|
6314
6333
|
return defaultMatch[1];
|
|
@@ -6339,7 +6358,7 @@ class Document {
|
|
|
6339
6358
|
const runText = run.getText();
|
|
6340
6359
|
const compareText = caseSensitive ? runText : runText.toLowerCase();
|
|
6341
6360
|
if (wholeWord) {
|
|
6342
|
-
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6361
|
+
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, caseSensitive ? 'g' : 'gi');
|
|
6343
6362
|
let match;
|
|
6344
6363
|
while ((match = wordPattern.exec(runText)) !== null) {
|
|
6345
6364
|
results.push({
|
|
@@ -6387,11 +6406,9 @@ class Document {
|
|
|
6387
6406
|
if (!run)
|
|
6388
6407
|
continue;
|
|
6389
6408
|
const runText = run.getText();
|
|
6390
|
-
const compareText = caseSensitive
|
|
6391
|
-
? runText
|
|
6392
|
-
: runText.toLowerCase();
|
|
6409
|
+
const compareText = caseSensitive ? runText : runText.toLowerCase();
|
|
6393
6410
|
if (wholeWord) {
|
|
6394
|
-
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6411
|
+
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, caseSensitive ? 'g' : 'gi');
|
|
6395
6412
|
let match;
|
|
6396
6413
|
while ((match = wordPattern.exec(runText)) !== null) {
|
|
6397
6414
|
results.push({
|
|
@@ -6428,7 +6445,7 @@ class Document {
|
|
|
6428
6445
|
}
|
|
6429
6446
|
findParagraphsByText(pattern) {
|
|
6430
6447
|
const results = [];
|
|
6431
|
-
const regex = typeof pattern ===
|
|
6448
|
+
const regex = typeof pattern === 'string' ? new RegExp(pattern, 'gi') : pattern;
|
|
6432
6449
|
for (const paragraph of this.getAllParagraphs()) {
|
|
6433
6450
|
const text = paragraph.getText();
|
|
6434
6451
|
const matches = text.match(regex);
|
|
@@ -6453,12 +6470,12 @@ class Document {
|
|
|
6453
6470
|
}
|
|
6454
6471
|
getRunsByColor(color) {
|
|
6455
6472
|
const results = [];
|
|
6456
|
-
const normalizedColor = color.replace(/^#/,
|
|
6473
|
+
const normalizedColor = color.replace(/^#/, '').toUpperCase();
|
|
6457
6474
|
for (const paragraph of this.getAllParagraphs()) {
|
|
6458
6475
|
for (const run of paragraph.getRuns()) {
|
|
6459
6476
|
const formatting = run.getFormatting();
|
|
6460
6477
|
if (formatting.color) {
|
|
6461
|
-
const runColor = formatting.color.replace(/^#/,
|
|
6478
|
+
const runColor = formatting.color.replace(/^#/, '').toUpperCase();
|
|
6462
6479
|
if (runColor === normalizedColor) {
|
|
6463
6480
|
results.push(run);
|
|
6464
6481
|
}
|
|
@@ -6517,7 +6534,7 @@ class Document {
|
|
|
6517
6534
|
sizes.set(formatting.size, (sizes.get(formatting.size) || 0) + 1);
|
|
6518
6535
|
}
|
|
6519
6536
|
if (formatting.color) {
|
|
6520
|
-
const normalizedColor = formatting.color.toUpperCase().replace(/^#/,
|
|
6537
|
+
const normalizedColor = formatting.color.toUpperCase().replace(/^#/, '');
|
|
6521
6538
|
colors.set(normalizedColor, (colors.get(normalizedColor) || 0) + 1);
|
|
6522
6539
|
}
|
|
6523
6540
|
}
|
|
@@ -6572,7 +6589,7 @@ class Document {
|
|
|
6572
6589
|
const originalText = run.getText();
|
|
6573
6590
|
let newText = originalText;
|
|
6574
6591
|
if (wholeWord) {
|
|
6575
|
-
const wordPattern = new RegExp(`\\b${find.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6592
|
+
const wordPattern = new RegExp(`\\b${find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, caseSensitive ? 'g' : 'gi');
|
|
6576
6593
|
const matches = originalText.match(wordPattern);
|
|
6577
6594
|
if (matches) {
|
|
6578
6595
|
replacementCount += matches.length;
|
|
@@ -6580,7 +6597,7 @@ class Document {
|
|
|
6580
6597
|
}
|
|
6581
6598
|
}
|
|
6582
6599
|
else {
|
|
6583
|
-
const searchPattern = new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6600
|
+
const searchPattern = new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), caseSensitive ? 'g' : 'gi');
|
|
6584
6601
|
const matches = originalText.match(searchPattern);
|
|
6585
6602
|
if (matches) {
|
|
6586
6603
|
replacementCount += matches.length;
|
|
@@ -6595,20 +6612,18 @@ class Document {
|
|
|
6595
6612
|
return replacementCount;
|
|
6596
6613
|
}
|
|
6597
6614
|
findAndReplaceAll(pattern, replacement, options) {
|
|
6598
|
-
const { caseSensitive = false, wholeWord = false, trackChanges = false, author =
|
|
6615
|
+
const { caseSensitive = false, wholeWord = false, trackChanges = false, author = 'Unknown', } = options || {};
|
|
6599
6616
|
let count = 0;
|
|
6600
6617
|
const revisions = [];
|
|
6601
6618
|
let regex;
|
|
6602
|
-
if (typeof pattern ===
|
|
6603
|
-
const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6619
|
+
if (typeof pattern === 'string') {
|
|
6620
|
+
const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
6604
6621
|
const boundaryPattern = wholeWord ? `\\b${escaped}\\b` : escaped;
|
|
6605
|
-
const flags = caseSensitive ?
|
|
6622
|
+
const flags = caseSensitive ? 'g' : 'gi';
|
|
6606
6623
|
regex = new RegExp(boundaryPattern, flags);
|
|
6607
6624
|
}
|
|
6608
6625
|
else {
|
|
6609
|
-
const flags = pattern.flags.includes(
|
|
6610
|
-
? pattern.flags
|
|
6611
|
-
: pattern.flags + "g";
|
|
6626
|
+
const flags = pattern.flags.includes('g') ? pattern.flags : pattern.flags + 'g';
|
|
6612
6627
|
regex = new RegExp(pattern.source, flags);
|
|
6613
6628
|
}
|
|
6614
6629
|
const runs = this.getAllRuns();
|
|
@@ -6627,16 +6642,16 @@ class Document {
|
|
|
6627
6642
|
const newContent = [];
|
|
6628
6643
|
if (useGranular) {
|
|
6629
6644
|
for (const seg of segments) {
|
|
6630
|
-
if (seg.type ===
|
|
6645
|
+
if (seg.type === 'equal') {
|
|
6631
6646
|
newContent.push(new Run_1.Run(seg.text, formatting));
|
|
6632
6647
|
}
|
|
6633
|
-
else if (seg.type ===
|
|
6648
|
+
else if (seg.type === 'delete') {
|
|
6634
6649
|
const delRev = Revision_1.Revision.createDeletion(author, new Run_1.Run(seg.text, formatting), now);
|
|
6635
6650
|
this.revisionManager.register(delRev);
|
|
6636
6651
|
revisions.push(delRev);
|
|
6637
6652
|
newContent.push(delRev);
|
|
6638
6653
|
}
|
|
6639
|
-
else if (seg.type ===
|
|
6654
|
+
else if (seg.type === 'insert') {
|
|
6640
6655
|
const insRev = Revision_1.Revision.createInsertion(author, new Run_1.Run(seg.text, formatting), now);
|
|
6641
6656
|
this.revisionManager.register(insRev);
|
|
6642
6657
|
revisions.push(insRev);
|
|
@@ -6721,7 +6736,7 @@ class Document {
|
|
|
6721
6736
|
totalChars += text.length;
|
|
6722
6737
|
}
|
|
6723
6738
|
else {
|
|
6724
|
-
totalChars += text.replace(/\s/g,
|
|
6739
|
+
totalChars += text.replace(/\s/g, '').length;
|
|
6725
6740
|
}
|
|
6726
6741
|
}
|
|
6727
6742
|
const tables = this.getTables();
|
|
@@ -6741,7 +6756,7 @@ class Document {
|
|
|
6741
6756
|
totalChars += text.length;
|
|
6742
6757
|
}
|
|
6743
6758
|
else {
|
|
6744
|
-
totalChars += text.replace(/\s/g,
|
|
6759
|
+
totalChars += text.replace(/\s/g, '').length;
|
|
6745
6760
|
}
|
|
6746
6761
|
}
|
|
6747
6762
|
}
|
|
@@ -6751,7 +6766,7 @@ class Document {
|
|
|
6751
6766
|
}
|
|
6752
6767
|
removeParagraph(paragraphOrIndex) {
|
|
6753
6768
|
let index;
|
|
6754
|
-
if (typeof paragraphOrIndex ===
|
|
6769
|
+
if (typeof paragraphOrIndex === 'number') {
|
|
6755
6770
|
index = paragraphOrIndex;
|
|
6756
6771
|
}
|
|
6757
6772
|
else {
|
|
@@ -6778,7 +6793,7 @@ class Document {
|
|
|
6778
6793
|
}
|
|
6779
6794
|
removeTable(tableOrIndex) {
|
|
6780
6795
|
let index;
|
|
6781
|
-
if (typeof tableOrIndex ===
|
|
6796
|
+
if (typeof tableOrIndex === 'number') {
|
|
6782
6797
|
const tables = this.getTables();
|
|
6783
6798
|
if (tableOrIndex >= 0 && tableOrIndex < tables.length) {
|
|
6784
6799
|
const table = tables[tableOrIndex];
|
|
@@ -6804,7 +6819,7 @@ class Document {
|
|
|
6804
6819
|
}
|
|
6805
6820
|
validateParagraph(paragraph) {
|
|
6806
6821
|
if (!(paragraph instanceof Paragraph_1.Paragraph)) {
|
|
6807
|
-
throw new Error(
|
|
6822
|
+
throw new Error('insertParagraphAt: parameter must be a Paragraph instance');
|
|
6808
6823
|
}
|
|
6809
6824
|
const paraId = paragraph.getFormatting().paraId;
|
|
6810
6825
|
if (paraId) {
|
|
@@ -6827,15 +6842,15 @@ class Document {
|
|
|
6827
6842
|
}
|
|
6828
6843
|
validateTable(table) {
|
|
6829
6844
|
if (!(table instanceof Table_1.Table)) {
|
|
6830
|
-
throw new Error(
|
|
6845
|
+
throw new Error('insertTableAt: parameter must be a Table instance');
|
|
6831
6846
|
}
|
|
6832
6847
|
const rows = table.getRows();
|
|
6833
6848
|
if (rows.length === 0) {
|
|
6834
|
-
throw new Error(
|
|
6849
|
+
throw new Error('insertTableAt: table must have at least one row');
|
|
6835
6850
|
}
|
|
6836
6851
|
const firstRow = rows[0];
|
|
6837
6852
|
if (firstRow?.getCells().length === 0) {
|
|
6838
|
-
throw new Error(
|
|
6853
|
+
throw new Error('insertTableAt: table rows must have at least one cell');
|
|
6839
6854
|
}
|
|
6840
6855
|
const tableStyle = table.getFormatting().style;
|
|
6841
6856
|
if (tableStyle && !this.stylesManager.hasStyle(tableStyle)) {
|
|
@@ -6844,21 +6859,21 @@ class Document {
|
|
|
6844
6859
|
}
|
|
6845
6860
|
validateToc(toc) {
|
|
6846
6861
|
if (!(toc instanceof TableOfContentsElement_1.TableOfContentsElement)) {
|
|
6847
|
-
throw new Error(
|
|
6862
|
+
throw new Error('insertTocAt: parameter must be a TableOfContentsElement instance');
|
|
6848
6863
|
}
|
|
6849
6864
|
const hasHeadings = [
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6865
|
+
'Heading1',
|
|
6866
|
+
'Heading2',
|
|
6867
|
+
'Heading3',
|
|
6868
|
+
'Heading4',
|
|
6869
|
+
'Heading5',
|
|
6870
|
+
'Heading6',
|
|
6871
|
+
'Heading7',
|
|
6872
|
+
'Heading8',
|
|
6873
|
+
'Heading9',
|
|
6859
6874
|
].some((style) => this.stylesManager.hasStyle(style));
|
|
6860
6875
|
if (!hasHeadings) {
|
|
6861
|
-
logger_1.defaultLogger.warn(
|
|
6876
|
+
logger_1.defaultLogger.warn('No heading styles found in document. Table of Contents may not display entries correctly.');
|
|
6862
6877
|
}
|
|
6863
6878
|
}
|
|
6864
6879
|
normalizeIndex(index) {
|
|
@@ -7320,7 +7335,7 @@ class Document {
|
|
|
7320
7335
|
const toRemove = [];
|
|
7321
7336
|
this.bodyElements.forEach((element, index) => {
|
|
7322
7337
|
if (element instanceof Paragraph_1.Paragraph) {
|
|
7323
|
-
const isEmpty = element.getText().trim() ===
|
|
7338
|
+
const isEmpty = element.getText().trim() === '';
|
|
7324
7339
|
if (isEmpty && lastWasEmpty) {
|
|
7325
7340
|
toRemove.push(index);
|
|
7326
7341
|
}
|
|
@@ -7347,7 +7362,7 @@ class Document {
|
|
|
7347
7362
|
}
|
|
7348
7363
|
}
|
|
7349
7364
|
if (standardLineSpacing !== undefined) {
|
|
7350
|
-
para.setLineSpacing(standardLineSpacing,
|
|
7365
|
+
para.setLineSpacing(standardLineSpacing, 'auto');
|
|
7351
7366
|
normalized++;
|
|
7352
7367
|
}
|
|
7353
7368
|
if (removeTrailingSpaces) {
|
|
@@ -7381,7 +7396,7 @@ class Document {
|
|
|
7381
7396
|
}
|
|
7382
7397
|
}
|
|
7383
7398
|
if (standardLineSpacing !== undefined) {
|
|
7384
|
-
para.setLineSpacing(standardLineSpacing,
|
|
7399
|
+
para.setLineSpacing(standardLineSpacing, 'auto');
|
|
7385
7400
|
normalized++;
|
|
7386
7401
|
}
|
|
7387
7402
|
if (removeTrailingSpaces) {
|
|
@@ -7490,9 +7505,9 @@ class Document {
|
|
|
7490
7505
|
}
|
|
7491
7506
|
normalizeTableBorders(options) {
|
|
7492
7507
|
const border = {
|
|
7493
|
-
style: options?.style ??
|
|
7508
|
+
style: options?.style ?? 'single',
|
|
7494
7509
|
size: options?.size ?? 4,
|
|
7495
|
-
color: options?.color ??
|
|
7510
|
+
color: options?.color ?? '000000',
|
|
7496
7511
|
};
|
|
7497
7512
|
return this.applyBordersToAllTables(border);
|
|
7498
7513
|
}
|
|
@@ -7502,8 +7517,8 @@ class Document {
|
|
|
7502
7517
|
const matchItalic = options?.matchItalic ?? false;
|
|
7503
7518
|
const matchCase = options?.matchCase ?? false;
|
|
7504
7519
|
const pattern = matchCase
|
|
7505
|
-
? new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g,
|
|
7506
|
-
: new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g,
|
|
7520
|
+
? new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g')
|
|
7521
|
+
: new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi');
|
|
7507
7522
|
for (const para of this.getAllParagraphs()) {
|
|
7508
7523
|
for (const run of para.getRuns()) {
|
|
7509
7524
|
const text = run.getText();
|
|
@@ -7555,21 +7570,21 @@ class Document {
|
|
|
7555
7570
|
static createEmpty() {
|
|
7556
7571
|
const doc = new Document(undefined, {}, false);
|
|
7557
7572
|
const zipHandler = doc.getZipHandler();
|
|
7558
|
-
zipHandler.addFile(
|
|
7573
|
+
zipHandler.addFile('[Content_Types].xml', '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
7559
7574
|
'<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">\n' +
|
|
7560
7575
|
' <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>\n' +
|
|
7561
7576
|
' <Default Extension="xml" ContentType="application/xml"/>\n' +
|
|
7562
7577
|
' <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>\n' +
|
|
7563
|
-
|
|
7564
|
-
zipHandler.addFile(
|
|
7578
|
+
'</Types>');
|
|
7579
|
+
zipHandler.addFile('_rels/.rels', '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
7565
7580
|
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">\n' +
|
|
7566
7581
|
' <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>\n' +
|
|
7567
|
-
|
|
7568
|
-
zipHandler.addFile(
|
|
7582
|
+
'</Relationships>');
|
|
7583
|
+
zipHandler.addFile('word/document.xml', '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
7569
7584
|
'<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">\n' +
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
zipHandler.addFile(
|
|
7585
|
+
' <w:body/>\n' +
|
|
7586
|
+
'</w:document>');
|
|
7587
|
+
zipHandler.addFile('word/_rels/document.xml.rels', '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
7573
7588
|
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"/>');
|
|
7574
7589
|
return doc;
|
|
7575
7590
|
}
|