docxmlater 3.1.0 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -54
- package/dist/core/Document.d.ts +1 -0
- package/dist/core/Document.d.ts.map +1 -1
- package/dist/core/Document.js +38 -40
- package/dist/core/Document.js.map +1 -1
- package/dist/elements/Paragraph.d.ts +27 -27
- package/dist/elements/Paragraph.d.ts.map +1 -1
- package/dist/elements/Paragraph.js +156 -127
- package/dist/elements/Paragraph.js.map +1 -1
- package/dist/elements/Run.d.ts +14 -14
- package/dist/elements/Run.d.ts.map +1 -1
- package/dist/elements/Run.js +137 -133
- package/dist/elements/Run.js.map +1 -1
- package/dist/elements/Table.d.ts +13 -13
- package/dist/elements/Table.d.ts.map +1 -1
- package/dist/elements/Table.js +61 -51
- package/dist/elements/Table.js.map +1 -1
- package/package.json +1 -1
package/dist/core/Document.js
CHANGED
|
@@ -418,6 +418,7 @@ class Document {
|
|
|
418
418
|
images: sizeInfo.images,
|
|
419
419
|
});
|
|
420
420
|
}
|
|
421
|
+
this.clearAllPreserveFlags();
|
|
421
422
|
this.processHyperlinks();
|
|
422
423
|
this.updateDocumentXml();
|
|
423
424
|
this.updateStylesXml();
|
|
@@ -466,6 +467,7 @@ class Document {
|
|
|
466
467
|
images: sizeInfo.images,
|
|
467
468
|
});
|
|
468
469
|
}
|
|
470
|
+
this.clearAllPreserveFlags();
|
|
469
471
|
this.processHyperlinks();
|
|
470
472
|
this.updateDocumentXml();
|
|
471
473
|
this.updateStylesXml();
|
|
@@ -2006,6 +2008,7 @@ class Document {
|
|
|
2006
2008
|
const nextElement = this.bodyElements[tableIndex + 1];
|
|
2007
2009
|
if (nextElement instanceof Paragraph_1.Paragraph) {
|
|
2008
2010
|
if (this.isParagraphBlank(nextElement)) {
|
|
2011
|
+
nextElement.setStyle(style);
|
|
2009
2012
|
if (markAsPreserved && !nextElement.isPreserved()) {
|
|
2010
2013
|
nextElement.setPreserved(true);
|
|
2011
2014
|
existingLinesMarked++;
|
|
@@ -2067,6 +2070,7 @@ class Document {
|
|
|
2067
2070
|
const nextElement = this.bodyElements[tableIndex + 1];
|
|
2068
2071
|
if (nextElement instanceof Paragraph_1.Paragraph) {
|
|
2069
2072
|
if (this.isParagraphBlank(nextElement)) {
|
|
2073
|
+
nextElement.setStyle(style);
|
|
2070
2074
|
if (markAsPreserved && !nextElement.isPreserved()) {
|
|
2071
2075
|
nextElement.setPreserved(true);
|
|
2072
2076
|
existingLinesMarked++;
|
|
@@ -2424,76 +2428,70 @@ class Document {
|
|
|
2424
2428
|
}
|
|
2425
2429
|
return true;
|
|
2426
2430
|
}
|
|
2431
|
+
clearAllPreserveFlags() {
|
|
2432
|
+
let cleared = 0;
|
|
2433
|
+
for (const para of this.getAllParagraphs()) {
|
|
2434
|
+
if (para.isPreserved()) {
|
|
2435
|
+
para.setPreserved(false);
|
|
2436
|
+
cleared++;
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
return cleared;
|
|
2440
|
+
}
|
|
2427
2441
|
parseTOCFieldInstruction(instrText) {
|
|
2428
2442
|
const levels = new Set();
|
|
2429
2443
|
let hasOutlineSwitch = false;
|
|
2430
2444
|
let hasTableSwitch = false;
|
|
2431
|
-
|
|
2432
|
-
const outlineMatch =
|
|
2433
|
-
if (outlineMatch
|
|
2445
|
+
const normalizedText = instrText.trim().replace(/"/g, '"');
|
|
2446
|
+
const outlineMatch = normalizedText.match(/\\o\s+"(\d+)-(\d+)"/);
|
|
2447
|
+
if (outlineMatch?.[1] && outlineMatch?.[2]) {
|
|
2434
2448
|
hasOutlineSwitch = true;
|
|
2435
2449
|
const start = parseInt(outlineMatch[1], 10);
|
|
2436
2450
|
const end = parseInt(outlineMatch[2], 10);
|
|
2437
2451
|
for (let i = start; i <= end; i++) {
|
|
2438
|
-
if (i >= 1 && i <= 9)
|
|
2452
|
+
if (i >= 1 && i <= 9)
|
|
2439
2453
|
levels.add(i);
|
|
2440
|
-
}
|
|
2441
2454
|
}
|
|
2442
2455
|
}
|
|
2443
|
-
if (
|
|
2444
|
-
|
|
2445
|
-
if (!hasOutlineSwitch && !
|
|
2446
|
-
for (let i = 1; i <= 9; i++)
|
|
2456
|
+
if (/\\u(?:\s|\\|$)/.test(normalizedText)) {
|
|
2457
|
+
const hasTSwitch = /\\t\s+"/.test(normalizedText);
|
|
2458
|
+
if (!hasOutlineSwitch && !hasTSwitch) {
|
|
2459
|
+
for (let i = 1; i <= 9; i++)
|
|
2447
2460
|
levels.add(i);
|
|
2448
|
-
}
|
|
2449
2461
|
}
|
|
2450
2462
|
}
|
|
2451
|
-
const
|
|
2452
|
-
|
|
2463
|
+
const tSwitchRegex = /\\t\s+"([^"]*)"/g;
|
|
2464
|
+
const tMatches = [...normalizedText.matchAll(tSwitchRegex)];
|
|
2465
|
+
for (const match of tMatches) {
|
|
2453
2466
|
hasTableSwitch = true;
|
|
2454
|
-
const content = match[1];
|
|
2467
|
+
const content = (match[1] || "").trim();
|
|
2455
2468
|
if (!content)
|
|
2456
2469
|
continue;
|
|
2457
2470
|
const rangeMatch = content.match(/^(\d+)-(\d+)$/);
|
|
2458
|
-
if (rangeMatch
|
|
2471
|
+
if (rangeMatch?.[1] && rangeMatch?.[2]) {
|
|
2459
2472
|
const start = parseInt(rangeMatch[1], 10);
|
|
2460
2473
|
const end = parseInt(rangeMatch[2], 10);
|
|
2461
2474
|
for (let i = start; i <= end; i++) {
|
|
2462
|
-
if (i >= 1 && i <= 9)
|
|
2475
|
+
if (i >= 1 && i <= 9)
|
|
2463
2476
|
levels.add(i);
|
|
2464
|
-
}
|
|
2465
2477
|
}
|
|
2466
2478
|
continue;
|
|
2467
2479
|
}
|
|
2468
2480
|
const parts = content
|
|
2469
2481
|
.split(",")
|
|
2470
2482
|
.map((p) => p.trim())
|
|
2471
|
-
.filter(
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
const headingMatch = styleName.match(/Heading\s*(\d+)/i);
|
|
2482
|
-
if (headingMatch && headingMatch[1]) {
|
|
2483
|
-
const headingLevel = parseInt(headingMatch[1], 10);
|
|
2484
|
-
if (headingLevel >= 1 && headingLevel <= 9) {
|
|
2485
|
-
levels.add(headingLevel);
|
|
2483
|
+
.filter(Boolean);
|
|
2484
|
+
for (let i = 0; i < parts.length; i += 2) {
|
|
2485
|
+
if (i + 1 < parts.length) {
|
|
2486
|
+
const levelStr = parts[i + 1];
|
|
2487
|
+
if (levelStr) {
|
|
2488
|
+
const level = parseInt(levelStr, 10);
|
|
2489
|
+
if (!isNaN(level) && level >= 1 && level <= 9) {
|
|
2490
|
+
levels.add(level);
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2486
2493
|
}
|
|
2487
2494
|
}
|
|
2488
|
-
else if (level >= 1 && level <= 9) {
|
|
2489
|
-
levels.add(level);
|
|
2490
|
-
}
|
|
2491
|
-
}
|
|
2492
|
-
if (levels.size === 0) {
|
|
2493
|
-
if (!hasOutlineSwitch && !hasTableSwitch && !hasUseOutlineLevelsSwitch) {
|
|
2494
|
-
return [1, 2, 3];
|
|
2495
|
-
}
|
|
2496
|
-
return [];
|
|
2497
2495
|
}
|
|
2498
2496
|
return Array.from(levels).sort((a, b) => a - b);
|
|
2499
2497
|
}
|