docxmlater 10.1.3 → 10.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +759 -754
- package/dist/constants/legacyCompatFlags.js +1 -1
- package/dist/constants/legacyCompatFlags.js.map +1 -1
- package/dist/constants/limits.js.map +1 -1
- package/dist/core/Document.d.ts +50 -50
- package/dist/core/Document.d.ts.map +1 -1
- package/dist/core/Document.js +483 -471
- package/dist/core/Document.js.map +1 -1
- package/dist/core/DocumentContent.d.ts +9 -9
- package/dist/core/DocumentContent.d.ts.map +1 -1
- package/dist/core/DocumentContent.js +1 -1
- package/dist/core/DocumentContent.js.map +1 -1
- package/dist/core/DocumentGenerator.d.ts +11 -11
- package/dist/core/DocumentGenerator.d.ts.map +1 -1
- package/dist/core/DocumentGenerator.js +251 -251
- package/dist/core/DocumentGenerator.js.map +1 -1
- package/dist/core/DocumentIdManager.js.map +1 -1
- package/dist/core/DocumentParser.d.ts +15 -15
- package/dist/core/DocumentParser.d.ts.map +1 -1
- package/dist/core/DocumentParser.js +2123 -2155
- package/dist/core/DocumentParser.js.map +1 -1
- package/dist/core/DocumentValidator.d.ts.map +1 -1
- package/dist/core/DocumentValidator.js +2 -5
- package/dist/core/DocumentValidator.js.map +1 -1
- package/dist/core/Relationship.js.map +1 -1
- package/dist/core/RelationshipManager.d.ts.map +1 -1
- package/dist/core/RelationshipManager.js +3 -3
- package/dist/core/RelationshipManager.js.map +1 -1
- package/dist/elements/AlternateContent.js.map +1 -1
- package/dist/elements/Bookmark.d.ts.map +1 -1
- package/dist/elements/Bookmark.js +3 -1
- package/dist/elements/Bookmark.js.map +1 -1
- package/dist/elements/BookmarkManager.d.ts.map +1 -1
- package/dist/elements/BookmarkManager.js.map +1 -1
- package/dist/elements/Comment.d.ts.map +1 -1
- package/dist/elements/Comment.js +9 -6
- package/dist/elements/Comment.js.map +1 -1
- package/dist/elements/CommentManager.d.ts.map +1 -1
- package/dist/elements/CommentManager.js +18 -17
- package/dist/elements/CommentManager.js.map +1 -1
- package/dist/elements/CommonTypes.d.ts +21 -21
- package/dist/elements/CommonTypes.d.ts.map +1 -1
- package/dist/elements/CommonTypes.js +56 -56
- package/dist/elements/CommonTypes.js.map +1 -1
- package/dist/elements/CustomXml.js.map +1 -1
- package/dist/elements/Endnote.d.ts.map +1 -1
- package/dist/elements/Endnote.js +6 -6
- package/dist/elements/Endnote.js.map +1 -1
- package/dist/elements/EndnoteManager.d.ts.map +1 -1
- package/dist/elements/EndnoteManager.js +6 -7
- package/dist/elements/EndnoteManager.js.map +1 -1
- package/dist/elements/Field.d.ts.map +1 -1
- package/dist/elements/Field.js +82 -25
- package/dist/elements/Field.js.map +1 -1
- package/dist/elements/FieldHelpers.d.ts.map +1 -1
- package/dist/elements/FieldHelpers.js.map +1 -1
- package/dist/elements/FontManager.d.ts.map +1 -1
- package/dist/elements/FontManager.js +1 -1
- package/dist/elements/FontManager.js.map +1 -1
- package/dist/elements/Footer.js +2 -2
- package/dist/elements/Footer.js.map +1 -1
- package/dist/elements/Footnote.d.ts.map +1 -1
- package/dist/elements/Footnote.js +6 -6
- package/dist/elements/Footnote.js.map +1 -1
- package/dist/elements/FootnoteManager.d.ts.map +1 -1
- package/dist/elements/FootnoteManager.js +6 -7
- package/dist/elements/FootnoteManager.js.map +1 -1
- package/dist/elements/Header.js +2 -2
- package/dist/elements/Header.js.map +1 -1
- package/dist/elements/HeaderFooterManager.js.map +1 -1
- package/dist/elements/Hyperlink.d.ts +5 -3
- package/dist/elements/Hyperlink.d.ts.map +1 -1
- package/dist/elements/Hyperlink.js +134 -76
- package/dist/elements/Hyperlink.js.map +1 -1
- package/dist/elements/Image.d.ts.map +1 -1
- package/dist/elements/Image.js +238 -106
- package/dist/elements/Image.js.map +1 -1
- package/dist/elements/ImageManager.d.ts.map +1 -1
- package/dist/elements/ImageManager.js +1 -1
- package/dist/elements/ImageManager.js.map +1 -1
- package/dist/elements/ImageRun.js +1 -1
- package/dist/elements/ImageRun.js.map +1 -1
- package/dist/elements/MathElement.js.map +1 -1
- package/dist/elements/Paragraph.d.ts +24 -24
- package/dist/elements/Paragraph.d.ts.map +1 -1
- package/dist/elements/Paragraph.js +181 -188
- package/dist/elements/Paragraph.js.map +1 -1
- package/dist/elements/PreservedElement.js.map +1 -1
- package/dist/elements/PropertyChangeTypes.d.ts.map +1 -1
- package/dist/elements/PropertyChangeTypes.js +6 -6
- package/dist/elements/PropertyChangeTypes.js.map +1 -1
- package/dist/elements/RangeMarker.d.ts.map +1 -1
- package/dist/elements/RangeMarker.js.map +1 -1
- package/dist/elements/Revision.d.ts.map +1 -1
- package/dist/elements/Revision.js +4 -5
- package/dist/elements/Revision.js.map +1 -1
- package/dist/elements/RevisionContent.js.map +1 -1
- package/dist/elements/RevisionManager.d.ts.map +1 -1
- package/dist/elements/RevisionManager.js +40 -48
- package/dist/elements/RevisionManager.js.map +1 -1
- package/dist/elements/Run.d.ts +16 -16
- package/dist/elements/Run.d.ts.map +1 -1
- package/dist/elements/Run.js +256 -238
- package/dist/elements/Run.js.map +1 -1
- package/dist/elements/Section.d.ts.map +1 -1
- package/dist/elements/Section.js +36 -11
- package/dist/elements/Section.js.map +1 -1
- package/dist/elements/Shape.d.ts.map +1 -1
- package/dist/elements/Shape.js.map +1 -1
- package/dist/elements/StructuredDocumentTag.d.ts +6 -6
- package/dist/elements/StructuredDocumentTag.d.ts.map +1 -1
- package/dist/elements/StructuredDocumentTag.js +99 -104
- package/dist/elements/StructuredDocumentTag.js.map +1 -1
- package/dist/elements/Table.d.ts +11 -11
- package/dist/elements/Table.d.ts.map +1 -1
- package/dist/elements/Table.js +102 -107
- package/dist/elements/Table.js.map +1 -1
- package/dist/elements/TableCell.d.ts +10 -10
- package/dist/elements/TableCell.d.ts.map +1 -1
- package/dist/elements/TableCell.js +105 -106
- package/dist/elements/TableCell.js.map +1 -1
- package/dist/elements/TableGridChange.d.ts.map +1 -1
- package/dist/elements/TableGridChange.js.map +1 -1
- package/dist/elements/TableOfContents.d.ts.map +1 -1
- package/dist/elements/TableOfContents.js +4 -4
- package/dist/elements/TableOfContents.js.map +1 -1
- package/dist/elements/TableOfContentsElement.js.map +1 -1
- package/dist/elements/TableRow.d.ts.map +1 -1
- package/dist/elements/TableRow.js +13 -6
- package/dist/elements/TableRow.js.map +1 -1
- package/dist/elements/TextBox.d.ts.map +1 -1
- package/dist/elements/TextBox.js +3 -5
- package/dist/elements/TextBox.js.map +1 -1
- package/dist/formatting/AbstractNumbering.d.ts +4 -4
- package/dist/formatting/AbstractNumbering.d.ts.map +1 -1
- package/dist/formatting/AbstractNumbering.js +54 -49
- package/dist/formatting/AbstractNumbering.js.map +1 -1
- package/dist/formatting/NumberingInstance.d.ts.map +1 -1
- package/dist/formatting/NumberingInstance.js +1 -3
- package/dist/formatting/NumberingInstance.js.map +1 -1
- package/dist/formatting/NumberingLevel.d.ts +5 -5
- package/dist/formatting/NumberingLevel.d.ts.map +1 -1
- package/dist/formatting/NumberingLevel.js +119 -125
- package/dist/formatting/NumberingLevel.js.map +1 -1
- package/dist/formatting/NumberingManager.d.ts.map +1 -1
- package/dist/formatting/NumberingManager.js +9 -9
- package/dist/formatting/NumberingManager.js.map +1 -1
- package/dist/formatting/Style.d.ts +11 -11
- package/dist/formatting/Style.d.ts.map +1 -1
- package/dist/formatting/Style.js +219 -247
- package/dist/formatting/Style.js.map +1 -1
- package/dist/formatting/StylesManager.d.ts +2 -2
- package/dist/formatting/StylesManager.d.ts.map +1 -1
- package/dist/formatting/StylesManager.js +96 -102
- package/dist/formatting/StylesManager.js.map +1 -1
- package/dist/helpers/CleanupHelper.d.ts +1 -1
- package/dist/helpers/CleanupHelper.d.ts.map +1 -1
- package/dist/helpers/CleanupHelper.js +6 -6
- package/dist/helpers/CleanupHelper.js.map +1 -1
- package/dist/images/ImageOptimizer.js +7 -7
- package/dist/images/ImageOptimizer.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/managers/DrawingManager.js.map +1 -1
- package/dist/tracking/DocumentTrackingContext.d.ts.map +1 -1
- package/dist/tracking/DocumentTrackingContext.js +23 -7
- package/dist/tracking/DocumentTrackingContext.js.map +1 -1
- package/dist/tracking/TrackingContext.d.ts.map +1 -1
- package/dist/tracking/TrackingContext.js.map +1 -1
- package/dist/types/compatibility-types.js.map +1 -1
- package/dist/types/formatting.js.map +1 -1
- package/dist/types/list-types.d.ts +6 -6
- package/dist/types/list-types.js.map +1 -1
- package/dist/types/settings-types.js.map +1 -1
- package/dist/types/styleConfig.d.ts +2 -2
- package/dist/types/styleConfig.js.map +1 -1
- package/dist/utils/ChangelogGenerator.d.ts.map +1 -1
- package/dist/utils/ChangelogGenerator.js +97 -101
- package/dist/utils/ChangelogGenerator.js.map +1 -1
- package/dist/utils/CompatibilityUpgrader.d.ts.map +1 -1
- package/dist/utils/CompatibilityUpgrader.js +1 -1
- package/dist/utils/CompatibilityUpgrader.js.map +1 -1
- package/dist/utils/InMemoryRevisionAcceptor.d.ts.map +1 -1
- package/dist/utils/InMemoryRevisionAcceptor.js +1 -6
- package/dist/utils/InMemoryRevisionAcceptor.js.map +1 -1
- package/dist/utils/MoveOperationHelper.d.ts.map +1 -1
- package/dist/utils/MoveOperationHelper.js +1 -1
- package/dist/utils/MoveOperationHelper.js.map +1 -1
- package/dist/utils/RevisionAwareProcessor.d.ts.map +1 -1
- package/dist/utils/RevisionAwareProcessor.js +2 -4
- package/dist/utils/RevisionAwareProcessor.js.map +1 -1
- package/dist/utils/RevisionWalker.d.ts.map +1 -1
- package/dist/utils/RevisionWalker.js +4 -12
- package/dist/utils/RevisionWalker.js.map +1 -1
- package/dist/utils/SelectiveRevisionAcceptor.d.ts.map +1 -1
- package/dist/utils/SelectiveRevisionAcceptor.js +2 -6
- package/dist/utils/SelectiveRevisionAcceptor.js.map +1 -1
- package/dist/utils/ShadingResolver.d.ts.map +1 -1
- package/dist/utils/ShadingResolver.js +1 -1
- package/dist/utils/ShadingResolver.js.map +1 -1
- package/dist/utils/acceptRevisions.d.ts.map +1 -1
- package/dist/utils/acceptRevisions.js +23 -12
- package/dist/utils/acceptRevisions.js.map +1 -1
- package/dist/utils/cnfStyleDecoder.d.ts +1 -1
- package/dist/utils/cnfStyleDecoder.d.ts.map +1 -1
- package/dist/utils/cnfStyleDecoder.js +40 -40
- package/dist/utils/cnfStyleDecoder.js.map +1 -1
- package/dist/utils/corruptionDetection.d.ts.map +1 -1
- package/dist/utils/corruptionDetection.js.map +1 -1
- package/dist/utils/dateFormatting.js.map +1 -1
- package/dist/utils/deepClone.js +1 -1
- package/dist/utils/deepClone.js.map +1 -1
- package/dist/utils/diagnostics.d.ts.map +1 -1
- package/dist/utils/diagnostics.js +1 -1
- package/dist/utils/diagnostics.js.map +1 -1
- package/dist/utils/errorHandling.js.map +1 -1
- package/dist/utils/formatting.d.ts.map +1 -1
- package/dist/utils/formatting.js +10 -2
- package/dist/utils/formatting.js.map +1 -1
- package/dist/utils/list-detection.d.ts +2 -2
- package/dist/utils/list-detection.d.ts.map +1 -1
- package/dist/utils/list-detection.js +21 -23
- package/dist/utils/list-detection.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +12 -7
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/parsingHelpers.js.map +1 -1
- package/dist/utils/stripTrackedChanges.d.ts.map +1 -1
- package/dist/utils/stripTrackedChanges.js +3 -3
- package/dist/utils/stripTrackedChanges.js.map +1 -1
- package/dist/utils/textDiff.d.ts +1 -1
- package/dist/utils/textDiff.js +8 -8
- package/dist/utils/textDiff.js.map +1 -1
- package/dist/utils/units.js.map +1 -1
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +24 -7
- package/dist/utils/validation.js.map +1 -1
- package/dist/utils/xmlSanitization.d.ts.map +1 -1
- package/dist/utils/xmlSanitization.js +3 -3
- package/dist/utils/xmlSanitization.js.map +1 -1
- package/dist/validation/RevisionAutoFixer.d.ts.map +1 -1
- package/dist/validation/RevisionAutoFixer.js +5 -5
- package/dist/validation/RevisionAutoFixer.js.map +1 -1
- package/dist/validation/RevisionValidator.d.ts.map +1 -1
- package/dist/validation/RevisionValidator.js +7 -9
- package/dist/validation/RevisionValidator.js.map +1 -1
- package/dist/validation/ValidationRules.js +3 -3
- package/dist/validation/ValidationRules.js.map +1 -1
- package/dist/validation/index.js.map +1 -1
- package/dist/xml/XMLBuilder.d.ts +1 -1
- package/dist/xml/XMLBuilder.d.ts.map +1 -1
- package/dist/xml/XMLBuilder.js +98 -100
- package/dist/xml/XMLBuilder.js.map +1 -1
- package/dist/xml/XMLParser.d.ts.map +1 -1
- package/dist/xml/XMLParser.js +61 -66
- package/dist/xml/XMLParser.js.map +1 -1
- package/dist/zip/ZipHandler.d.ts.map +1 -1
- package/dist/zip/ZipHandler.js.map +1 -1
- package/dist/zip/ZipReader.d.ts.map +1 -1
- package/dist/zip/ZipReader.js +1 -3
- package/dist/zip/ZipReader.js.map +1 -1
- package/dist/zip/ZipWriter.d.ts +1 -1
- package/dist/zip/ZipWriter.d.ts.map +1 -1
- package/dist/zip/ZipWriter.js +28 -36
- package/dist/zip/ZipWriter.js.map +1 -1
- package/dist/zip/types.js +1 -1
- package/dist/zip/types.js.map +1 -1
- package/package.json +92 -92
- package/src/__tests__/helper-methods.test.ts +512 -512
- package/src/constants/legacyCompatFlags.ts +138 -138
- package/src/constants/limits.ts +50 -50
- package/src/core/Document.ts +985 -1145
- package/src/core/DocumentContent.ts +461 -467
- package/src/core/DocumentGenerator.ts +1133 -1104
- package/src/core/DocumentIdManager.ts +158 -158
- package/src/core/DocumentParser.ts +2347 -2716
- package/src/core/DocumentValidator.ts +363 -372
- package/src/core/Relationship.ts +367 -367
- package/src/core/RelationshipManager.ts +429 -428
- package/src/elements/AlternateContent.ts +42 -42
- package/src/elements/Bookmark.ts +212 -210
- package/src/elements/BookmarkManager.ts +247 -250
- package/src/elements/Comment.ts +356 -359
- package/src/elements/CommentManager.ts +499 -502
- package/src/elements/CommonTypes.ts +524 -549
- package/src/elements/CustomXml.ts +36 -36
- package/src/elements/Endnote.ts +221 -217
- package/src/elements/EndnoteManager.ts +246 -249
- package/src/elements/Field.ts +1292 -1233
- package/src/elements/FieldHelpers.ts +329 -333
- package/src/elements/FontManager.ts +336 -339
- package/src/elements/Footer.ts +269 -269
- package/src/elements/Footnote.ts +221 -217
- package/src/elements/FootnoteManager.ts +246 -249
- package/src/elements/Header.ts +269 -269
- package/src/elements/HeaderFooterManager.ts +219 -219
- package/src/elements/Hyperlink.ts +1288 -1193
- package/src/elements/Image.ts +1982 -1756
- package/src/elements/ImageManager.ts +437 -432
- package/src/elements/ImageRun.ts +59 -59
- package/src/elements/MathElement.ts +65 -65
- package/src/elements/Paragraph.ts +4347 -4287
- package/src/elements/PreservedElement.ts +53 -53
- package/src/elements/PropertyChangeTypes.ts +458 -442
- package/src/elements/RangeMarker.ts +382 -400
- package/src/elements/Revision.ts +1198 -1217
- package/src/elements/RevisionContent.ts +73 -73
- package/src/elements/RevisionManager.ts +1070 -1070
- package/src/elements/Run.ts +3103 -3073
- package/src/elements/Section.ts +1521 -1421
- package/src/elements/Shape.ts +884 -873
- package/src/elements/StructuredDocumentTag.ts +1176 -1207
- package/src/elements/Table.ts +2468 -2524
- package/src/elements/TableCell.ts +1617 -1621
- package/src/elements/TableGridChange.ts +149 -151
- package/src/elements/TableOfContents.ts +701 -691
- package/src/elements/TableOfContentsElement.ts +89 -89
- package/src/elements/TableRow.ts +960 -929
- package/src/elements/TextBox.ts +766 -768
- package/src/formatting/AbstractNumbering.ts +580 -579
- package/src/formatting/NumberingInstance.ts +295 -299
- package/src/formatting/NumberingLevel.ts +981 -1040
- package/src/formatting/NumberingManager.ts +833 -827
- package/src/formatting/Style.ts +1785 -1879
- package/src/formatting/StylesManager.ts +1090 -1130
- package/src/helpers/CleanupHelper.ts +524 -524
- package/src/images/ImageOptimizer.ts +274 -274
- package/src/index.ts +559 -554
- package/src/managers/DrawingManager.ts +319 -319
- package/src/tracking/DocumentTrackingContext.ts +687 -674
- package/src/tracking/TrackingContext.ts +175 -173
- package/src/types/compatibility-types.ts +49 -49
- package/src/types/formatting.ts +210 -210
- package/src/types/list-types.ts +14 -14
- package/src/types/settings-types.ts +59 -59
- package/src/types/styleConfig.ts +189 -189
- package/src/utils/ChangelogGenerator.ts +1583 -1581
- package/src/utils/CompatibilityUpgrader.ts +235 -237
- package/src/utils/InMemoryRevisionAcceptor.ts +691 -696
- package/src/utils/MoveOperationHelper.ts +233 -238
- package/src/utils/RevisionAwareProcessor.ts +518 -526
- package/src/utils/RevisionWalker.ts +427 -457
- package/src/utils/SelectiveRevisionAcceptor.ts +662 -683
- package/src/utils/ShadingResolver.ts +105 -107
- package/src/utils/acceptRevisions.ts +723 -714
- package/src/utils/cnfStyleDecoder.ts +212 -217
- package/src/utils/corruptionDetection.ts +346 -345
- package/src/utils/dateFormatting.ts +20 -20
- package/src/utils/deepClone.ts +77 -78
- package/src/utils/diagnostics.ts +125 -129
- package/src/utils/errorHandling.ts +80 -80
- package/src/utils/formatting.ts +220 -213
- package/src/utils/list-detection.ts +32 -42
- package/src/utils/logger.ts +412 -404
- package/src/utils/parsingHelpers.ts +190 -190
- package/src/utils/stripTrackedChanges.ts +356 -353
- package/src/utils/textDiff.ts +100 -100
- package/src/utils/units.ts +421 -421
- package/src/utils/validation.ts +553 -542
- package/src/utils/xmlSanitization.ts +179 -182
- package/src/validation/RevisionAutoFixer.ts +541 -542
- package/src/validation/RevisionValidator.ts +470 -460
- package/src/validation/ValidationRules.ts +338 -338
- package/src/validation/index.ts +30 -30
- package/src/xml/XMLBuilder.ts +857 -871
- package/src/xml/XMLParser.ts +877 -919
- package/src/zip/ZipHandler.ts +629 -637
- package/src/zip/ZipReader.ts +295 -299
- package/src/zip/ZipWriter.ts +374 -390
- package/src/zip/types.ts +116 -116
package/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++;
|
|
@@ -2815,15 +2839,15 @@ class Document {
|
|
|
2815
2839
|
if (!abstractNum)
|
|
2816
2840
|
continue;
|
|
2817
2841
|
const level0 = abstractNum.getLevel(0);
|
|
2818
|
-
if (level0?.getFormat() !==
|
|
2842
|
+
if (level0?.getFormat() !== 'bullet')
|
|
2819
2843
|
continue;
|
|
2820
2844
|
for (let levelIndex = 0; levelIndex < 9; levelIndex++) {
|
|
2821
2845
|
const numLevel = abstractNum.getLevel(levelIndex);
|
|
2822
2846
|
if (!numLevel)
|
|
2823
2847
|
continue;
|
|
2824
|
-
const bullet = levelIndex % 2 === 0 ?
|
|
2848
|
+
const bullet = levelIndex % 2 === 0 ? '•' : '○';
|
|
2825
2849
|
numLevel.setText(bullet);
|
|
2826
|
-
numLevel.setFont(
|
|
2850
|
+
numLevel.setFont('Arial');
|
|
2827
2851
|
numLevel.setFontSize(24);
|
|
2828
2852
|
numLevel.setLeftIndent(720 * (levelIndex + 1));
|
|
2829
2853
|
numLevel.setHangingIndent(360);
|
|
@@ -2842,17 +2866,17 @@ class Document {
|
|
|
2842
2866
|
if (!abstractNum)
|
|
2843
2867
|
continue;
|
|
2844
2868
|
const level0 = abstractNum.getLevel(0);
|
|
2845
|
-
if (!level0 || level0.getFormat() ===
|
|
2869
|
+
if (!level0 || level0.getFormat() === 'bullet')
|
|
2846
2870
|
continue;
|
|
2847
2871
|
for (let levelIndex = 0; levelIndex < 9; levelIndex++) {
|
|
2848
2872
|
const numLevel = abstractNum.getLevel(levelIndex);
|
|
2849
2873
|
if (!numLevel)
|
|
2850
2874
|
continue;
|
|
2851
|
-
numLevel.setFont(
|
|
2875
|
+
numLevel.setFont('Verdana');
|
|
2852
2876
|
numLevel.setFontSize(24);
|
|
2853
2877
|
numLevel.setLeftIndent(720 * (levelIndex + 1));
|
|
2854
2878
|
numLevel.setHangingIndent(360);
|
|
2855
|
-
numLevel.setAlignment(
|
|
2879
|
+
numLevel.setAlignment('left');
|
|
2856
2880
|
}
|
|
2857
2881
|
this.applyFormattingToListParagraphs(instance.getNumId());
|
|
2858
2882
|
count++;
|
|
@@ -2866,7 +2890,7 @@ class Document {
|
|
|
2866
2890
|
if (numbering?.numId === numId) {
|
|
2867
2891
|
const runs = para.getRuns();
|
|
2868
2892
|
for (const run of runs) {
|
|
2869
|
-
run.setFont(
|
|
2893
|
+
run.setFont('Verdana', 12);
|
|
2870
2894
|
}
|
|
2871
2895
|
para.setSpaceBefore(0);
|
|
2872
2896
|
para.setSpaceAfter(60);
|
|
@@ -2894,12 +2918,12 @@ class Document {
|
|
|
2894
2918
|
wrapParagraphInTable(para, options) {
|
|
2895
2919
|
const paraIndex = this.bodyElements.indexOf(para);
|
|
2896
2920
|
if (paraIndex === -1) {
|
|
2897
|
-
throw new Error(
|
|
2921
|
+
throw new Error('Paragraph not found in document body elements');
|
|
2898
2922
|
}
|
|
2899
2923
|
const table = new Table_1.Table(1, 1);
|
|
2900
2924
|
const cell = table.getCell(0, 0);
|
|
2901
2925
|
if (!cell) {
|
|
2902
|
-
throw new Error(
|
|
2926
|
+
throw new Error('Failed to get cell from newly created table');
|
|
2903
2927
|
}
|
|
2904
2928
|
this.bodyElements.splice(paraIndex, 1);
|
|
2905
2929
|
cell.addParagraph(para);
|
|
@@ -2919,36 +2943,36 @@ class Document {
|
|
|
2919
2943
|
}
|
|
2920
2944
|
if (options.tableWidthPercent !== undefined) {
|
|
2921
2945
|
table.setWidth(options.tableWidthPercent);
|
|
2922
|
-
table.setWidthType(
|
|
2946
|
+
table.setWidthType('pct');
|
|
2923
2947
|
}
|
|
2924
2948
|
this.bodyElements.splice(paraIndex, 0, table);
|
|
2925
2949
|
return table;
|
|
2926
2950
|
}
|
|
2927
2951
|
static DEFAULT_HEADING1_CONFIG = {
|
|
2928
2952
|
run: {
|
|
2929
|
-
font:
|
|
2953
|
+
font: 'Verdana',
|
|
2930
2954
|
size: 18,
|
|
2931
2955
|
bold: true,
|
|
2932
|
-
color:
|
|
2956
|
+
color: '000000',
|
|
2933
2957
|
},
|
|
2934
2958
|
paragraph: {
|
|
2935
|
-
alignment:
|
|
2936
|
-
spacing: { before: 0, after: 240, line: 240, lineRule:
|
|
2959
|
+
alignment: 'left',
|
|
2960
|
+
spacing: { before: 0, after: 240, line: 240, lineRule: 'auto' },
|
|
2937
2961
|
},
|
|
2938
2962
|
};
|
|
2939
2963
|
static DEFAULT_HEADING2_CONFIG = {
|
|
2940
2964
|
run: {
|
|
2941
|
-
font:
|
|
2965
|
+
font: 'Verdana',
|
|
2942
2966
|
size: 14,
|
|
2943
2967
|
bold: true,
|
|
2944
|
-
color:
|
|
2968
|
+
color: '000000',
|
|
2945
2969
|
},
|
|
2946
2970
|
paragraph: {
|
|
2947
|
-
alignment:
|
|
2948
|
-
spacing: { before: 120, after: 120, line: 240, lineRule:
|
|
2971
|
+
alignment: 'left',
|
|
2972
|
+
spacing: { before: 120, after: 120, line: 240, lineRule: 'auto' },
|
|
2949
2973
|
},
|
|
2950
2974
|
tableOptions: {
|
|
2951
|
-
shading:
|
|
2975
|
+
shading: 'BFBFBF',
|
|
2952
2976
|
marginTop: 0,
|
|
2953
2977
|
marginBottom: 0,
|
|
2954
2978
|
marginLeft: 115,
|
|
@@ -2958,36 +2982,36 @@ class Document {
|
|
|
2958
2982
|
};
|
|
2959
2983
|
static DEFAULT_HEADING3_CONFIG = {
|
|
2960
2984
|
run: {
|
|
2961
|
-
font:
|
|
2985
|
+
font: 'Verdana',
|
|
2962
2986
|
size: 12,
|
|
2963
2987
|
bold: true,
|
|
2964
|
-
color:
|
|
2988
|
+
color: '000000',
|
|
2965
2989
|
},
|
|
2966
2990
|
paragraph: {
|
|
2967
|
-
alignment:
|
|
2968
|
-
spacing: { before: 60, after: 60, line: 240, lineRule:
|
|
2991
|
+
alignment: 'left',
|
|
2992
|
+
spacing: { before: 60, after: 60, line: 240, lineRule: 'auto' },
|
|
2969
2993
|
},
|
|
2970
2994
|
};
|
|
2971
2995
|
static DEFAULT_NORMAL_CONFIG = {
|
|
2972
2996
|
run: {
|
|
2973
|
-
font:
|
|
2997
|
+
font: 'Verdana',
|
|
2974
2998
|
size: 12,
|
|
2975
|
-
color:
|
|
2999
|
+
color: '000000',
|
|
2976
3000
|
},
|
|
2977
3001
|
paragraph: {
|
|
2978
|
-
alignment:
|
|
2979
|
-
spacing: { before: 60, after: 60, line: 240, lineRule:
|
|
3002
|
+
alignment: 'left',
|
|
3003
|
+
spacing: { before: 60, after: 60, line: 240, lineRule: 'auto' },
|
|
2980
3004
|
},
|
|
2981
3005
|
};
|
|
2982
3006
|
static DEFAULT_LIST_PARAGRAPH_CONFIG = {
|
|
2983
3007
|
run: {
|
|
2984
|
-
font:
|
|
3008
|
+
font: 'Verdana',
|
|
2985
3009
|
size: 12,
|
|
2986
|
-
color:
|
|
3010
|
+
color: '000000',
|
|
2987
3011
|
},
|
|
2988
3012
|
paragraph: {
|
|
2989
|
-
alignment:
|
|
2990
|
-
spacing: { before: 0, after: 60, line: 240, lineRule:
|
|
3013
|
+
alignment: 'left',
|
|
3014
|
+
spacing: { before: 0, after: 60, line: 240, lineRule: 'auto' },
|
|
2991
3015
|
indentation: { left: 360, hanging: 360 },
|
|
2992
3016
|
contextualSpacing: true,
|
|
2993
3017
|
},
|
|
@@ -3018,32 +3042,28 @@ class Document {
|
|
|
3018
3042
|
normal: false,
|
|
3019
3043
|
listParagraph: false,
|
|
3020
3044
|
};
|
|
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(
|
|
3045
|
+
const heading1 = this.stylesManager.getStyle('Heading1');
|
|
3046
|
+
const heading2 = this.stylesManager.getStyle('Heading2');
|
|
3047
|
+
const heading3 = this.stylesManager.getStyle('Heading3');
|
|
3048
|
+
const normal = this.stylesManager.getStyle('Normal');
|
|
3049
|
+
const listParagraph = this.stylesManager.getStyle('ListParagraph');
|
|
3026
3050
|
const h1Config = {
|
|
3027
3051
|
run: {
|
|
3028
|
-
...(heading1?.getRunFormatting() ||
|
|
3029
|
-
Document.DEFAULT_HEADING1_CONFIG.run),
|
|
3052
|
+
...(heading1?.getRunFormatting() || Document.DEFAULT_HEADING1_CONFIG.run),
|
|
3030
3053
|
...options?.heading1?.run,
|
|
3031
3054
|
},
|
|
3032
3055
|
paragraph: {
|
|
3033
|
-
...(heading1?.getParagraphFormatting() ||
|
|
3034
|
-
Document.DEFAULT_HEADING1_CONFIG.paragraph),
|
|
3056
|
+
...(heading1?.getParagraphFormatting() || Document.DEFAULT_HEADING1_CONFIG.paragraph),
|
|
3035
3057
|
...options?.heading1?.paragraph,
|
|
3036
3058
|
},
|
|
3037
3059
|
};
|
|
3038
3060
|
const h2Config = {
|
|
3039
3061
|
run: {
|
|
3040
|
-
...(heading2?.getRunFormatting() ||
|
|
3041
|
-
Document.DEFAULT_HEADING2_CONFIG.run),
|
|
3062
|
+
...(heading2?.getRunFormatting() || Document.DEFAULT_HEADING2_CONFIG.run),
|
|
3042
3063
|
...options?.heading2?.run,
|
|
3043
3064
|
},
|
|
3044
3065
|
paragraph: {
|
|
3045
|
-
...(heading2?.getParagraphFormatting() ||
|
|
3046
|
-
Document.DEFAULT_HEADING2_CONFIG.paragraph),
|
|
3066
|
+
...(heading2?.getParagraphFormatting() || Document.DEFAULT_HEADING2_CONFIG.paragraph),
|
|
3047
3067
|
...options?.heading2?.paragraph,
|
|
3048
3068
|
},
|
|
3049
3069
|
tableOptions: {
|
|
@@ -3053,13 +3073,11 @@ class Document {
|
|
|
3053
3073
|
};
|
|
3054
3074
|
const h3Config = {
|
|
3055
3075
|
run: {
|
|
3056
|
-
...(heading3?.getRunFormatting() ||
|
|
3057
|
-
Document.DEFAULT_HEADING3_CONFIG.run),
|
|
3076
|
+
...(heading3?.getRunFormatting() || Document.DEFAULT_HEADING3_CONFIG.run),
|
|
3058
3077
|
...options?.heading3?.run,
|
|
3059
3078
|
},
|
|
3060
3079
|
paragraph: {
|
|
3061
|
-
...(heading3?.getParagraphFormatting() ||
|
|
3062
|
-
Document.DEFAULT_HEADING3_CONFIG.paragraph),
|
|
3080
|
+
...(heading3?.getParagraphFormatting() || Document.DEFAULT_HEADING3_CONFIG.paragraph),
|
|
3063
3081
|
...options?.heading3?.paragraph,
|
|
3064
3082
|
},
|
|
3065
3083
|
};
|
|
@@ -3069,15 +3087,13 @@ class Document {
|
|
|
3069
3087
|
...options?.normal?.run,
|
|
3070
3088
|
},
|
|
3071
3089
|
paragraph: {
|
|
3072
|
-
...(normal?.getParagraphFormatting() ||
|
|
3073
|
-
Document.DEFAULT_NORMAL_CONFIG.paragraph),
|
|
3090
|
+
...(normal?.getParagraphFormatting() || Document.DEFAULT_NORMAL_CONFIG.paragraph),
|
|
3074
3091
|
...options?.normal?.paragraph,
|
|
3075
3092
|
},
|
|
3076
3093
|
};
|
|
3077
3094
|
const listParaConfig = {
|
|
3078
3095
|
run: {
|
|
3079
|
-
...(listParagraph?.getRunFormatting() ||
|
|
3080
|
-
Document.DEFAULT_LIST_PARAGRAPH_CONFIG.run),
|
|
3096
|
+
...(listParagraph?.getRunFormatting() || Document.DEFAULT_LIST_PARAGRAPH_CONFIG.run),
|
|
3081
3097
|
...options?.listParagraph?.run,
|
|
3082
3098
|
},
|
|
3083
3099
|
paragraph: {
|
|
@@ -3119,7 +3135,7 @@ class Document {
|
|
|
3119
3135
|
this.addStyle(normal);
|
|
3120
3136
|
const shouldLinkNormalWeb = options?.linkNormalWebToNormal !== false;
|
|
3121
3137
|
if (shouldLinkNormalWeb) {
|
|
3122
|
-
const normalWeb = this.stylesManager.getStyle(
|
|
3138
|
+
const normalWeb = this.stylesManager.getStyle('NormalWeb');
|
|
3123
3139
|
if (normalWeb) {
|
|
3124
3140
|
if (normalConfig.run)
|
|
3125
3141
|
normalWeb.setRunFormatting(normalConfig.run);
|
|
@@ -3180,10 +3196,10 @@ class Document {
|
|
|
3180
3196
|
continue;
|
|
3181
3197
|
}
|
|
3182
3198
|
const styleId = para.getStyle();
|
|
3183
|
-
if (styleId ===
|
|
3199
|
+
if (styleId === 'Heading1' && heading1) {
|
|
3184
3200
|
const allRuns = this.getAllRunsFromParagraph(para);
|
|
3185
3201
|
const whiteFontRuns = new Set(options?.preserveWhiteFont
|
|
3186
|
-
? allRuns.filter(run => run.getColor()?.toUpperCase() === 'FFFFFF')
|
|
3202
|
+
? allRuns.filter((run) => run.getColor()?.toUpperCase() === 'FFFFFF')
|
|
3187
3203
|
: []);
|
|
3188
3204
|
para.clearDirectFormattingConflicts(heading1);
|
|
3189
3205
|
for (const run of allRuns) {
|
|
@@ -3197,7 +3213,7 @@ class Document {
|
|
|
3197
3213
|
run.setItalic(h1Config.run?.italic ?? false);
|
|
3198
3214
|
}
|
|
3199
3215
|
if (!h1Preserve.underline) {
|
|
3200
|
-
run.setUnderline(h1Config.run?.underline ?
|
|
3216
|
+
run.setUnderline(h1Config.run?.underline ? 'single' : false);
|
|
3201
3217
|
}
|
|
3202
3218
|
if (h1Config.run?.font) {
|
|
3203
3219
|
run.setFont(h1Config.run.font);
|
|
@@ -3216,19 +3232,13 @@ class Document {
|
|
|
3216
3232
|
}
|
|
3217
3233
|
if (para.formatting.paragraphMarkRunProperties) {
|
|
3218
3234
|
const markProps = para.formatting.paragraphMarkRunProperties;
|
|
3219
|
-
if (!h1Preserve.bold &&
|
|
3220
|
-
h1Config.run?.bold === false &&
|
|
3221
|
-
markProps.bold) {
|
|
3235
|
+
if (!h1Preserve.bold && h1Config.run?.bold === false && markProps.bold) {
|
|
3222
3236
|
delete markProps.bold;
|
|
3223
3237
|
}
|
|
3224
|
-
if (!h1Preserve.italic &&
|
|
3225
|
-
h1Config.run?.italic === false &&
|
|
3226
|
-
markProps.italic) {
|
|
3238
|
+
if (!h1Preserve.italic && h1Config.run?.italic === false && markProps.italic) {
|
|
3227
3239
|
delete markProps.italic;
|
|
3228
3240
|
}
|
|
3229
|
-
if (!h1Preserve.underline &&
|
|
3230
|
-
h1Config.run?.underline === false &&
|
|
3231
|
-
markProps.underline) {
|
|
3241
|
+
if (!h1Preserve.underline && h1Config.run?.underline === false && markProps.underline) {
|
|
3232
3242
|
delete markProps.underline;
|
|
3233
3243
|
}
|
|
3234
3244
|
if (h1Config.run?.font) {
|
|
@@ -3243,9 +3253,8 @@ class Document {
|
|
|
3243
3253
|
}
|
|
3244
3254
|
processedParagraphs.add(para);
|
|
3245
3255
|
}
|
|
3246
|
-
else if (styleId ===
|
|
3247
|
-
const hasContent = this.getAllRunsFromParagraph(para)
|
|
3248
|
-
.some((run) => run.getText().trim().length > 0);
|
|
3256
|
+
else if (styleId === 'Heading2' && heading2) {
|
|
3257
|
+
const hasContent = this.getAllRunsFromParagraph(para).some((run) => run.getText().trim().length > 0);
|
|
3249
3258
|
if (!hasContent) {
|
|
3250
3259
|
processedParagraphs.add(para);
|
|
3251
3260
|
continue;
|
|
@@ -3267,8 +3276,7 @@ class Document {
|
|
|
3267
3276
|
const colCount = table.getColumnCount();
|
|
3268
3277
|
const isMultiCellTable = !(rowCount === 1 && colCount === 1);
|
|
3269
3278
|
const cellFormatting = cell.getFormatting();
|
|
3270
|
-
const cellHasShading = !!(cellFormatting?.shading?.fill ||
|
|
3271
|
-
cellFormatting?.shading?.pattern);
|
|
3279
|
+
const cellHasShading = !!(cellFormatting?.shading?.fill || cellFormatting?.shading?.pattern);
|
|
3272
3280
|
if (isMultiCellTable && cellHasShading && para.formatting.alignment) {
|
|
3273
3281
|
preservedAlignment = para.formatting.alignment;
|
|
3274
3282
|
}
|
|
@@ -3276,7 +3284,7 @@ class Document {
|
|
|
3276
3284
|
}
|
|
3277
3285
|
const allRuns = this.getAllRunsFromParagraph(para);
|
|
3278
3286
|
const whiteFontRuns = new Set(options?.preserveWhiteFont
|
|
3279
|
-
? allRuns.filter(run => run.getColor()?.toUpperCase() === 'FFFFFF')
|
|
3287
|
+
? allRuns.filter((run) => run.getColor()?.toUpperCase() === 'FFFFFF')
|
|
3280
3288
|
: []);
|
|
3281
3289
|
para.clearDirectFormattingConflicts(heading2);
|
|
3282
3290
|
if (preservedAlignment) {
|
|
@@ -3293,7 +3301,7 @@ class Document {
|
|
|
3293
3301
|
run.setItalic(h2Config.run?.italic ?? false);
|
|
3294
3302
|
}
|
|
3295
3303
|
if (!h2Preserve.underline) {
|
|
3296
|
-
run.setUnderline(h2Config.run?.underline ?
|
|
3304
|
+
run.setUnderline(h2Config.run?.underline ? 'single' : false);
|
|
3297
3305
|
}
|
|
3298
3306
|
if (h2Config.run?.font) {
|
|
3299
3307
|
run.setFont(h2Config.run.font);
|
|
@@ -3312,19 +3320,13 @@ class Document {
|
|
|
3312
3320
|
}
|
|
3313
3321
|
if (para.formatting.paragraphMarkRunProperties) {
|
|
3314
3322
|
const markProps = para.formatting.paragraphMarkRunProperties;
|
|
3315
|
-
if (!h2Preserve.bold &&
|
|
3316
|
-
h2Config.run?.bold === false &&
|
|
3317
|
-
markProps.bold) {
|
|
3323
|
+
if (!h2Preserve.bold && h2Config.run?.bold === false && markProps.bold) {
|
|
3318
3324
|
delete markProps.bold;
|
|
3319
3325
|
}
|
|
3320
|
-
if (!h2Preserve.italic &&
|
|
3321
|
-
h2Config.run?.italic === false &&
|
|
3322
|
-
markProps.italic) {
|
|
3326
|
+
if (!h2Preserve.italic && h2Config.run?.italic === false && markProps.italic) {
|
|
3323
3327
|
delete markProps.italic;
|
|
3324
3328
|
}
|
|
3325
|
-
if (!h2Preserve.underline &&
|
|
3326
|
-
h2Config.run?.underline === false &&
|
|
3327
|
-
markProps.underline) {
|
|
3329
|
+
if (!h2Preserve.underline && h2Config.run?.underline === false && markProps.underline) {
|
|
3328
3330
|
delete markProps.underline;
|
|
3329
3331
|
}
|
|
3330
3332
|
if (h2Config.run?.font) {
|
|
@@ -3364,13 +3366,13 @@ class Document {
|
|
|
3364
3366
|
});
|
|
3365
3367
|
if (table) {
|
|
3366
3368
|
table.setWidth(h2Config.tableOptions.tableWidthPercent);
|
|
3367
|
-
table.setWidthType(
|
|
3369
|
+
table.setWidthType('pct');
|
|
3368
3370
|
}
|
|
3369
3371
|
}
|
|
3370
3372
|
}
|
|
3371
3373
|
else {
|
|
3372
3374
|
const table = this.wrapParagraphInTable(para, {
|
|
3373
|
-
shading: h2Config.tableOptions?.shading ??
|
|
3375
|
+
shading: h2Config.tableOptions?.shading ?? 'BFBFBF',
|
|
3374
3376
|
marginTop: h2Config.tableOptions?.marginTop ?? 0,
|
|
3375
3377
|
marginBottom: h2Config.tableOptions?.marginBottom ?? 0,
|
|
3376
3378
|
marginLeft: h2Config.tableOptions?.marginLeft ?? 115,
|
|
@@ -3392,7 +3394,7 @@ class Document {
|
|
|
3392
3394
|
}
|
|
3393
3395
|
if (item.getText) {
|
|
3394
3396
|
const text = item.getText().trim();
|
|
3395
|
-
if (text !==
|
|
3397
|
+
if (text !== '')
|
|
3396
3398
|
return false;
|
|
3397
3399
|
}
|
|
3398
3400
|
}
|
|
@@ -3410,10 +3412,10 @@ class Document {
|
|
|
3410
3412
|
}
|
|
3411
3413
|
processedParagraphs.add(para);
|
|
3412
3414
|
}
|
|
3413
|
-
else if (styleId ===
|
|
3415
|
+
else if (styleId === 'Heading3' && heading3) {
|
|
3414
3416
|
const allRuns = this.getAllRunsFromParagraph(para);
|
|
3415
3417
|
const whiteFontRuns = new Set(options?.preserveWhiteFont
|
|
3416
|
-
? allRuns.filter(run => run.getColor()?.toUpperCase() === 'FFFFFF')
|
|
3418
|
+
? allRuns.filter((run) => run.getColor()?.toUpperCase() === 'FFFFFF')
|
|
3417
3419
|
: []);
|
|
3418
3420
|
para.clearDirectFormattingConflicts(heading3);
|
|
3419
3421
|
for (const run of allRuns) {
|
|
@@ -3427,7 +3429,7 @@ class Document {
|
|
|
3427
3429
|
run.setItalic(h3Config.run?.italic ?? false);
|
|
3428
3430
|
}
|
|
3429
3431
|
if (!h3Preserve.underline) {
|
|
3430
|
-
run.setUnderline(h3Config.run?.underline ?
|
|
3432
|
+
run.setUnderline(h3Config.run?.underline ? 'single' : false);
|
|
3431
3433
|
}
|
|
3432
3434
|
if (h3Config.run?.font) {
|
|
3433
3435
|
run.setFont(h3Config.run.font);
|
|
@@ -3446,19 +3448,13 @@ class Document {
|
|
|
3446
3448
|
}
|
|
3447
3449
|
if (para.formatting.paragraphMarkRunProperties) {
|
|
3448
3450
|
const markProps = para.formatting.paragraphMarkRunProperties;
|
|
3449
|
-
if (!h3Preserve.bold &&
|
|
3450
|
-
h3Config.run?.bold === false &&
|
|
3451
|
-
markProps.bold) {
|
|
3451
|
+
if (!h3Preserve.bold && h3Config.run?.bold === false && markProps.bold) {
|
|
3452
3452
|
delete markProps.bold;
|
|
3453
3453
|
}
|
|
3454
|
-
if (!h3Preserve.italic &&
|
|
3455
|
-
h3Config.run?.italic === false &&
|
|
3456
|
-
markProps.italic) {
|
|
3454
|
+
if (!h3Preserve.italic && h3Config.run?.italic === false && markProps.italic) {
|
|
3457
3455
|
delete markProps.italic;
|
|
3458
3456
|
}
|
|
3459
|
-
if (!h3Preserve.underline &&
|
|
3460
|
-
h3Config.run?.underline === false &&
|
|
3461
|
-
markProps.underline) {
|
|
3457
|
+
if (!h3Preserve.underline && h3Config.run?.underline === false && markProps.underline) {
|
|
3462
3458
|
delete markProps.underline;
|
|
3463
3459
|
}
|
|
3464
3460
|
if (h3Config.run?.font) {
|
|
@@ -3473,11 +3469,11 @@ class Document {
|
|
|
3473
3469
|
}
|
|
3474
3470
|
processedParagraphs.add(para);
|
|
3475
3471
|
}
|
|
3476
|
-
else if (styleId ===
|
|
3472
|
+
else if (styleId === 'ListParagraph' && listParagraph) {
|
|
3477
3473
|
const paraIndentation = para.getFormatting().indentation;
|
|
3478
3474
|
const hasNumbering = para.getNumbering();
|
|
3479
3475
|
if (paraIndentation?.left === 0 && !hasNumbering) {
|
|
3480
|
-
para.setStyle(
|
|
3476
|
+
para.setStyle('Normal');
|
|
3481
3477
|
const allRuns = this.getAllRunsFromParagraph(para);
|
|
3482
3478
|
const preservedBold = allRuns.map((run) => ({
|
|
3483
3479
|
run,
|
|
@@ -3547,7 +3543,7 @@ class Document {
|
|
|
3547
3543
|
run.setItalic(listParaConfig.run?.italic ?? false);
|
|
3548
3544
|
}
|
|
3549
3545
|
if (!listParaPreserve.underline) {
|
|
3550
|
-
run.setUnderline(listParaConfig.run?.underline ?
|
|
3546
|
+
run.setUnderline(listParaConfig.run?.underline ? 'single' : false);
|
|
3551
3547
|
}
|
|
3552
3548
|
if (listParaConfig.run?.font) {
|
|
3553
3549
|
run.setFont(listParaConfig.run.font);
|
|
@@ -3566,9 +3562,7 @@ class Document {
|
|
|
3566
3562
|
}
|
|
3567
3563
|
if (para.formatting.paragraphMarkRunProperties) {
|
|
3568
3564
|
const markProps = para.formatting.paragraphMarkRunProperties;
|
|
3569
|
-
if (!listParaPreserve.bold &&
|
|
3570
|
-
listParaConfig.run?.bold === false &&
|
|
3571
|
-
markProps.bold) {
|
|
3565
|
+
if (!listParaPreserve.bold && listParaConfig.run?.bold === false && markProps.bold) {
|
|
3572
3566
|
delete markProps.bold;
|
|
3573
3567
|
}
|
|
3574
3568
|
if (!listParaPreserve.italic &&
|
|
@@ -3593,7 +3587,10 @@ class Document {
|
|
|
3593
3587
|
}
|
|
3594
3588
|
processedParagraphs.add(para);
|
|
3595
3589
|
}
|
|
3596
|
-
else if ((styleId ===
|
|
3590
|
+
else if ((styleId === 'Normal' ||
|
|
3591
|
+
styleId === undefined ||
|
|
3592
|
+
(styleId === 'NormalWeb' && options?.linkNormalWebToNormal !== false)) &&
|
|
3593
|
+
normal) {
|
|
3597
3594
|
const allRuns = this.getAllRunsFromParagraph(para);
|
|
3598
3595
|
const preservedFormatting = allRuns.map((run) => {
|
|
3599
3596
|
const fmt = run.getFormatting();
|
|
@@ -3605,8 +3602,7 @@ class Document {
|
|
|
3605
3602
|
isWhiteFont: options?.preserveWhiteFont && fmt.color?.toUpperCase() === 'FFFFFF',
|
|
3606
3603
|
};
|
|
3607
3604
|
});
|
|
3608
|
-
const savedCenterAlignment = options?.normal?.preserveCenterAlignment &&
|
|
3609
|
-
para.getAlignment() === 'center';
|
|
3605
|
+
const savedCenterAlignment = options?.normal?.preserveCenterAlignment && para.getAlignment() === 'center';
|
|
3610
3606
|
para.clearDirectFormattingConflicts(normal);
|
|
3611
3607
|
if (savedCenterAlignment) {
|
|
3612
3608
|
para.setAlignment('center');
|
|
@@ -3634,7 +3630,7 @@ class Document {
|
|
|
3634
3630
|
run.setItalic(normalConfig.run?.italic ?? false);
|
|
3635
3631
|
}
|
|
3636
3632
|
if (!normalPreserve.underline) {
|
|
3637
|
-
run.setUnderline(normalConfig.run?.underline ?
|
|
3633
|
+
run.setUnderline(normalConfig.run?.underline ? 'single' : false);
|
|
3638
3634
|
}
|
|
3639
3635
|
if (normalConfig.run?.font) {
|
|
3640
3636
|
run.setFont(normalConfig.run.font);
|
|
@@ -3653,14 +3649,10 @@ class Document {
|
|
|
3653
3649
|
}
|
|
3654
3650
|
if (para.formatting.paragraphMarkRunProperties) {
|
|
3655
3651
|
const markProps = para.formatting.paragraphMarkRunProperties;
|
|
3656
|
-
if (!normalPreserve.bold &&
|
|
3657
|
-
normalConfig.run?.bold === false &&
|
|
3658
|
-
markProps.bold) {
|
|
3652
|
+
if (!normalPreserve.bold && normalConfig.run?.bold === false && markProps.bold) {
|
|
3659
3653
|
delete markProps.bold;
|
|
3660
3654
|
}
|
|
3661
|
-
if (!normalPreserve.italic &&
|
|
3662
|
-
normalConfig.run?.italic === false &&
|
|
3663
|
-
markProps.italic) {
|
|
3655
|
+
if (!normalPreserve.italic && normalConfig.run?.italic === false && markProps.italic) {
|
|
3664
3656
|
delete markProps.italic;
|
|
3665
3657
|
}
|
|
3666
3658
|
if (!normalPreserve.underline &&
|
|
@@ -3684,8 +3676,7 @@ class Document {
|
|
|
3684
3676
|
return results;
|
|
3685
3677
|
}
|
|
3686
3678
|
formatTOCStyles(options) {
|
|
3687
|
-
const validLevels = (options.levels ?? [1, 2, 3, 4, 5, 6, 7, 8, 9])
|
|
3688
|
-
.filter((l) => l >= 1 && l <= 9);
|
|
3679
|
+
const validLevels = (options.levels ?? [1, 2, 3, 4, 5, 6, 7, 8, 9]).filter((l) => l >= 1 && l <= 9);
|
|
3689
3680
|
const levels = [...new Set(validLevels)].sort((a, b) => a - b);
|
|
3690
3681
|
const formatted = [];
|
|
3691
3682
|
for (let i = 0; i < levels.length; i++) {
|
|
@@ -3726,32 +3717,32 @@ class Document {
|
|
|
3726
3717
|
for (const style of styles) {
|
|
3727
3718
|
const styleId = style.getStyleId();
|
|
3728
3719
|
switch (styleId) {
|
|
3729
|
-
case
|
|
3720
|
+
case 'Heading1':
|
|
3730
3721
|
options.heading1 = {
|
|
3731
3722
|
run: style.getRunFormatting(),
|
|
3732
3723
|
paragraph: style.getParagraphFormatting(),
|
|
3733
3724
|
};
|
|
3734
3725
|
break;
|
|
3735
|
-
case
|
|
3726
|
+
case 'Heading2':
|
|
3736
3727
|
options.heading2 = {
|
|
3737
3728
|
run: style.getRunFormatting(),
|
|
3738
3729
|
paragraph: style.getParagraphFormatting(),
|
|
3739
3730
|
tableOptions: style.getHeading2TableOptions(),
|
|
3740
3731
|
};
|
|
3741
3732
|
break;
|
|
3742
|
-
case
|
|
3733
|
+
case 'Heading3':
|
|
3743
3734
|
options.heading3 = {
|
|
3744
3735
|
run: style.getRunFormatting(),
|
|
3745
3736
|
paragraph: style.getParagraphFormatting(),
|
|
3746
3737
|
};
|
|
3747
3738
|
break;
|
|
3748
|
-
case
|
|
3739
|
+
case 'Normal':
|
|
3749
3740
|
options.normal = {
|
|
3750
3741
|
run: style.getRunFormatting(),
|
|
3751
3742
|
paragraph: style.getParagraphFormatting(),
|
|
3752
3743
|
};
|
|
3753
3744
|
break;
|
|
3754
|
-
case
|
|
3745
|
+
case 'ListParagraph':
|
|
3755
3746
|
options.listParagraph = {
|
|
3756
3747
|
run: style.getRunFormatting(),
|
|
3757
3748
|
paragraph: style.getParagraphFormatting(),
|
|
@@ -3764,8 +3755,8 @@ class Document {
|
|
|
3764
3755
|
return this.applyStyles(options);
|
|
3765
3756
|
}
|
|
3766
3757
|
updateTableStyleShading(oldColor, newColor) {
|
|
3767
|
-
const normalizedOld = oldColor.replace(
|
|
3768
|
-
const normalizedNew = newColor.replace(
|
|
3758
|
+
const normalizedOld = oldColor.replace('#', '').toUpperCase();
|
|
3759
|
+
const normalizedNew = newColor.replace('#', '').toUpperCase();
|
|
3769
3760
|
if (normalizedOld === normalizedNew) {
|
|
3770
3761
|
return 0;
|
|
3771
3762
|
}
|
|
@@ -3774,12 +3765,12 @@ class Document {
|
|
|
3774
3765
|
return 0;
|
|
3775
3766
|
}
|
|
3776
3767
|
let updateCount = 0;
|
|
3777
|
-
const fillPattern = new RegExp(`(w:fill=["'])${normalizedOld}(["'])`,
|
|
3768
|
+
const fillPattern = new RegExp(`(w:fill=["'])${normalizedOld}(["'])`, 'gi');
|
|
3778
3769
|
stylesXml = stylesXml.replace(fillPattern, (match, prefix, suffix) => {
|
|
3779
3770
|
updateCount++;
|
|
3780
3771
|
return `${prefix}${normalizedNew}${suffix}`;
|
|
3781
3772
|
});
|
|
3782
|
-
const colorPattern = new RegExp(`(<w:shd[^>]*w:color=["'])${normalizedOld}(["'])`,
|
|
3773
|
+
const colorPattern = new RegExp(`(<w:shd[^>]*w:color=["'])${normalizedOld}(["'])`, 'gi');
|
|
3783
3774
|
stylesXml = stylesXml.replace(colorPattern, (match, prefix, suffix) => {
|
|
3784
3775
|
updateCount++;
|
|
3785
3776
|
return `${prefix}${normalizedNew}${suffix}`;
|
|
@@ -3791,7 +3782,7 @@ class Document {
|
|
|
3791
3782
|
}
|
|
3792
3783
|
updateTableStyleShadingBulk(settings) {
|
|
3793
3784
|
let totalUpdated = 0;
|
|
3794
|
-
const defaultReplaceColors = [
|
|
3785
|
+
const defaultReplaceColors = ['A5A5A5', 'C0C0C0', 'D9D9D9', 'E7E6E6'];
|
|
3795
3786
|
const colorsToReplace = settings.replaceColors || defaultReplaceColors;
|
|
3796
3787
|
if (settings.headerShading) {
|
|
3797
3788
|
for (const oldColor of colorsToReplace) {
|
|
@@ -3799,7 +3790,7 @@ class Document {
|
|
|
3799
3790
|
}
|
|
3800
3791
|
}
|
|
3801
3792
|
if (settings.dataShading && settings.dataShading !== settings.headerShading) {
|
|
3802
|
-
const dataColors = [
|
|
3793
|
+
const dataColors = ['D9D9D9', 'E7E6E6', 'F2F2F2'];
|
|
3803
3794
|
for (const oldColor of dataColors) {
|
|
3804
3795
|
totalUpdated += this.updateTableStyleShading(oldColor, settings.dataShading);
|
|
3805
3796
|
}
|
|
@@ -3822,7 +3813,7 @@ class Document {
|
|
|
3822
3813
|
}
|
|
3823
3814
|
}
|
|
3824
3815
|
standardizeBulletSymbols(options) {
|
|
3825
|
-
const { bold = false, fontSize = 24, color =
|
|
3816
|
+
const { bold = false, fontSize = 24, color = '000000', font = 'Arial', } = options || {};
|
|
3826
3817
|
let listsUpdated = 0;
|
|
3827
3818
|
let levelsModified = 0;
|
|
3828
3819
|
const instances = this.numberingManager.getAllInstances();
|
|
@@ -3832,7 +3823,7 @@ class Document {
|
|
|
3832
3823
|
if (!abstractNum)
|
|
3833
3824
|
continue;
|
|
3834
3825
|
const level0 = abstractNum.getLevel(0);
|
|
3835
|
-
if (level0?.getFormat() !==
|
|
3826
|
+
if (level0?.getFormat() !== 'bullet')
|
|
3836
3827
|
continue;
|
|
3837
3828
|
for (let levelIndex = 0; levelIndex < 9; levelIndex++) {
|
|
3838
3829
|
const numLevel = abstractNum.getLevel(levelIndex);
|
|
@@ -3849,7 +3840,7 @@ class Document {
|
|
|
3849
3840
|
return { listsUpdated, levelsModified };
|
|
3850
3841
|
}
|
|
3851
3842
|
standardizeNumberedListPrefixes(options) {
|
|
3852
|
-
const { bold = false, fontSize = 24, color =
|
|
3843
|
+
const { bold = false, fontSize = 24, color = '000000', font = 'Verdana', } = options || {};
|
|
3853
3844
|
let listsUpdated = 0;
|
|
3854
3845
|
let levelsModified = 0;
|
|
3855
3846
|
const instances = this.numberingManager.getAllInstances();
|
|
@@ -3859,7 +3850,7 @@ class Document {
|
|
|
3859
3850
|
if (!abstractNum)
|
|
3860
3851
|
continue;
|
|
3861
3852
|
const level0 = abstractNum.getLevel(0);
|
|
3862
|
-
if (!level0 || level0.getFormat() ===
|
|
3853
|
+
if (!level0 || level0.getFormat() === 'bullet')
|
|
3863
3854
|
continue;
|
|
3864
3855
|
for (let levelIndex = 0; levelIndex < 9; levelIndex++) {
|
|
3865
3856
|
const numLevel = abstractNum.getLevel(levelIndex);
|
|
@@ -3876,39 +3867,38 @@ class Document {
|
|
|
3876
3867
|
return { listsUpdated, levelsModified };
|
|
3877
3868
|
}
|
|
3878
3869
|
standardizeAllHyperlinks(options) {
|
|
3879
|
-
const { font =
|
|
3870
|
+
const { font = 'Verdana', size = 12, color = '0000FF', underline = true } = options || {};
|
|
3880
3871
|
const hyperlinks = this.getHyperlinks();
|
|
3881
3872
|
for (const { hyperlink } of hyperlinks) {
|
|
3882
3873
|
hyperlink.setFormatting({
|
|
3883
3874
|
font: font,
|
|
3884
3875
|
size: size,
|
|
3885
3876
|
color: color,
|
|
3886
|
-
underline: underline ?
|
|
3877
|
+
underline: underline ? 'single' : false,
|
|
3887
3878
|
});
|
|
3888
3879
|
}
|
|
3889
3880
|
return hyperlinks.length;
|
|
3890
3881
|
}
|
|
3891
3882
|
applyH1(options) {
|
|
3892
|
-
return this.applyStyleToMatching(
|
|
3883
|
+
return this.applyStyleToMatching('Heading1', options, (style) => /^(heading\s*1|header\s*1|h1)$/i.test(style));
|
|
3893
3884
|
}
|
|
3894
3885
|
applyH2(options) {
|
|
3895
|
-
return this.applyStyleToMatching(
|
|
3886
|
+
return this.applyStyleToMatching('Heading2', options, (style) => /^(heading\s*2|header\s*2|h2)$/i.test(style));
|
|
3896
3887
|
}
|
|
3897
3888
|
applyH3(options) {
|
|
3898
|
-
return this.applyStyleToMatching(
|
|
3889
|
+
return this.applyStyleToMatching('Heading3', options, (style) => /^(heading\s*3|header\s*3|h3)$/i.test(style));
|
|
3899
3890
|
}
|
|
3900
3891
|
applyNormal(options) {
|
|
3901
3892
|
const targets = options?.paragraphs ||
|
|
3902
3893
|
this.getAllParagraphs().filter((p) => {
|
|
3903
3894
|
const style = p.getStyle();
|
|
3904
|
-
return
|
|
3905
|
-
!/^(heading|header|h\d|list|toc|tod|caution|table)/i.test(style));
|
|
3895
|
+
return !style || !/^(heading|header|h\d|list|toc|tod|caution|table)/i.test(style);
|
|
3906
3896
|
});
|
|
3907
3897
|
let count = 0;
|
|
3908
3898
|
for (const para of targets) {
|
|
3909
3899
|
if (para.isPreserved())
|
|
3910
3900
|
continue;
|
|
3911
|
-
para.setStyle(
|
|
3901
|
+
para.setStyle('Normal');
|
|
3912
3902
|
if (options?.keepProperties && options.keepProperties.length > 0) {
|
|
3913
3903
|
this.clearFormattingExcept(para, options.keepProperties);
|
|
3914
3904
|
}
|
|
@@ -3923,19 +3913,19 @@ class Document {
|
|
|
3923
3913
|
return count;
|
|
3924
3914
|
}
|
|
3925
3915
|
applyNumList(options) {
|
|
3926
|
-
return this.applyStyleToMatching(
|
|
3916
|
+
return this.applyStyleToMatching('ListParagraph', options, (style) => /^(list\s*number|numbered\s*list|list\s*paragraph)$/i.test(style));
|
|
3927
3917
|
}
|
|
3928
3918
|
applyBulletList(options) {
|
|
3929
|
-
return this.applyStyleToMatching(
|
|
3919
|
+
return this.applyStyleToMatching('ListParagraph', options, (style) => /^(list\s*bullet|bullet\s*list|list\s*paragraph)$/i.test(style));
|
|
3930
3920
|
}
|
|
3931
3921
|
applyTOC(options) {
|
|
3932
|
-
return this.applyStyleToMatching(
|
|
3922
|
+
return this.applyStyleToMatching('TOC', options, (style) => /^(toc|table\s*of\s*contents|toc\s*heading)$/i.test(style));
|
|
3933
3923
|
}
|
|
3934
3924
|
applyTOD(options) {
|
|
3935
|
-
return this.applyStyleToMatching(
|
|
3925
|
+
return this.applyStyleToMatching('TopOfDocument', options, (style) => /^(tod|top\s*of\s*document|document\s*top)$/i.test(style));
|
|
3936
3926
|
}
|
|
3937
3927
|
applyCaution(options) {
|
|
3938
|
-
return this.applyStyleToMatching(
|
|
3928
|
+
return this.applyStyleToMatching('Caution', options, (style) => /^(caution|warning|important|alert)$/i.test(style));
|
|
3939
3929
|
}
|
|
3940
3930
|
applyCellHeader(options) {
|
|
3941
3931
|
let count = 0;
|
|
@@ -3948,7 +3938,7 @@ class Document {
|
|
|
3948
3938
|
for (const para of cell.getParagraphs()) {
|
|
3949
3939
|
if (para.isPreserved())
|
|
3950
3940
|
continue;
|
|
3951
|
-
para.setStyle(
|
|
3941
|
+
para.setStyle('TableHeader');
|
|
3952
3942
|
if (options?.keepProperties && options.keepProperties.length > 0) {
|
|
3953
3943
|
this.clearFormattingExcept(para, options.keepProperties);
|
|
3954
3944
|
}
|
|
@@ -3984,12 +3974,12 @@ class Document {
|
|
|
3984
3974
|
run.setColor(options.color);
|
|
3985
3975
|
if (options.emphasis) {
|
|
3986
3976
|
options.emphasis.forEach((emp) => {
|
|
3987
|
-
if (emp ===
|
|
3977
|
+
if (emp === 'bold')
|
|
3988
3978
|
run.setBold(true);
|
|
3989
|
-
if (emp ===
|
|
3979
|
+
if (emp === 'italic')
|
|
3990
3980
|
run.setItalic(true);
|
|
3991
|
-
if (emp ===
|
|
3992
|
-
run.setUnderline(
|
|
3981
|
+
if (emp === 'underline')
|
|
3982
|
+
run.setUnderline('single');
|
|
3993
3983
|
});
|
|
3994
3984
|
}
|
|
3995
3985
|
}
|
|
@@ -4136,7 +4126,7 @@ class Document {
|
|
|
4136
4126
|
const tMatches = [...normalizedText.matchAll(tSwitchRegex)];
|
|
4137
4127
|
for (const match of tMatches) {
|
|
4138
4128
|
hasTableSwitch = true;
|
|
4139
|
-
const content = (match[1] ||
|
|
4129
|
+
const content = (match[1] || '').trim();
|
|
4140
4130
|
if (!content)
|
|
4141
4131
|
continue;
|
|
4142
4132
|
const rangeMatch = /^(\d+)-(\d+)$/.exec(content);
|
|
@@ -4150,7 +4140,7 @@ class Document {
|
|
|
4150
4140
|
continue;
|
|
4151
4141
|
}
|
|
4152
4142
|
const parts = content
|
|
4153
|
-
.split(
|
|
4143
|
+
.split(',')
|
|
4154
4144
|
.map((p) => p.trim())
|
|
4155
4145
|
.filter(Boolean);
|
|
4156
4146
|
for (let i = 0; i < parts.length; i += 2) {
|
|
@@ -4188,22 +4178,22 @@ class Document {
|
|
|
4188
4178
|
if (!match?.[1])
|
|
4189
4179
|
continue;
|
|
4190
4180
|
const fieldInstruction = match[1]
|
|
4191
|
-
.replace(/&/g,
|
|
4192
|
-
.replace(/</g,
|
|
4193
|
-
.replace(/>/g,
|
|
4181
|
+
.replace(/&/g, '&')
|
|
4182
|
+
.replace(/</g, '<')
|
|
4183
|
+
.replace(/>/g, '>')
|
|
4194
4184
|
.replace(/"/g, '"')
|
|
4195
4185
|
.replace(/'/g, "'");
|
|
4196
|
-
if (!fieldInstruction.includes(
|
|
4186
|
+
if (!fieldInstruction.includes('\\t')) {
|
|
4197
4187
|
continue;
|
|
4198
4188
|
}
|
|
4199
4189
|
const updatedInstruction = this.updateTOCStyleNames(fieldInstruction);
|
|
4200
4190
|
if (updatedInstruction !== fieldInstruction) {
|
|
4201
4191
|
const encodedInstruction = updatedInstruction
|
|
4202
|
-
.replace(/&/g,
|
|
4203
|
-
.replace(/</g,
|
|
4204
|
-
.replace(/>/g,
|
|
4205
|
-
.replace(/"/g,
|
|
4206
|
-
.replace(/'/g,
|
|
4192
|
+
.replace(/&/g, '&')
|
|
4193
|
+
.replace(/</g, '<')
|
|
4194
|
+
.replace(/>/g, '>')
|
|
4195
|
+
.replace(/"/g, '"')
|
|
4196
|
+
.replace(/'/g, ''');
|
|
4207
4197
|
const updatedInstrXml = `<w:instrText xml:space="preserve">${encodedInstruction}</w:instrText>`;
|
|
4208
4198
|
modifiedXml = modifiedXml.replace(match[0], updatedInstrXml);
|
|
4209
4199
|
this.logger.info(`Synced TOC field instruction: "${fieldInstruction.substring(0, 50)}..." → "${updatedInstruction.substring(0, 50)}..."`);
|
|
@@ -4216,7 +4206,7 @@ class Document {
|
|
|
4216
4206
|
return modifiedXml;
|
|
4217
4207
|
}
|
|
4218
4208
|
catch (error) {
|
|
4219
|
-
this.logger.error(
|
|
4209
|
+
this.logger.error('Error syncing TOC field instructions - document will save with original instructions', error instanceof Error
|
|
4220
4210
|
? { message: error.message, stack: error.stack }
|
|
4221
4211
|
: { error: String(error) });
|
|
4222
4212
|
return documentXml;
|
|
@@ -4228,12 +4218,12 @@ class Document {
|
|
|
4228
4218
|
return { xml, changed: false };
|
|
4229
4219
|
}
|
|
4230
4220
|
const fieldInstruction = instrMatch[1]
|
|
4231
|
-
.replace(/&/g,
|
|
4232
|
-
.replace(/</g,
|
|
4233
|
-
.replace(/>/g,
|
|
4221
|
+
.replace(/&/g, '&')
|
|
4222
|
+
.replace(/</g, '<')
|
|
4223
|
+
.replace(/>/g, '>')
|
|
4234
4224
|
.replace(/"/g, '"')
|
|
4235
4225
|
.replace(/'/g, "'");
|
|
4236
|
-
if (!fieldInstruction.includes(
|
|
4226
|
+
if (!fieldInstruction.includes('\\t')) {
|
|
4237
4227
|
return { xml, changed: false };
|
|
4238
4228
|
}
|
|
4239
4229
|
const updatedInstruction = this.updateTOCStyleNames(fieldInstruction);
|
|
@@ -4241,11 +4231,11 @@ class Document {
|
|
|
4241
4231
|
return { xml, changed: false };
|
|
4242
4232
|
}
|
|
4243
4233
|
const encodedInstruction = updatedInstruction
|
|
4244
|
-
.replace(/&/g,
|
|
4245
|
-
.replace(/</g,
|
|
4246
|
-
.replace(/>/g,
|
|
4247
|
-
.replace(/"/g,
|
|
4248
|
-
.replace(/'/g,
|
|
4234
|
+
.replace(/&/g, '&')
|
|
4235
|
+
.replace(/</g, '<')
|
|
4236
|
+
.replace(/>/g, '>')
|
|
4237
|
+
.replace(/"/g, '"')
|
|
4238
|
+
.replace(/'/g, ''');
|
|
4249
4239
|
const updatedXml = xml.replace(/<w:instrText[^>]*>[\s\S]*?<\/w:instrText>/, `<w:instrText xml:space="preserve">${encodedInstruction}</w:instrText>`);
|
|
4250
4240
|
return { xml: updatedXml, changed: true };
|
|
4251
4241
|
}
|
|
@@ -4259,7 +4249,10 @@ class Document {
|
|
|
4259
4249
|
const content = match[1];
|
|
4260
4250
|
if (!content)
|
|
4261
4251
|
continue;
|
|
4262
|
-
const parts = content
|
|
4252
|
+
const parts = content
|
|
4253
|
+
.split(',')
|
|
4254
|
+
.map((p) => p.trim())
|
|
4255
|
+
.filter(Boolean);
|
|
4263
4256
|
const updatedParts = [];
|
|
4264
4257
|
for (let i = 0; i < parts.length; i += 2) {
|
|
4265
4258
|
const styleName = parts[i];
|
|
@@ -4365,20 +4358,20 @@ class Document {
|
|
|
4365
4358
|
const levelSet = new Set(levels);
|
|
4366
4359
|
try {
|
|
4367
4360
|
const parsed = XMLParser_1.XMLParser.parseToObject(docXml, { trimValues: false });
|
|
4368
|
-
const document = parsed[
|
|
4361
|
+
const document = parsed['w:document'];
|
|
4369
4362
|
if (!document) {
|
|
4370
4363
|
return headings;
|
|
4371
4364
|
}
|
|
4372
|
-
const body = document[
|
|
4365
|
+
const body = document['w:body'];
|
|
4373
4366
|
if (!body) {
|
|
4374
4367
|
return headings;
|
|
4375
4368
|
}
|
|
4376
4369
|
const extractHeading = (para) => {
|
|
4377
|
-
const pPr = para[
|
|
4378
|
-
if (!pPr?.[
|
|
4370
|
+
const pPr = para['w:pPr'];
|
|
4371
|
+
if (!pPr?.['w:pStyle']) {
|
|
4379
4372
|
return;
|
|
4380
4373
|
}
|
|
4381
|
-
const styleVal = pPr[
|
|
4374
|
+
const styleVal = pPr['w:pStyle']['@_w:val'];
|
|
4382
4375
|
if (!styleVal) {
|
|
4383
4376
|
return;
|
|
4384
4377
|
}
|
|
@@ -4390,39 +4383,38 @@ class Document {
|
|
|
4390
4383
|
if (!levelSet.has(headingLevel)) {
|
|
4391
4384
|
return;
|
|
4392
4385
|
}
|
|
4393
|
-
let bookmark =
|
|
4394
|
-
const bookmarkStart = para[
|
|
4386
|
+
let bookmark = '';
|
|
4387
|
+
const bookmarkStart = para['w:bookmarkStart'];
|
|
4395
4388
|
if (bookmarkStart) {
|
|
4396
|
-
const bookmarkArray = Array.isArray(bookmarkStart)
|
|
4397
|
-
? bookmarkStart
|
|
4398
|
-
: [bookmarkStart];
|
|
4389
|
+
const bookmarkArray = Array.isArray(bookmarkStart) ? bookmarkStart : [bookmarkStart];
|
|
4399
4390
|
for (const bm of bookmarkArray) {
|
|
4400
|
-
const bmName = bm[
|
|
4401
|
-
if (bmName &&
|
|
4391
|
+
const bmName = bm['@_w:name'];
|
|
4392
|
+
if (bmName &&
|
|
4393
|
+
(bmName.toLowerCase().includes('_heading') || bmName.toLowerCase().includes('_toc'))) {
|
|
4402
4394
|
bookmark = bmName;
|
|
4403
4395
|
break;
|
|
4404
4396
|
}
|
|
4405
4397
|
}
|
|
4406
4398
|
if (!bookmark && bookmarkArray.length > 0) {
|
|
4407
4399
|
const firstBm = bookmarkArray[0];
|
|
4408
|
-
const bmName = firstBm[
|
|
4400
|
+
const bmName = firstBm['@_w:name'];
|
|
4409
4401
|
if (bmName) {
|
|
4410
4402
|
bookmark = bmName;
|
|
4411
4403
|
}
|
|
4412
4404
|
}
|
|
4413
4405
|
}
|
|
4414
|
-
let text =
|
|
4415
|
-
const runs = para[
|
|
4406
|
+
let text = '';
|
|
4407
|
+
const runs = para['w:r'];
|
|
4416
4408
|
if (runs) {
|
|
4417
4409
|
const runArray = Array.isArray(runs) ? runs : [runs];
|
|
4418
4410
|
for (const run of runArray) {
|
|
4419
|
-
const textElement = run[
|
|
4411
|
+
const textElement = run['w:t'];
|
|
4420
4412
|
if (textElement) {
|
|
4421
|
-
if (typeof textElement ===
|
|
4413
|
+
if (typeof textElement === 'string') {
|
|
4422
4414
|
text += textElement;
|
|
4423
4415
|
}
|
|
4424
|
-
else if (textElement[
|
|
4425
|
-
text += textElement[
|
|
4416
|
+
else if (textElement['#text']) {
|
|
4417
|
+
text += textElement['#text'];
|
|
4426
4418
|
}
|
|
4427
4419
|
}
|
|
4428
4420
|
}
|
|
@@ -4440,33 +4432,31 @@ class Document {
|
|
|
4440
4432
|
bookmark: bookmark,
|
|
4441
4433
|
});
|
|
4442
4434
|
};
|
|
4443
|
-
const paragraphs = body[
|
|
4435
|
+
const paragraphs = body['w:p'];
|
|
4444
4436
|
if (paragraphs) {
|
|
4445
4437
|
const paraArray = Array.isArray(paragraphs) ? paragraphs : [paragraphs];
|
|
4446
4438
|
for (const para of paraArray) {
|
|
4447
4439
|
extractHeading(para);
|
|
4448
4440
|
}
|
|
4449
4441
|
}
|
|
4450
|
-
const tables = body[
|
|
4442
|
+
const tables = body['w:tbl'];
|
|
4451
4443
|
if (tables) {
|
|
4452
4444
|
const tableArray = Array.isArray(tables) ? tables : [tables];
|
|
4453
4445
|
for (const table of tableArray) {
|
|
4454
|
-
const rows = table[
|
|
4446
|
+
const rows = table['w:tr'];
|
|
4455
4447
|
if (!rows)
|
|
4456
4448
|
continue;
|
|
4457
4449
|
const rowArray = Array.isArray(rows) ? rows : [rows];
|
|
4458
4450
|
for (const row of rowArray) {
|
|
4459
|
-
const cells = row[
|
|
4451
|
+
const cells = row['w:tc'];
|
|
4460
4452
|
if (!cells)
|
|
4461
4453
|
continue;
|
|
4462
4454
|
const cellArray = Array.isArray(cells) ? cells : [cells];
|
|
4463
4455
|
for (const cell of cellArray) {
|
|
4464
|
-
const cellParas = cell[
|
|
4456
|
+
const cellParas = cell['w:p'];
|
|
4465
4457
|
if (!cellParas)
|
|
4466
4458
|
continue;
|
|
4467
|
-
const cellParaArray = Array.isArray(cellParas)
|
|
4468
|
-
? cellParas
|
|
4469
|
-
: [cellParas];
|
|
4459
|
+
const cellParaArray = Array.isArray(cellParas) ? cellParas : [cellParas];
|
|
4470
4460
|
for (const para of cellParaArray) {
|
|
4471
4461
|
extractHeading(para);
|
|
4472
4462
|
}
|
|
@@ -4476,7 +4466,7 @@ class Document {
|
|
|
4476
4466
|
}
|
|
4477
4467
|
}
|
|
4478
4468
|
catch (error) {
|
|
4479
|
-
logger_1.defaultLogger.error(
|
|
4469
|
+
logger_1.defaultLogger.error('Error parsing document.xml for headings:', error instanceof Error
|
|
4480
4470
|
? { message: error.message, stack: error.stack }
|
|
4481
4471
|
: { error: String(error) });
|
|
4482
4472
|
}
|
|
@@ -4512,99 +4502,95 @@ class Document {
|
|
|
4512
4502
|
}
|
|
4513
4503
|
generateTOCXML(headings, originalInstrText) {
|
|
4514
4504
|
const sdtId = Math.floor(Math.random() * 2000000000) - 1000000000;
|
|
4515
|
-
let tocXml =
|
|
4516
|
-
tocXml +=
|
|
4505
|
+
let tocXml = '<w:sdt>';
|
|
4506
|
+
tocXml += '<w:sdtPr>';
|
|
4517
4507
|
tocXml += `<w:id w:val="${sdtId}"/>`;
|
|
4518
|
-
tocXml +=
|
|
4508
|
+
tocXml += '<w:docPartObj>';
|
|
4519
4509
|
tocXml += '<w:docPartGallery w:val="Table of Contents"/>';
|
|
4520
4510
|
tocXml += '<w:docPartUnique w:val="1"/>';
|
|
4521
|
-
tocXml +=
|
|
4522
|
-
tocXml +=
|
|
4523
|
-
tocXml +=
|
|
4511
|
+
tocXml += '</w:docPartObj>';
|
|
4512
|
+
tocXml += '</w:sdtPr>';
|
|
4513
|
+
tocXml += '<w:sdtContent>';
|
|
4524
4514
|
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"/>';
|
|
4515
|
+
tocXml += '<w:p>';
|
|
4516
|
+
tocXml += '<w:pPr>';
|
|
4517
|
+
tocXml += '<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
|
|
4529
4518
|
if (headings.length > 0 && headings[0]) {
|
|
4530
4519
|
const firstIndent = (headings[0].level - minLevel) * 360;
|
|
4531
4520
|
if (firstIndent > 0) {
|
|
4532
4521
|
tocXml += `<w:ind w:left="${firstIndent}"/>`;
|
|
4533
4522
|
}
|
|
4534
4523
|
}
|
|
4535
|
-
tocXml +=
|
|
4524
|
+
tocXml += '</w:pPr>';
|
|
4536
4525
|
tocXml += '<w:r><w:fldChar w:fldCharType="begin"/></w:r>';
|
|
4537
|
-
tocXml +=
|
|
4526
|
+
tocXml += '<w:r>';
|
|
4538
4527
|
tocXml += `<w:instrText xml:space="preserve">${this.escapeXml(originalInstrText)}</w:instrText>`;
|
|
4539
|
-
tocXml +=
|
|
4528
|
+
tocXml += '</w:r>';
|
|
4540
4529
|
tocXml += '<w:r><w:fldChar w:fldCharType="separate"/></w:r>';
|
|
4541
4530
|
if (headings.length > 0 && headings[0]) {
|
|
4542
4531
|
tocXml += this.buildTOCEntryXML(headings[0]);
|
|
4543
4532
|
}
|
|
4544
|
-
tocXml +=
|
|
4533
|
+
tocXml += '</w:p>';
|
|
4545
4534
|
for (let i = 1; i < headings.length; i++) {
|
|
4546
4535
|
const heading = headings[i];
|
|
4547
4536
|
if (!heading)
|
|
4548
4537
|
continue;
|
|
4549
|
-
tocXml +=
|
|
4550
|
-
tocXml +=
|
|
4551
|
-
tocXml +=
|
|
4552
|
-
'<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
|
|
4538
|
+
tocXml += '<w:p>';
|
|
4539
|
+
tocXml += '<w:pPr>';
|
|
4540
|
+
tocXml += '<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
|
|
4553
4541
|
const indent = (heading.level - minLevel) * 360;
|
|
4554
4542
|
if (indent > 0) {
|
|
4555
4543
|
tocXml += `<w:ind w:left="${indent}"/>`;
|
|
4556
4544
|
}
|
|
4557
|
-
tocXml +=
|
|
4545
|
+
tocXml += '</w:pPr>';
|
|
4558
4546
|
tocXml += this.buildTOCEntryXML(heading);
|
|
4559
|
-
tocXml +=
|
|
4547
|
+
tocXml += '</w:p>';
|
|
4560
4548
|
}
|
|
4561
|
-
tocXml +=
|
|
4562
|
-
tocXml +=
|
|
4563
|
-
tocXml +=
|
|
4564
|
-
|
|
4565
|
-
tocXml += "</w:pPr>";
|
|
4549
|
+
tocXml += '<w:p>';
|
|
4550
|
+
tocXml += '<w:pPr>';
|
|
4551
|
+
tocXml += '<w:spacing w:after="0" w:before="0" w:line="240" w:lineRule="auto"/>';
|
|
4552
|
+
tocXml += '</w:pPr>';
|
|
4566
4553
|
tocXml += '<w:r><w:fldChar w:fldCharType="end"/></w:r>';
|
|
4567
|
-
tocXml +=
|
|
4568
|
-
tocXml +=
|
|
4569
|
-
tocXml +=
|
|
4554
|
+
tocXml += '</w:p>';
|
|
4555
|
+
tocXml += '</w:sdtContent>';
|
|
4556
|
+
tocXml += '</w:sdt>';
|
|
4570
4557
|
return tocXml;
|
|
4571
4558
|
}
|
|
4572
4559
|
buildTOCEntryXML(heading) {
|
|
4573
4560
|
const escapedText = this.escapeXml(heading.text);
|
|
4574
|
-
let xml =
|
|
4561
|
+
let xml = '';
|
|
4575
4562
|
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"/>';
|
|
4563
|
+
xml += '<w:r>';
|
|
4564
|
+
xml += '<w:rPr>';
|
|
4565
|
+
xml += '<w:rFonts w:ascii="Verdana" w:hAnsi="Verdana" w:cs="Verdana" w:eastAsia="Verdana"/>';
|
|
4580
4566
|
xml += '<w:color w:val="0000FF"/>';
|
|
4581
4567
|
xml += '<w:sz w:val="24"/>';
|
|
4582
4568
|
xml += '<w:szCs w:val="24"/>';
|
|
4583
4569
|
xml += '<w:u w:val="single"/>';
|
|
4584
|
-
xml +=
|
|
4570
|
+
xml += '</w:rPr>';
|
|
4585
4571
|
xml += `<w:t xml:space="preserve">${escapedText}</w:t>`;
|
|
4586
|
-
xml +=
|
|
4587
|
-
xml +=
|
|
4572
|
+
xml += '</w:r>';
|
|
4573
|
+
xml += '</w:hyperlink>';
|
|
4588
4574
|
return xml;
|
|
4589
4575
|
}
|
|
4590
4576
|
escapeXml(text) {
|
|
4591
4577
|
return text
|
|
4592
|
-
.replace(/&/g,
|
|
4593
|
-
.replace(/</g,
|
|
4594
|
-
.replace(/>/g,
|
|
4595
|
-
.replace(/"/g,
|
|
4596
|
-
.replace(/'/g,
|
|
4578
|
+
.replace(/&/g, '&')
|
|
4579
|
+
.replace(/</g, '<')
|
|
4580
|
+
.replace(/>/g, '>')
|
|
4581
|
+
.replace(/"/g, '"')
|
|
4582
|
+
.replace(/'/g, ''');
|
|
4597
4583
|
}
|
|
4598
4584
|
async populateTOCsInFile(filePath) {
|
|
4599
4585
|
const handler = new ZipHandler_1.ZipHandler();
|
|
4600
4586
|
await handler.load(filePath);
|
|
4601
|
-
const docXml = handler.getFileAsString(
|
|
4587
|
+
const docXml = handler.getFileAsString('word/document.xml');
|
|
4602
4588
|
if (!docXml) {
|
|
4603
4589
|
return 0;
|
|
4604
4590
|
}
|
|
4605
4591
|
const modifiedXml = this.populateAllTOCsInXML(docXml);
|
|
4606
4592
|
if (modifiedXml !== docXml) {
|
|
4607
|
-
handler.updateFile(
|
|
4593
|
+
handler.updateFile('word/document.xml', modifiedXml);
|
|
4608
4594
|
await handler.save(filePath);
|
|
4609
4595
|
const tocRegex = /<w:sdt>[\s\S]*?<w:docPartGallery w:val="Table of Contents"[\s\S]*?<\/w:sdt>/g;
|
|
4610
4596
|
const matches = Array.from(docXml.matchAll(tocRegex));
|
|
@@ -4624,9 +4610,9 @@ class Document {
|
|
|
4624
4610
|
if (!instrMatch?.[1])
|
|
4625
4611
|
continue;
|
|
4626
4612
|
const fieldInstruction = instrMatch[1]
|
|
4627
|
-
.replace(/&/g,
|
|
4628
|
-
.replace(/</g,
|
|
4629
|
-
.replace(/>/g,
|
|
4613
|
+
.replace(/&/g, '&')
|
|
4614
|
+
.replace(/</g, '<')
|
|
4615
|
+
.replace(/>/g, '>')
|
|
4630
4616
|
.replace(/"/g, '"')
|
|
4631
4617
|
.replace(/'/g, "'");
|
|
4632
4618
|
const levels = this.parseTOCFieldInstruction(fieldInstruction);
|
|
@@ -4637,7 +4623,7 @@ class Document {
|
|
|
4637
4623
|
modifiedXml = modifiedXml.replace(tocXml, newTocXml);
|
|
4638
4624
|
}
|
|
4639
4625
|
catch (error) {
|
|
4640
|
-
this.logger.error(
|
|
4626
|
+
this.logger.error('Error populating SDT TOC', error instanceof Error
|
|
4641
4627
|
? { message: error.message, stack: error.stack }
|
|
4642
4628
|
: { error: String(error) });
|
|
4643
4629
|
continue;
|
|
@@ -4654,9 +4640,9 @@ class Document {
|
|
|
4654
4640
|
if (!instrText)
|
|
4655
4641
|
continue;
|
|
4656
4642
|
const fieldInstruction = instrText
|
|
4657
|
-
.replace(/&/g,
|
|
4658
|
-
.replace(/</g,
|
|
4659
|
-
.replace(/>/g,
|
|
4643
|
+
.replace(/&/g, '&')
|
|
4644
|
+
.replace(/</g, '<')
|
|
4645
|
+
.replace(/>/g, '>')
|
|
4660
4646
|
.replace(/"/g, '"')
|
|
4661
4647
|
.replace(/'/g, "'");
|
|
4662
4648
|
const levels = this.parseTOCFieldInstruction(fieldInstruction);
|
|
@@ -4676,7 +4662,7 @@ class Document {
|
|
|
4676
4662
|
this.logger.info(`Populated simple TOC with ${headings.length} heading entries`);
|
|
4677
4663
|
}
|
|
4678
4664
|
catch (error) {
|
|
4679
|
-
this.logger.error(
|
|
4665
|
+
this.logger.error('Error populating simple TOC', error instanceof Error
|
|
4680
4666
|
? { message: error.message, stack: error.stack }
|
|
4681
4667
|
: { error: String(error) });
|
|
4682
4668
|
continue;
|
|
@@ -4690,10 +4676,10 @@ class Document {
|
|
|
4690
4676
|
for (const heading of headings) {
|
|
4691
4677
|
const tocStyle = `TOC${heading.level}`;
|
|
4692
4678
|
const escapedText = heading.text
|
|
4693
|
-
.replace(/&/g,
|
|
4694
|
-
.replace(/</g,
|
|
4695
|
-
.replace(/>/g,
|
|
4696
|
-
.replace(/"/g,
|
|
4679
|
+
.replace(/&/g, '&')
|
|
4680
|
+
.replace(/</g, '<')
|
|
4681
|
+
.replace(/>/g, '>')
|
|
4682
|
+
.replace(/"/g, '"');
|
|
4697
4683
|
entries.push(`<w:p>` +
|
|
4698
4684
|
`<w:pPr><w:pStyle w:val="${tocStyle}"/></w:pPr>` +
|
|
4699
4685
|
`<w:hyperlink w:anchor="${heading.bookmark}" w:history="1">` +
|
|
@@ -4703,17 +4689,17 @@ class Document {
|
|
|
4703
4689
|
`</w:p>`);
|
|
4704
4690
|
}
|
|
4705
4691
|
const escapedInstruction = fieldInstruction
|
|
4706
|
-
.replace(/&/g,
|
|
4707
|
-
.replace(/</g,
|
|
4708
|
-
.replace(/>/g,
|
|
4709
|
-
.replace(/"/g,
|
|
4692
|
+
.replace(/&/g, '&')
|
|
4693
|
+
.replace(/</g, '<')
|
|
4694
|
+
.replace(/>/g, '>')
|
|
4695
|
+
.replace(/"/g, '"');
|
|
4710
4696
|
return (`<w:p>` +
|
|
4711
4697
|
`<w:pPr><w:pStyle w:val="TOC2"/></w:pPr>` +
|
|
4712
4698
|
`<w:r><w:fldChar w:fldCharType="begin"/></w:r>` +
|
|
4713
4699
|
`<w:r><w:instrText xml:space="preserve">${escapedInstruction}</w:instrText></w:r>` +
|
|
4714
4700
|
`<w:r><w:fldChar w:fldCharType="separate"/></w:r>` +
|
|
4715
4701
|
`</w:p>` +
|
|
4716
|
-
entries.join(
|
|
4702
|
+
entries.join('') +
|
|
4717
4703
|
`<w:p>` +
|
|
4718
4704
|
`<w:pPr><w:pStyle w:val="TOC2"/></w:pPr>` +
|
|
4719
4705
|
`<w:r><w:fldChar w:fldCharType="end"/></w:r>` +
|
|
@@ -4744,39 +4730,39 @@ class Document {
|
|
|
4744
4730
|
setHeader(header) {
|
|
4745
4731
|
const relationship = this.relationshipManager.addHeader(`${header.getFilename(1)}`);
|
|
4746
4732
|
this.headerFooterManager.registerHeader(header, relationship.getId());
|
|
4747
|
-
this.section.setHeaderReference(
|
|
4733
|
+
this.section.setHeaderReference('default', relationship.getId());
|
|
4748
4734
|
return this;
|
|
4749
4735
|
}
|
|
4750
4736
|
setFirstPageHeader(header) {
|
|
4751
4737
|
this.section.setTitlePage(true);
|
|
4752
4738
|
const relationship = this.relationshipManager.addHeader(`${header.getFilename(this.headerFooterManager.getHeaderCount() + 1)}`);
|
|
4753
4739
|
this.headerFooterManager.registerHeader(header, relationship.getId());
|
|
4754
|
-
this.section.setHeaderReference(
|
|
4740
|
+
this.section.setHeaderReference('first', relationship.getId());
|
|
4755
4741
|
return this;
|
|
4756
4742
|
}
|
|
4757
4743
|
setEvenPageHeader(header) {
|
|
4758
4744
|
const relationship = this.relationshipManager.addHeader(`${header.getFilename(this.headerFooterManager.getHeaderCount() + 1)}`);
|
|
4759
4745
|
this.headerFooterManager.registerHeader(header, relationship.getId());
|
|
4760
|
-
this.section.setHeaderReference(
|
|
4746
|
+
this.section.setHeaderReference('even', relationship.getId());
|
|
4761
4747
|
return this;
|
|
4762
4748
|
}
|
|
4763
4749
|
setFooter(footer) {
|
|
4764
4750
|
const relationship = this.relationshipManager.addFooter(`${footer.getFilename(1)}`);
|
|
4765
4751
|
this.headerFooterManager.registerFooter(footer, relationship.getId());
|
|
4766
|
-
this.section.setFooterReference(
|
|
4752
|
+
this.section.setFooterReference('default', relationship.getId());
|
|
4767
4753
|
return this;
|
|
4768
4754
|
}
|
|
4769
4755
|
setFirstPageFooter(footer) {
|
|
4770
4756
|
this.section.setTitlePage(true);
|
|
4771
4757
|
const relationship = this.relationshipManager.addFooter(`${footer.getFilename(this.headerFooterManager.getFooterCount() + 1)}`);
|
|
4772
4758
|
this.headerFooterManager.registerFooter(footer, relationship.getId());
|
|
4773
|
-
this.section.setFooterReference(
|
|
4759
|
+
this.section.setFooterReference('first', relationship.getId());
|
|
4774
4760
|
return this;
|
|
4775
4761
|
}
|
|
4776
4762
|
setEvenPageFooter(footer) {
|
|
4777
4763
|
const relationship = this.relationshipManager.addFooter(`${footer.getFilename(this.headerFooterManager.getFooterCount() + 1)}`);
|
|
4778
4764
|
this.headerFooterManager.registerFooter(footer, relationship.getId());
|
|
4779
|
-
this.section.setFooterReference(
|
|
4765
|
+
this.section.setFooterReference('even', relationship.getId());
|
|
4780
4766
|
return this;
|
|
4781
4767
|
}
|
|
4782
4768
|
getHeaderFooterManager() {
|
|
@@ -4900,20 +4886,20 @@ class Document {
|
|
|
4900
4886
|
}
|
|
4901
4887
|
updateRelationships() {
|
|
4902
4888
|
const xml = this.relationshipManager.generateXml();
|
|
4903
|
-
this.zipHandler.updateFile(
|
|
4889
|
+
this.zipHandler.updateFile('word/_rels/document.xml.rels', xml);
|
|
4904
4890
|
}
|
|
4905
4891
|
saveComments() {
|
|
4906
4892
|
if (this._commentsModified) {
|
|
4907
4893
|
if (this.commentManager.getCount() > 0) {
|
|
4908
4894
|
const xml = this.commentManager.generateCommentsXml();
|
|
4909
|
-
this.zipHandler.addFile(
|
|
4895
|
+
this.zipHandler.addFile('word/comments.xml', xml);
|
|
4910
4896
|
const existingRels = this.relationshipManager.getRelationshipsByType(Relationship_1.RelationshipType.COMMENTS);
|
|
4911
4897
|
if (existingRels.length === 0) {
|
|
4912
4898
|
this.relationshipManager.addComments();
|
|
4913
4899
|
}
|
|
4914
4900
|
}
|
|
4915
4901
|
else {
|
|
4916
|
-
this.zipHandler.removeFile(
|
|
4902
|
+
this.zipHandler.removeFile('word/comments.xml');
|
|
4917
4903
|
const existingRels = this.relationshipManager.getRelationshipsByType(Relationship_1.RelationshipType.COMMENTS);
|
|
4918
4904
|
for (const rel of existingRels) {
|
|
4919
4905
|
this.relationshipManager.removeRelationship(rel.getId());
|
|
@@ -4922,7 +4908,7 @@ class Document {
|
|
|
4922
4908
|
this.removeCommentCompanionFiles();
|
|
4923
4909
|
}
|
|
4924
4910
|
else if (this._originalCommentsXml) {
|
|
4925
|
-
this.zipHandler.addFile(
|
|
4911
|
+
this.zipHandler.addFile('word/comments.xml', this._originalCommentsXml);
|
|
4926
4912
|
for (const [path, content] of this._originalCommentCompanionFiles) {
|
|
4927
4913
|
this.zipHandler.addFile(path, content);
|
|
4928
4914
|
}
|
|
@@ -4933,7 +4919,7 @@ class Document {
|
|
|
4933
4919
|
}
|
|
4934
4920
|
else if (this.commentManager.getCount() > 0) {
|
|
4935
4921
|
const xml = this.commentManager.generateCommentsXml();
|
|
4936
|
-
this.zipHandler.addFile(
|
|
4922
|
+
this.zipHandler.addFile('word/comments.xml', xml);
|
|
4937
4923
|
const existingRels = this.relationshipManager.getRelationshipsByType(Relationship_1.RelationshipType.COMMENTS);
|
|
4938
4924
|
if (existingRels.length === 0) {
|
|
4939
4925
|
this.relationshipManager.addComments();
|
|
@@ -4941,7 +4927,11 @@ class Document {
|
|
|
4941
4927
|
}
|
|
4942
4928
|
}
|
|
4943
4929
|
removeCommentCompanionFiles() {
|
|
4944
|
-
const companionPaths = [
|
|
4930
|
+
const companionPaths = [
|
|
4931
|
+
types_1.DOCX_PATHS.COMMENTS_EXTENDED,
|
|
4932
|
+
types_1.DOCX_PATHS.COMMENTS_IDS,
|
|
4933
|
+
types_1.DOCX_PATHS.COMMENTS_EXTENSIBLE,
|
|
4934
|
+
];
|
|
4945
4935
|
for (const filePath of companionPaths) {
|
|
4946
4936
|
this.zipHandler.removeFile(filePath);
|
|
4947
4937
|
const fileName = filePath.replace('word/', '');
|
|
@@ -4960,7 +4950,7 @@ class Document {
|
|
|
4960
4950
|
if (existingRels.length === 0) {
|
|
4961
4951
|
this.relationshipManager.addFootnotes();
|
|
4962
4952
|
}
|
|
4963
|
-
this.generatePartLevelHyperlinkRels(this.footnoteManager.getAllFootnotes().flatMap(fn => fn.getParagraphs()), 'word/_rels/footnotes.xml.rels');
|
|
4953
|
+
this.generatePartLevelHyperlinkRels(this.footnoteManager.getAllFootnotes().flatMap((fn) => fn.getParagraphs()), 'word/_rels/footnotes.xml.rels');
|
|
4964
4954
|
}
|
|
4965
4955
|
else if (this._originalFootnotesXml) {
|
|
4966
4956
|
this.zipHandler.addFile(types_1.DOCX_PATHS.FOOTNOTES, this._originalFootnotesXml);
|
|
@@ -4978,7 +4968,7 @@ class Document {
|
|
|
4978
4968
|
if (existingRels.length === 0) {
|
|
4979
4969
|
this.relationshipManager.addEndnotes();
|
|
4980
4970
|
}
|
|
4981
|
-
this.generatePartLevelHyperlinkRels(this.endnoteManager.getAllEndnotes().flatMap(en => en.getParagraphs()), 'word/_rels/endnotes.xml.rels');
|
|
4971
|
+
this.generatePartLevelHyperlinkRels(this.endnoteManager.getAllEndnotes().flatMap((en) => en.getParagraphs()), 'word/_rels/endnotes.xml.rels');
|
|
4982
4972
|
}
|
|
4983
4973
|
else if (this._originalEndnotesXml) {
|
|
4984
4974
|
this.zipHandler.addFile(types_1.DOCX_PATHS.ENDNOTES, this._originalEndnotesXml);
|
|
@@ -5030,7 +5020,8 @@ class Document {
|
|
|
5030
5020
|
}
|
|
5031
5021
|
if (hyperlinkRels.length > 0) {
|
|
5032
5022
|
let xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
|
|
5033
|
-
xml +=
|
|
5023
|
+
xml +=
|
|
5024
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">\n';
|
|
5034
5025
|
for (const rel of hyperlinkRels) {
|
|
5035
5026
|
const escapedId = XMLBuilder_1.XMLBuilder.escapeXmlAttribute(rel.id);
|
|
5036
5027
|
const escapedUrl = XMLBuilder_1.XMLBuilder.escapeXmlAttribute(rel.url);
|
|
@@ -5087,10 +5078,16 @@ class Document {
|
|
|
5087
5078
|
}
|
|
5088
5079
|
if (missingAuthors.length === 0)
|
|
5089
5080
|
return;
|
|
5090
|
-
const personElements = missingAuthors
|
|
5091
|
-
|
|
5081
|
+
const personElements = missingAuthors
|
|
5082
|
+
.map((author) => {
|
|
5083
|
+
const escapedAuthor = author
|
|
5084
|
+
.replace(/&/g, '&')
|
|
5085
|
+
.replace(/"/g, '"')
|
|
5086
|
+
.replace(/</g, '<')
|
|
5087
|
+
.replace(/>/g, '>');
|
|
5092
5088
|
return `<w15:person w15:author="${escapedAuthor}"><w15:presenceInfo w15:providerId="None" w15:userId="${escapedAuthor}"/></w15:person>`;
|
|
5093
|
-
})
|
|
5089
|
+
})
|
|
5090
|
+
.join('');
|
|
5094
5091
|
if (existingPeopleXml) {
|
|
5095
5092
|
const updatedXml = existingPeopleXml.replace('</w15:people>', `${personElements}</w15:people>`);
|
|
5096
5093
|
this.zipHandler.updateFile('word/people.xml', updatedXml);
|
|
@@ -5104,7 +5101,10 @@ class Document {
|
|
|
5104
5101
|
if (existingPeopleRels.length === 0) {
|
|
5105
5102
|
this.relationshipManager.addPeople();
|
|
5106
5103
|
}
|
|
5107
|
-
this.logger.info('Updated people.xml with missing authors', {
|
|
5104
|
+
this.logger.info('Updated people.xml with missing authors', {
|
|
5105
|
+
added: missingAuthors.length,
|
|
5106
|
+
authors: missingAuthors,
|
|
5107
|
+
});
|
|
5108
5108
|
}
|
|
5109
5109
|
collectAuthorsFromTable(table, authors) {
|
|
5110
5110
|
for (let r = 0; r < table.getRowCount(); r++) {
|
|
@@ -5141,7 +5141,7 @@ class Document {
|
|
|
5141
5141
|
Object.keys(this.properties.customProperties).length > 0) {
|
|
5142
5142
|
const customXml = this.generator.generateCustomProps(this.properties.customProperties);
|
|
5143
5143
|
if (customXml) {
|
|
5144
|
-
this.zipHandler.addFile(
|
|
5144
|
+
this.zipHandler.addFile('docProps/custom.xml', customXml);
|
|
5145
5145
|
}
|
|
5146
5146
|
}
|
|
5147
5147
|
}
|
|
@@ -5159,8 +5159,7 @@ class Document {
|
|
|
5159
5159
|
return { defaults, overrides };
|
|
5160
5160
|
}
|
|
5161
5161
|
updateContentTypesWithImagesHeadersFootersAndComments() {
|
|
5162
|
-
const hasCustomProps = this.properties.customProperties &&
|
|
5163
|
-
Object.keys(this.properties.customProperties).length > 0;
|
|
5162
|
+
const hasCustomProps = this.properties.customProperties && Object.keys(this.properties.customProperties).length > 0;
|
|
5164
5163
|
const contentTypes = this.generator.generateContentTypesWithImagesHeadersFootersAndComments(this.imageManager, this.headerFooterManager, this.commentManager, this.zipHandler, undefined, hasCustomProps, this._originalContentTypes, this.footnoteManager, this.endnoteManager);
|
|
5165
5164
|
this.zipHandler.updateFile(types_1.DOCX_PATHS.CONTENT_TYPES, contentTypes);
|
|
5166
5165
|
}
|
|
@@ -5180,14 +5179,12 @@ class Document {
|
|
|
5180
5179
|
return this.bookmarkManager.hasBookmark(name);
|
|
5181
5180
|
}
|
|
5182
5181
|
addBookmarkToParagraph(paragraph, bookmarkOrName) {
|
|
5183
|
-
const bookmark = typeof bookmarkOrName ===
|
|
5184
|
-
? this.createBookmark(bookmarkOrName)
|
|
5185
|
-
: bookmarkOrName;
|
|
5182
|
+
const bookmark = typeof bookmarkOrName === 'string' ? this.createBookmark(bookmarkOrName) : bookmarkOrName;
|
|
5186
5183
|
paragraph.addBookmark(bookmark);
|
|
5187
5184
|
return bookmark;
|
|
5188
5185
|
}
|
|
5189
5186
|
addTopBookmark() {
|
|
5190
|
-
const BOOKMARK_NAME =
|
|
5187
|
+
const BOOKMARK_NAME = '_top';
|
|
5191
5188
|
let bookmark = this.getBookmark(BOOKMARK_NAME);
|
|
5192
5189
|
if (!bookmark) {
|
|
5193
5190
|
bookmark = new Bookmark_1.Bookmark({
|
|
@@ -5268,7 +5265,7 @@ class Document {
|
|
|
5268
5265
|
return location;
|
|
5269
5266
|
}
|
|
5270
5267
|
trackInsertion(paragraph, author, text, date) {
|
|
5271
|
-
const revision = this.createRevisionFromText(
|
|
5268
|
+
const revision = this.createRevisionFromText('insert', author, text, date);
|
|
5272
5269
|
const location = this.createRevisionLocation(paragraph);
|
|
5273
5270
|
if (location) {
|
|
5274
5271
|
location.runIndex = paragraph.getRuns().length;
|
|
@@ -5278,7 +5275,7 @@ class Document {
|
|
|
5278
5275
|
return revision;
|
|
5279
5276
|
}
|
|
5280
5277
|
trackDeletion(paragraph, author, text, date) {
|
|
5281
|
-
const revision = this.createRevisionFromText(
|
|
5278
|
+
const revision = this.createRevisionFromText('delete', author, text, date);
|
|
5282
5279
|
const location = this.createRevisionLocation(paragraph);
|
|
5283
5280
|
if (location) {
|
|
5284
5281
|
location.runIndex = paragraph.getRuns().length;
|
|
@@ -5335,15 +5332,13 @@ class Document {
|
|
|
5335
5332
|
this.trackFormatting = options.trackFormatting;
|
|
5336
5333
|
}
|
|
5337
5334
|
if (options.showInsertionsAndDeletions !== undefined) {
|
|
5338
|
-
this.revisionViewSettings.showInsertionsAndDeletions =
|
|
5339
|
-
options.showInsertionsAndDeletions;
|
|
5335
|
+
this.revisionViewSettings.showInsertionsAndDeletions = options.showInsertionsAndDeletions;
|
|
5340
5336
|
}
|
|
5341
5337
|
if (options.showFormatting !== undefined) {
|
|
5342
5338
|
this.revisionViewSettings.showFormatting = options.showFormatting;
|
|
5343
5339
|
}
|
|
5344
5340
|
if (options.showInkAnnotations !== undefined) {
|
|
5345
|
-
this.revisionViewSettings.showInkAnnotations =
|
|
5346
|
-
options.showInkAnnotations;
|
|
5341
|
+
this.revisionViewSettings.showInkAnnotations = options.showInkAnnotations;
|
|
5347
5342
|
}
|
|
5348
5343
|
}
|
|
5349
5344
|
this.trackingContext.enable({
|
|
@@ -5386,6 +5381,31 @@ class Document {
|
|
|
5386
5381
|
this.bindTrackingToElement(element);
|
|
5387
5382
|
}
|
|
5388
5383
|
this.bindTrackingToElement(this.section);
|
|
5384
|
+
for (const entry of this.headerFooterManager.getAllHeaders()) {
|
|
5385
|
+
for (const element of entry.header.getElements()) {
|
|
5386
|
+
this.bindTrackingToElement(element);
|
|
5387
|
+
}
|
|
5388
|
+
}
|
|
5389
|
+
for (const entry of this.headerFooterManager.getAllFooters()) {
|
|
5390
|
+
for (const element of entry.footer.getElements()) {
|
|
5391
|
+
this.bindTrackingToElement(element);
|
|
5392
|
+
}
|
|
5393
|
+
}
|
|
5394
|
+
for (const footnote of this.footnoteManager.getAllFootnotes()) {
|
|
5395
|
+
for (const para of footnote.getParagraphs()) {
|
|
5396
|
+
this.bindTrackingToElement(para);
|
|
5397
|
+
}
|
|
5398
|
+
}
|
|
5399
|
+
for (const endnote of this.endnoteManager.getAllEndnotes()) {
|
|
5400
|
+
for (const para of endnote.getParagraphs()) {
|
|
5401
|
+
this.bindTrackingToElement(para);
|
|
5402
|
+
}
|
|
5403
|
+
}
|
|
5404
|
+
for (const comment of this.commentManager.getAllCommentsWithReplies()) {
|
|
5405
|
+
for (const run of comment.getRuns()) {
|
|
5406
|
+
this.bindTrackingToElement(run);
|
|
5407
|
+
}
|
|
5408
|
+
}
|
|
5389
5409
|
}
|
|
5390
5410
|
bindTrackingToElement(element) {
|
|
5391
5411
|
if (element && typeof element._setTrackingContext === 'function') {
|
|
@@ -5419,7 +5439,7 @@ class Document {
|
|
|
5419
5439
|
}
|
|
5420
5440
|
setRsidRoot(rsidRoot) {
|
|
5421
5441
|
if (!/^[0-9A-Fa-f]{8}$/.test(rsidRoot)) {
|
|
5422
|
-
throw new Error(
|
|
5442
|
+
throw new Error('RSID must be an 8-character hexadecimal value');
|
|
5423
5443
|
}
|
|
5424
5444
|
this.rsidRoot = rsidRoot.toUpperCase();
|
|
5425
5445
|
this.rsids.add(this.rsidRoot);
|
|
@@ -5428,7 +5448,7 @@ class Document {
|
|
|
5428
5448
|
}
|
|
5429
5449
|
addRsid(rsid) {
|
|
5430
5450
|
if (!/^[0-9A-Fa-f]{8}$/.test(rsid)) {
|
|
5431
|
-
throw new Error(
|
|
5451
|
+
throw new Error('RSID must be an 8-character hexadecimal value');
|
|
5432
5452
|
}
|
|
5433
5453
|
this.rsids.add(rsid.toUpperCase());
|
|
5434
5454
|
this._settingsModified = true;
|
|
@@ -5438,7 +5458,7 @@ class Document {
|
|
|
5438
5458
|
const rsid = Math.floor(Math.random() * 0xffffffff)
|
|
5439
5459
|
.toString(16)
|
|
5440
5460
|
.toUpperCase()
|
|
5441
|
-
.padStart(8,
|
|
5461
|
+
.padStart(8, '0');
|
|
5442
5462
|
this.rsids.add(rsid);
|
|
5443
5463
|
this._settingsModified = true;
|
|
5444
5464
|
return rsid;
|
|
@@ -5461,11 +5481,11 @@ class Document {
|
|
|
5461
5481
|
};
|
|
5462
5482
|
this._settingsModified = true;
|
|
5463
5483
|
if (protection.password) {
|
|
5464
|
-
const crypto = require(
|
|
5465
|
-
const salt = crypto.randomBytes(16).toString(
|
|
5484
|
+
const crypto = require('crypto');
|
|
5485
|
+
const salt = crypto.randomBytes(16).toString('base64');
|
|
5466
5486
|
const hash = crypto
|
|
5467
|
-
.pbkdf2Sync(protection.password, salt, protection.cryptSpinCount || 100000, 32,
|
|
5468
|
-
.toString(
|
|
5487
|
+
.pbkdf2Sync(protection.password, salt, protection.cryptSpinCount || 100000, 32, 'sha512')
|
|
5488
|
+
.toString('base64');
|
|
5469
5489
|
this.documentProtection.hash = hash;
|
|
5470
5490
|
this.documentProtection.salt = salt;
|
|
5471
5491
|
}
|
|
@@ -5588,12 +5608,12 @@ class Document {
|
|
|
5588
5608
|
return this._compatInfo?.isLegacyMode ?? true;
|
|
5589
5609
|
}
|
|
5590
5610
|
getCompatibilityInfo() {
|
|
5591
|
-
return this._compatInfo ?? {
|
|
5611
|
+
return (this._compatInfo ?? {
|
|
5592
5612
|
mode: compatibility_types_1.CompatibilityMode.Word2007,
|
|
5593
5613
|
isLegacyMode: true,
|
|
5594
5614
|
compatSettings: [],
|
|
5595
5615
|
legacyFlags: [],
|
|
5596
|
-
};
|
|
5616
|
+
});
|
|
5597
5617
|
}
|
|
5598
5618
|
upgradeToModernFormat() {
|
|
5599
5619
|
const currentMode = this.getCompatibilityMode();
|
|
@@ -5635,7 +5655,7 @@ class Document {
|
|
|
5635
5655
|
previousMode: currentMode,
|
|
5636
5656
|
newMode: 15,
|
|
5637
5657
|
removedFlags: [],
|
|
5638
|
-
addedSettings: legacyCompatFlags_1.MODERN_COMPAT_SETTINGS.map(s => s.name),
|
|
5658
|
+
addedSettings: legacyCompatFlags_1.MODERN_COMPAT_SETTINGS.map((s) => s.name),
|
|
5639
5659
|
namespacesExpanded: nsResult.expanded,
|
|
5640
5660
|
changed: currentMode !== compatibility_types_1.CompatibilityMode.Word2013Plus,
|
|
5641
5661
|
};
|
|
@@ -5661,9 +5681,7 @@ class Document {
|
|
|
5661
5681
|
return this.revisionManager.register(revision);
|
|
5662
5682
|
}
|
|
5663
5683
|
trackMove(author, content, date) {
|
|
5664
|
-
const moveId = `move${Date.now()}_${Math.random()
|
|
5665
|
-
.toString(36)
|
|
5666
|
-
.substr(2, 9)}`;
|
|
5684
|
+
const moveId = `move${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
5667
5685
|
const moveName = `move${Date.now()}`;
|
|
5668
5686
|
const rangeIdStart = this.revisionManager.getStats().nextId;
|
|
5669
5687
|
const moveFromRangeStart = RangeMarker_1.RangeMarker.createMoveFromStart(rangeIdStart, moveName, author, date);
|
|
@@ -5738,7 +5756,7 @@ class Document {
|
|
|
5738
5756
|
this._endnotesModified = true;
|
|
5739
5757
|
}
|
|
5740
5758
|
addCommentToParagraph(paragraph, commentOrAuthor, content, initials) {
|
|
5741
|
-
const comment = typeof commentOrAuthor ===
|
|
5759
|
+
const comment = typeof commentOrAuthor === 'string'
|
|
5742
5760
|
? this.createComment(commentOrAuthor, content, initials)
|
|
5743
5761
|
: commentOrAuthor;
|
|
5744
5762
|
paragraph.addComment(comment);
|
|
@@ -5916,7 +5934,7 @@ class Document {
|
|
|
5916
5934
|
const revisions = para.getRevisions();
|
|
5917
5935
|
if (revisions.length > 0) {
|
|
5918
5936
|
const content = para.getContent();
|
|
5919
|
-
const nonRevisionContent = content.filter(item => !(item instanceof Revision_1.Revision));
|
|
5937
|
+
const nonRevisionContent = content.filter((item) => !(item instanceof Revision_1.Revision));
|
|
5920
5938
|
para.clearContent();
|
|
5921
5939
|
for (const item of nonRevisionContent) {
|
|
5922
5940
|
if (item instanceof Run_1.Run || item instanceof ImageRun_1.ImageRun) {
|
|
@@ -6074,7 +6092,7 @@ class Document {
|
|
|
6074
6092
|
}
|
|
6075
6093
|
let content = file.content;
|
|
6076
6094
|
if (!file.isBinary && Buffer.isBuffer(file.content)) {
|
|
6077
|
-
content = file.content.toString(
|
|
6095
|
+
content = file.content.toString('utf-8');
|
|
6078
6096
|
}
|
|
6079
6097
|
return {
|
|
6080
6098
|
name: partName,
|
|
@@ -6104,13 +6122,13 @@ class Document {
|
|
|
6104
6122
|
}
|
|
6105
6123
|
}
|
|
6106
6124
|
}
|
|
6107
|
-
const relsXml = this.zipHandler.getFileAsString(
|
|
6125
|
+
const relsXml = this.zipHandler.getFileAsString('_rels/.rels');
|
|
6108
6126
|
if (relsXml) {
|
|
6109
6127
|
const target = partName.replace(/^\//, '');
|
|
6110
6128
|
const relPattern = new RegExp(`\\s*<Relationship[^>]*Target="${target.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"[^>]*/?>`, 'g');
|
|
6111
6129
|
const cleaned = relsXml.replace(relPattern, '');
|
|
6112
6130
|
if (cleaned !== relsXml) {
|
|
6113
|
-
this.zipHandler.updateFile(
|
|
6131
|
+
this.zipHandler.updateFile('_rels/.rels', cleaned);
|
|
6114
6132
|
}
|
|
6115
6133
|
}
|
|
6116
6134
|
this._removedParts.add(partName);
|
|
@@ -6126,7 +6144,7 @@ class Document {
|
|
|
6126
6144
|
async getContentTypes() {
|
|
6127
6145
|
const contentTypes = new Map();
|
|
6128
6146
|
try {
|
|
6129
|
-
const contentTypesXml = this.zipHandler.getFileAsString(
|
|
6147
|
+
const contentTypesXml = this.zipHandler.getFileAsString('[Content_Types].xml');
|
|
6130
6148
|
if (!contentTypesXml) {
|
|
6131
6149
|
return contentTypes;
|
|
6132
6150
|
}
|
|
@@ -6154,11 +6172,11 @@ class Document {
|
|
|
6154
6172
|
if (!part) {
|
|
6155
6173
|
return null;
|
|
6156
6174
|
}
|
|
6157
|
-
if (typeof part.content ===
|
|
6175
|
+
if (typeof part.content === 'string') {
|
|
6158
6176
|
return part.content;
|
|
6159
6177
|
}
|
|
6160
6178
|
if (Buffer.isBuffer(part.content)) {
|
|
6161
|
-
return part.content.toString(
|
|
6179
|
+
return part.content.toString('utf8');
|
|
6162
6180
|
}
|
|
6163
6181
|
return null;
|
|
6164
6182
|
}
|
|
@@ -6185,41 +6203,41 @@ class Document {
|
|
|
6185
6203
|
return xmlMap;
|
|
6186
6204
|
}
|
|
6187
6205
|
async setRawXml(partName, xmlContent) {
|
|
6188
|
-
if (typeof xmlContent !==
|
|
6189
|
-
throw new Error(
|
|
6206
|
+
if (typeof xmlContent !== 'string') {
|
|
6207
|
+
throw new Error('XML content must be a string');
|
|
6190
6208
|
}
|
|
6191
6209
|
await this.setPart(partName, xmlContent);
|
|
6192
6210
|
}
|
|
6193
6211
|
async addContentType(partNameOrExtension, contentType) {
|
|
6194
6212
|
try {
|
|
6195
|
-
let contentTypesXml = this.zipHandler.getFileAsString(
|
|
6213
|
+
let contentTypesXml = this.zipHandler.getFileAsString('[Content_Types].xml');
|
|
6196
6214
|
if (!contentTypesXml) {
|
|
6197
6215
|
return false;
|
|
6198
6216
|
}
|
|
6199
|
-
const isExtension = partNameOrExtension.startsWith(
|
|
6217
|
+
const isExtension = partNameOrExtension.startsWith('.');
|
|
6200
6218
|
if (isExtension) {
|
|
6201
6219
|
const extension = partNameOrExtension.substring(1);
|
|
6202
|
-
const existingPattern = new RegExp(`<Default\\s+Extension="${extension}"\\s+ContentType="[^"]+"/?>`,
|
|
6220
|
+
const existingPattern = new RegExp(`<Default\\s+Extension="${extension}"\\s+ContentType="[^"]+"/?>`, 'g');
|
|
6203
6221
|
if (existingPattern.test(contentTypesXml)) {
|
|
6204
6222
|
contentTypesXml = contentTypesXml.replace(existingPattern, `<Default Extension="${extension}" ContentType="${contentType}"/>`);
|
|
6205
6223
|
}
|
|
6206
6224
|
else {
|
|
6207
|
-
contentTypesXml = contentTypesXml.replace(
|
|
6225
|
+
contentTypesXml = contentTypesXml.replace('</Types>', ` <Default Extension="${extension}" ContentType="${contentType}"/>\n</Types>`);
|
|
6208
6226
|
}
|
|
6209
6227
|
}
|
|
6210
6228
|
else {
|
|
6211
|
-
const partName = partNameOrExtension.startsWith(
|
|
6229
|
+
const partName = partNameOrExtension.startsWith('/')
|
|
6212
6230
|
? partNameOrExtension
|
|
6213
6231
|
: `/${partNameOrExtension}`;
|
|
6214
|
-
const existingPattern = new RegExp(`<Override\\s+PartName="${partName.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6232
|
+
const existingPattern = new RegExp(`<Override\\s+PartName="${partName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"\\s+ContentType="[^"]+"/?>`, 'g');
|
|
6215
6233
|
if (existingPattern.test(contentTypesXml)) {
|
|
6216
6234
|
contentTypesXml = contentTypesXml.replace(existingPattern, `<Override PartName="${partName}" ContentType="${contentType}"/>`);
|
|
6217
6235
|
}
|
|
6218
6236
|
else {
|
|
6219
|
-
contentTypesXml = contentTypesXml.replace(
|
|
6237
|
+
contentTypesXml = contentTypesXml.replace('</Types>', ` <Override PartName="${partName}" ContentType="${contentType}"/>\n</Types>`);
|
|
6220
6238
|
}
|
|
6221
6239
|
}
|
|
6222
|
-
this.zipHandler.updateFile(
|
|
6240
|
+
this.zipHandler.updateFile('[Content_Types].xml', contentTypesXml);
|
|
6223
6241
|
return true;
|
|
6224
6242
|
}
|
|
6225
6243
|
catch (error) {
|
|
@@ -6229,20 +6247,18 @@ class Document {
|
|
|
6229
6247
|
async getAllRelationships() {
|
|
6230
6248
|
const relationships = new Map();
|
|
6231
6249
|
try {
|
|
6232
|
-
const relsPaths = this.zipHandler
|
|
6233
|
-
.getFilePaths()
|
|
6234
|
-
.filter((path) => path.endsWith(".rels"));
|
|
6250
|
+
const relsPaths = this.zipHandler.getFilePaths().filter((path) => path.endsWith('.rels'));
|
|
6235
6251
|
for (const relsPath of relsPaths) {
|
|
6236
6252
|
const relsContent = this.zipHandler.getFileAsString(relsPath);
|
|
6237
6253
|
if (relsContent) {
|
|
6238
6254
|
const rels = [];
|
|
6239
|
-
const relationshipElements = XMLParser_1.XMLParser.extractElements(relsContent,
|
|
6255
|
+
const relationshipElements = XMLParser_1.XMLParser.extractElements(relsContent, 'Relationship');
|
|
6240
6256
|
for (const relElement of relationshipElements) {
|
|
6241
6257
|
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,
|
|
6258
|
+
const id = XMLParser_1.XMLParser.extractAttribute(relElement, 'Id');
|
|
6259
|
+
const type = XMLParser_1.XMLParser.extractAttribute(relElement, 'Type');
|
|
6260
|
+
const target = XMLParser_1.XMLParser.extractAttribute(relElement, 'Target');
|
|
6261
|
+
const targetMode = XMLParser_1.XMLParser.extractAttribute(relElement, 'TargetMode');
|
|
6246
6262
|
if (id)
|
|
6247
6263
|
rel.id = id;
|
|
6248
6264
|
if (type)
|
|
@@ -6263,7 +6279,7 @@ class Document {
|
|
|
6263
6279
|
}
|
|
6264
6280
|
async getRelationships(partName) {
|
|
6265
6281
|
try {
|
|
6266
|
-
const lastSlash = partName.lastIndexOf(
|
|
6282
|
+
const lastSlash = partName.lastIndexOf('/');
|
|
6267
6283
|
const relsPath = lastSlash === -1
|
|
6268
6284
|
? `_rels/${partName}.rels`
|
|
6269
6285
|
: `${partName.substring(0, lastSlash)}/_rels/${partName.substring(lastSlash + 1)}.rels`;
|
|
@@ -6272,13 +6288,13 @@ class Document {
|
|
|
6272
6288
|
return [];
|
|
6273
6289
|
}
|
|
6274
6290
|
const relationships = [];
|
|
6275
|
-
const relationshipElements = XMLParser_1.XMLParser.extractElements(relsContent,
|
|
6291
|
+
const relationshipElements = XMLParser_1.XMLParser.extractElements(relsContent, 'Relationship');
|
|
6276
6292
|
for (const relElement of relationshipElements) {
|
|
6277
6293
|
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,
|
|
6294
|
+
const id = XMLParser_1.XMLParser.extractAttribute(relElement, 'Id');
|
|
6295
|
+
const type = XMLParser_1.XMLParser.extractAttribute(relElement, 'Type');
|
|
6296
|
+
const target = XMLParser_1.XMLParser.extractAttribute(relElement, 'Target');
|
|
6297
|
+
const targetMode = XMLParser_1.XMLParser.extractAttribute(relElement, 'TargetMode');
|
|
6282
6298
|
if (id)
|
|
6283
6299
|
rel.id = id;
|
|
6284
6300
|
if (type)
|
|
@@ -6297,18 +6313,18 @@ class Document {
|
|
|
6297
6313
|
}
|
|
6298
6314
|
getContentTypeForPart(partName) {
|
|
6299
6315
|
try {
|
|
6300
|
-
const contentTypesXml = this.zipHandler.getFileAsString(
|
|
6316
|
+
const contentTypesXml = this.zipHandler.getFileAsString('[Content_Types].xml');
|
|
6301
6317
|
if (!contentTypesXml) {
|
|
6302
6318
|
return undefined;
|
|
6303
6319
|
}
|
|
6304
|
-
const overridePattern = new RegExp(`<Override\\s+PartName="${partName.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6320
|
+
const overridePattern = new RegExp(`<Override\\s+PartName="${partName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}"\\s+ContentType="([^"]+)"`, 'i');
|
|
6305
6321
|
const overrideMatch = contentTypesXml.match(overridePattern);
|
|
6306
6322
|
if (overrideMatch) {
|
|
6307
6323
|
return overrideMatch[1];
|
|
6308
6324
|
}
|
|
6309
|
-
const ext = partName.substring(partName.lastIndexOf(
|
|
6325
|
+
const ext = partName.substring(partName.lastIndexOf('.'));
|
|
6310
6326
|
if (ext) {
|
|
6311
|
-
const defaultPattern = new RegExp(`<Default\\s+Extension="${ext.substring(1)}"\\s+ContentType="([^"]+)"`,
|
|
6327
|
+
const defaultPattern = new RegExp(`<Default\\s+Extension="${ext.substring(1)}"\\s+ContentType="([^"]+)"`, 'i');
|
|
6312
6328
|
const defaultMatch = contentTypesXml.match(defaultPattern);
|
|
6313
6329
|
if (defaultMatch) {
|
|
6314
6330
|
return defaultMatch[1];
|
|
@@ -6339,7 +6355,7 @@ class Document {
|
|
|
6339
6355
|
const runText = run.getText();
|
|
6340
6356
|
const compareText = caseSensitive ? runText : runText.toLowerCase();
|
|
6341
6357
|
if (wholeWord) {
|
|
6342
|
-
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6358
|
+
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, caseSensitive ? 'g' : 'gi');
|
|
6343
6359
|
let match;
|
|
6344
6360
|
while ((match = wordPattern.exec(runText)) !== null) {
|
|
6345
6361
|
results.push({
|
|
@@ -6387,11 +6403,9 @@ class Document {
|
|
|
6387
6403
|
if (!run)
|
|
6388
6404
|
continue;
|
|
6389
6405
|
const runText = run.getText();
|
|
6390
|
-
const compareText = caseSensitive
|
|
6391
|
-
? runText
|
|
6392
|
-
: runText.toLowerCase();
|
|
6406
|
+
const compareText = caseSensitive ? runText : runText.toLowerCase();
|
|
6393
6407
|
if (wholeWord) {
|
|
6394
|
-
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6408
|
+
const wordPattern = new RegExp(`\\b${searchText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, caseSensitive ? 'g' : 'gi');
|
|
6395
6409
|
let match;
|
|
6396
6410
|
while ((match = wordPattern.exec(runText)) !== null) {
|
|
6397
6411
|
results.push({
|
|
@@ -6428,7 +6442,7 @@ class Document {
|
|
|
6428
6442
|
}
|
|
6429
6443
|
findParagraphsByText(pattern) {
|
|
6430
6444
|
const results = [];
|
|
6431
|
-
const regex = typeof pattern ===
|
|
6445
|
+
const regex = typeof pattern === 'string' ? new RegExp(pattern, 'gi') : pattern;
|
|
6432
6446
|
for (const paragraph of this.getAllParagraphs()) {
|
|
6433
6447
|
const text = paragraph.getText();
|
|
6434
6448
|
const matches = text.match(regex);
|
|
@@ -6453,12 +6467,12 @@ class Document {
|
|
|
6453
6467
|
}
|
|
6454
6468
|
getRunsByColor(color) {
|
|
6455
6469
|
const results = [];
|
|
6456
|
-
const normalizedColor = color.replace(/^#/,
|
|
6470
|
+
const normalizedColor = color.replace(/^#/, '').toUpperCase();
|
|
6457
6471
|
for (const paragraph of this.getAllParagraphs()) {
|
|
6458
6472
|
for (const run of paragraph.getRuns()) {
|
|
6459
6473
|
const formatting = run.getFormatting();
|
|
6460
6474
|
if (formatting.color) {
|
|
6461
|
-
const runColor = formatting.color.replace(/^#/,
|
|
6475
|
+
const runColor = formatting.color.replace(/^#/, '').toUpperCase();
|
|
6462
6476
|
if (runColor === normalizedColor) {
|
|
6463
6477
|
results.push(run);
|
|
6464
6478
|
}
|
|
@@ -6517,7 +6531,7 @@ class Document {
|
|
|
6517
6531
|
sizes.set(formatting.size, (sizes.get(formatting.size) || 0) + 1);
|
|
6518
6532
|
}
|
|
6519
6533
|
if (formatting.color) {
|
|
6520
|
-
const normalizedColor = formatting.color.toUpperCase().replace(/^#/,
|
|
6534
|
+
const normalizedColor = formatting.color.toUpperCase().replace(/^#/, '');
|
|
6521
6535
|
colors.set(normalizedColor, (colors.get(normalizedColor) || 0) + 1);
|
|
6522
6536
|
}
|
|
6523
6537
|
}
|
|
@@ -6572,7 +6586,7 @@ class Document {
|
|
|
6572
6586
|
const originalText = run.getText();
|
|
6573
6587
|
let newText = originalText;
|
|
6574
6588
|
if (wholeWord) {
|
|
6575
|
-
const wordPattern = new RegExp(`\\b${find.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6589
|
+
const wordPattern = new RegExp(`\\b${find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, caseSensitive ? 'g' : 'gi');
|
|
6576
6590
|
const matches = originalText.match(wordPattern);
|
|
6577
6591
|
if (matches) {
|
|
6578
6592
|
replacementCount += matches.length;
|
|
@@ -6580,7 +6594,7 @@ class Document {
|
|
|
6580
6594
|
}
|
|
6581
6595
|
}
|
|
6582
6596
|
else {
|
|
6583
|
-
const searchPattern = new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6597
|
+
const searchPattern = new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), caseSensitive ? 'g' : 'gi');
|
|
6584
6598
|
const matches = originalText.match(searchPattern);
|
|
6585
6599
|
if (matches) {
|
|
6586
6600
|
replacementCount += matches.length;
|
|
@@ -6595,20 +6609,18 @@ class Document {
|
|
|
6595
6609
|
return replacementCount;
|
|
6596
6610
|
}
|
|
6597
6611
|
findAndReplaceAll(pattern, replacement, options) {
|
|
6598
|
-
const { caseSensitive = false, wholeWord = false, trackChanges = false, author =
|
|
6612
|
+
const { caseSensitive = false, wholeWord = false, trackChanges = false, author = 'Unknown', } = options || {};
|
|
6599
6613
|
let count = 0;
|
|
6600
6614
|
const revisions = [];
|
|
6601
6615
|
let regex;
|
|
6602
|
-
if (typeof pattern ===
|
|
6603
|
-
const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g,
|
|
6616
|
+
if (typeof pattern === 'string') {
|
|
6617
|
+
const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
6604
6618
|
const boundaryPattern = wholeWord ? `\\b${escaped}\\b` : escaped;
|
|
6605
|
-
const flags = caseSensitive ?
|
|
6619
|
+
const flags = caseSensitive ? 'g' : 'gi';
|
|
6606
6620
|
regex = new RegExp(boundaryPattern, flags);
|
|
6607
6621
|
}
|
|
6608
6622
|
else {
|
|
6609
|
-
const flags = pattern.flags.includes(
|
|
6610
|
-
? pattern.flags
|
|
6611
|
-
: pattern.flags + "g";
|
|
6623
|
+
const flags = pattern.flags.includes('g') ? pattern.flags : pattern.flags + 'g';
|
|
6612
6624
|
regex = new RegExp(pattern.source, flags);
|
|
6613
6625
|
}
|
|
6614
6626
|
const runs = this.getAllRuns();
|
|
@@ -6627,16 +6639,16 @@ class Document {
|
|
|
6627
6639
|
const newContent = [];
|
|
6628
6640
|
if (useGranular) {
|
|
6629
6641
|
for (const seg of segments) {
|
|
6630
|
-
if (seg.type ===
|
|
6642
|
+
if (seg.type === 'equal') {
|
|
6631
6643
|
newContent.push(new Run_1.Run(seg.text, formatting));
|
|
6632
6644
|
}
|
|
6633
|
-
else if (seg.type ===
|
|
6645
|
+
else if (seg.type === 'delete') {
|
|
6634
6646
|
const delRev = Revision_1.Revision.createDeletion(author, new Run_1.Run(seg.text, formatting), now);
|
|
6635
6647
|
this.revisionManager.register(delRev);
|
|
6636
6648
|
revisions.push(delRev);
|
|
6637
6649
|
newContent.push(delRev);
|
|
6638
6650
|
}
|
|
6639
|
-
else if (seg.type ===
|
|
6651
|
+
else if (seg.type === 'insert') {
|
|
6640
6652
|
const insRev = Revision_1.Revision.createInsertion(author, new Run_1.Run(seg.text, formatting), now);
|
|
6641
6653
|
this.revisionManager.register(insRev);
|
|
6642
6654
|
revisions.push(insRev);
|
|
@@ -6721,7 +6733,7 @@ class Document {
|
|
|
6721
6733
|
totalChars += text.length;
|
|
6722
6734
|
}
|
|
6723
6735
|
else {
|
|
6724
|
-
totalChars += text.replace(/\s/g,
|
|
6736
|
+
totalChars += text.replace(/\s/g, '').length;
|
|
6725
6737
|
}
|
|
6726
6738
|
}
|
|
6727
6739
|
const tables = this.getTables();
|
|
@@ -6741,7 +6753,7 @@ class Document {
|
|
|
6741
6753
|
totalChars += text.length;
|
|
6742
6754
|
}
|
|
6743
6755
|
else {
|
|
6744
|
-
totalChars += text.replace(/\s/g,
|
|
6756
|
+
totalChars += text.replace(/\s/g, '').length;
|
|
6745
6757
|
}
|
|
6746
6758
|
}
|
|
6747
6759
|
}
|
|
@@ -6751,7 +6763,7 @@ class Document {
|
|
|
6751
6763
|
}
|
|
6752
6764
|
removeParagraph(paragraphOrIndex) {
|
|
6753
6765
|
let index;
|
|
6754
|
-
if (typeof paragraphOrIndex ===
|
|
6766
|
+
if (typeof paragraphOrIndex === 'number') {
|
|
6755
6767
|
index = paragraphOrIndex;
|
|
6756
6768
|
}
|
|
6757
6769
|
else {
|
|
@@ -6778,7 +6790,7 @@ class Document {
|
|
|
6778
6790
|
}
|
|
6779
6791
|
removeTable(tableOrIndex) {
|
|
6780
6792
|
let index;
|
|
6781
|
-
if (typeof tableOrIndex ===
|
|
6793
|
+
if (typeof tableOrIndex === 'number') {
|
|
6782
6794
|
const tables = this.getTables();
|
|
6783
6795
|
if (tableOrIndex >= 0 && tableOrIndex < tables.length) {
|
|
6784
6796
|
const table = tables[tableOrIndex];
|
|
@@ -6804,7 +6816,7 @@ class Document {
|
|
|
6804
6816
|
}
|
|
6805
6817
|
validateParagraph(paragraph) {
|
|
6806
6818
|
if (!(paragraph instanceof Paragraph_1.Paragraph)) {
|
|
6807
|
-
throw new Error(
|
|
6819
|
+
throw new Error('insertParagraphAt: parameter must be a Paragraph instance');
|
|
6808
6820
|
}
|
|
6809
6821
|
const paraId = paragraph.getFormatting().paraId;
|
|
6810
6822
|
if (paraId) {
|
|
@@ -6827,15 +6839,15 @@ class Document {
|
|
|
6827
6839
|
}
|
|
6828
6840
|
validateTable(table) {
|
|
6829
6841
|
if (!(table instanceof Table_1.Table)) {
|
|
6830
|
-
throw new Error(
|
|
6842
|
+
throw new Error('insertTableAt: parameter must be a Table instance');
|
|
6831
6843
|
}
|
|
6832
6844
|
const rows = table.getRows();
|
|
6833
6845
|
if (rows.length === 0) {
|
|
6834
|
-
throw new Error(
|
|
6846
|
+
throw new Error('insertTableAt: table must have at least one row');
|
|
6835
6847
|
}
|
|
6836
6848
|
const firstRow = rows[0];
|
|
6837
6849
|
if (firstRow?.getCells().length === 0) {
|
|
6838
|
-
throw new Error(
|
|
6850
|
+
throw new Error('insertTableAt: table rows must have at least one cell');
|
|
6839
6851
|
}
|
|
6840
6852
|
const tableStyle = table.getFormatting().style;
|
|
6841
6853
|
if (tableStyle && !this.stylesManager.hasStyle(tableStyle)) {
|
|
@@ -6844,21 +6856,21 @@ class Document {
|
|
|
6844
6856
|
}
|
|
6845
6857
|
validateToc(toc) {
|
|
6846
6858
|
if (!(toc instanceof TableOfContentsElement_1.TableOfContentsElement)) {
|
|
6847
|
-
throw new Error(
|
|
6859
|
+
throw new Error('insertTocAt: parameter must be a TableOfContentsElement instance');
|
|
6848
6860
|
}
|
|
6849
6861
|
const hasHeadings = [
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6862
|
+
'Heading1',
|
|
6863
|
+
'Heading2',
|
|
6864
|
+
'Heading3',
|
|
6865
|
+
'Heading4',
|
|
6866
|
+
'Heading5',
|
|
6867
|
+
'Heading6',
|
|
6868
|
+
'Heading7',
|
|
6869
|
+
'Heading8',
|
|
6870
|
+
'Heading9',
|
|
6859
6871
|
].some((style) => this.stylesManager.hasStyle(style));
|
|
6860
6872
|
if (!hasHeadings) {
|
|
6861
|
-
logger_1.defaultLogger.warn(
|
|
6873
|
+
logger_1.defaultLogger.warn('No heading styles found in document. Table of Contents may not display entries correctly.');
|
|
6862
6874
|
}
|
|
6863
6875
|
}
|
|
6864
6876
|
normalizeIndex(index) {
|
|
@@ -7320,7 +7332,7 @@ class Document {
|
|
|
7320
7332
|
const toRemove = [];
|
|
7321
7333
|
this.bodyElements.forEach((element, index) => {
|
|
7322
7334
|
if (element instanceof Paragraph_1.Paragraph) {
|
|
7323
|
-
const isEmpty = element.getText().trim() ===
|
|
7335
|
+
const isEmpty = element.getText().trim() === '';
|
|
7324
7336
|
if (isEmpty && lastWasEmpty) {
|
|
7325
7337
|
toRemove.push(index);
|
|
7326
7338
|
}
|
|
@@ -7347,7 +7359,7 @@ class Document {
|
|
|
7347
7359
|
}
|
|
7348
7360
|
}
|
|
7349
7361
|
if (standardLineSpacing !== undefined) {
|
|
7350
|
-
para.setLineSpacing(standardLineSpacing,
|
|
7362
|
+
para.setLineSpacing(standardLineSpacing, 'auto');
|
|
7351
7363
|
normalized++;
|
|
7352
7364
|
}
|
|
7353
7365
|
if (removeTrailingSpaces) {
|
|
@@ -7381,7 +7393,7 @@ class Document {
|
|
|
7381
7393
|
}
|
|
7382
7394
|
}
|
|
7383
7395
|
if (standardLineSpacing !== undefined) {
|
|
7384
|
-
para.setLineSpacing(standardLineSpacing,
|
|
7396
|
+
para.setLineSpacing(standardLineSpacing, 'auto');
|
|
7385
7397
|
normalized++;
|
|
7386
7398
|
}
|
|
7387
7399
|
if (removeTrailingSpaces) {
|
|
@@ -7490,9 +7502,9 @@ class Document {
|
|
|
7490
7502
|
}
|
|
7491
7503
|
normalizeTableBorders(options) {
|
|
7492
7504
|
const border = {
|
|
7493
|
-
style: options?.style ??
|
|
7505
|
+
style: options?.style ?? 'single',
|
|
7494
7506
|
size: options?.size ?? 4,
|
|
7495
|
-
color: options?.color ??
|
|
7507
|
+
color: options?.color ?? '000000',
|
|
7496
7508
|
};
|
|
7497
7509
|
return this.applyBordersToAllTables(border);
|
|
7498
7510
|
}
|
|
@@ -7502,8 +7514,8 @@ class Document {
|
|
|
7502
7514
|
const matchItalic = options?.matchItalic ?? false;
|
|
7503
7515
|
const matchCase = options?.matchCase ?? false;
|
|
7504
7516
|
const pattern = matchCase
|
|
7505
|
-
? new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g,
|
|
7506
|
-
: new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g,
|
|
7517
|
+
? new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g')
|
|
7518
|
+
: new RegExp(find.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi');
|
|
7507
7519
|
for (const para of this.getAllParagraphs()) {
|
|
7508
7520
|
for (const run of para.getRuns()) {
|
|
7509
7521
|
const text = run.getText();
|
|
@@ -7555,21 +7567,21 @@ class Document {
|
|
|
7555
7567
|
static createEmpty() {
|
|
7556
7568
|
const doc = new Document(undefined, {}, false);
|
|
7557
7569
|
const zipHandler = doc.getZipHandler();
|
|
7558
|
-
zipHandler.addFile(
|
|
7570
|
+
zipHandler.addFile('[Content_Types].xml', '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
7559
7571
|
'<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">\n' +
|
|
7560
7572
|
' <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>\n' +
|
|
7561
7573
|
' <Default Extension="xml" ContentType="application/xml"/>\n' +
|
|
7562
7574
|
' <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>\n' +
|
|
7563
|
-
|
|
7564
|
-
zipHandler.addFile(
|
|
7575
|
+
'</Types>');
|
|
7576
|
+
zipHandler.addFile('_rels/.rels', '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
7565
7577
|
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">\n' +
|
|
7566
7578
|
' <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>\n' +
|
|
7567
|
-
|
|
7568
|
-
zipHandler.addFile(
|
|
7579
|
+
'</Relationships>');
|
|
7580
|
+
zipHandler.addFile('word/document.xml', '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
7569
7581
|
'<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">\n' +
|
|
7570
|
-
|
|
7571
|
-
|
|
7572
|
-
zipHandler.addFile(
|
|
7582
|
+
' <w:body/>\n' +
|
|
7583
|
+
'</w:document>');
|
|
7584
|
+
zipHandler.addFile('word/_rels/document.xml.rels', '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
|
|
7573
7585
|
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"/>');
|
|
7574
7586
|
return doc;
|
|
7575
7587
|
}
|