docxmlater 7.3.2 → 7.3.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/dist/core/DocumentParser.d.ts +1 -0
- package/dist/core/DocumentParser.d.ts.map +1 -1
- package/dist/core/DocumentParser.js +203 -0
- package/dist/core/DocumentParser.js.map +1 -1
- package/dist/elements/Run.d.ts +2 -1
- package/dist/elements/Run.d.ts.map +1 -1
- package/dist/elements/Run.js +8 -0
- package/dist/elements/Run.js.map +1 -1
- package/dist/xml/XMLBuilder.d.ts +1 -0
- package/dist/xml/XMLBuilder.d.ts.map +1 -1
- package/dist/xml/XMLBuilder.js +6 -0
- package/dist/xml/XMLBuilder.js.map +1 -1
- package/package.json +1 -1
|
@@ -46,6 +46,7 @@ export declare class DocumentParser {
|
|
|
46
46
|
private assembleMultiParagraphFields;
|
|
47
47
|
private collectAllParagraphs;
|
|
48
48
|
private processMultiParagraphField;
|
|
49
|
+
private processMultiParagraphFieldAsComplexField;
|
|
49
50
|
private createComplexFieldFromRuns;
|
|
50
51
|
private parseRunFromObject;
|
|
51
52
|
private parseHyperlinkFromObject;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentParser.d.ts","sourceRoot":"","sources":["../../src/core/DocumentParser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DocumentParser.d.ts","sourceRoot":"","sources":["../../src/core/DocumentParser.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,SAAS,EAAyC,MAAM,uBAAuB,CAAC;AAGzF,OAAO,EAEL,OAAO,EAGR,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AAE5E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
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.DocumentParser = void 0;
|
|
37
37
|
const Field_1 = require("../elements/Field");
|
|
38
|
+
const FieldHelpers_1 = require("../elements/FieldHelpers");
|
|
38
39
|
const Footer_1 = require("../elements/Footer");
|
|
39
40
|
const Header_1 = require("../elements/Header");
|
|
40
41
|
const Hyperlink_1 = require("../elements/Hyperlink");
|
|
@@ -424,6 +425,32 @@ class DocumentParser {
|
|
|
424
425
|
const delXmls = XMLParser_1.XMLParser.extractElements(paraContent, "w:del");
|
|
425
426
|
const moveFromXmls = XMLParser_1.XMLParser.extractElements(paraContent, "w:moveFrom");
|
|
426
427
|
const moveToXmls = XMLParser_1.XMLParser.extractElements(paraContent, "w:moveTo");
|
|
428
|
+
const extractRunXmlAtPosition = (pos) => {
|
|
429
|
+
const closeTag = "</w:r>";
|
|
430
|
+
let depth = 1;
|
|
431
|
+
let searchPos = paraContent.indexOf(">", pos) + 1;
|
|
432
|
+
while (depth > 0 && searchPos < paraContent.length) {
|
|
433
|
+
const nextOpen = paraContent.indexOf("<w:r", searchPos);
|
|
434
|
+
const nextClose = paraContent.indexOf(closeTag, searchPos);
|
|
435
|
+
if (nextClose === -1)
|
|
436
|
+
break;
|
|
437
|
+
if (nextOpen !== -1 && nextOpen < nextClose) {
|
|
438
|
+
const charAfter = paraContent[nextOpen + 4];
|
|
439
|
+
if (charAfter === ">" || charAfter === " " || charAfter === "/") {
|
|
440
|
+
depth++;
|
|
441
|
+
}
|
|
442
|
+
searchPos = nextOpen + 4;
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
depth--;
|
|
446
|
+
if (depth === 0) {
|
|
447
|
+
return paraContent.substring(pos, nextClose + closeTag.length);
|
|
448
|
+
}
|
|
449
|
+
searchPos = nextClose + closeTag.length;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return null;
|
|
453
|
+
};
|
|
427
454
|
for (const child of children) {
|
|
428
455
|
if (child.type === "w:r") {
|
|
429
456
|
const runs = pElement["w:r"];
|
|
@@ -438,6 +465,17 @@ class DocumentParser {
|
|
|
438
465
|
}
|
|
439
466
|
}
|
|
440
467
|
}
|
|
468
|
+
else if (runObj["w:pict"]) {
|
|
469
|
+
const runXml = extractRunXmlAtPosition(child.pos);
|
|
470
|
+
if (runXml) {
|
|
471
|
+
const pictXmls = XMLParser_1.XMLParser.extractElements(runXml, "w:pict");
|
|
472
|
+
if (pictXmls.length > 0 && pictXmls[0]) {
|
|
473
|
+
const run = Run_1.Run.createFromContent([{ type: "vml", rawXml: pictXmls[0] }]);
|
|
474
|
+
this.parseRunPropertiesFromObject(runObj["w:rPr"], run);
|
|
475
|
+
paragraph.addRun(run);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
441
479
|
else {
|
|
442
480
|
const run = this.parseRunFromObject(runObj);
|
|
443
481
|
if (run) {
|
|
@@ -1060,6 +1098,75 @@ class DocumentParser {
|
|
|
1060
1098
|
case "end":
|
|
1061
1099
|
fieldState = "end";
|
|
1062
1100
|
if (fieldState === "end" && fieldRuns.length > 0) {
|
|
1101
|
+
let instruction = "";
|
|
1102
|
+
let resultText = "";
|
|
1103
|
+
let resultFormatting;
|
|
1104
|
+
let hasSeparate = false;
|
|
1105
|
+
for (const run of fieldRuns) {
|
|
1106
|
+
const runContent = run.getContent();
|
|
1107
|
+
const instrText = runContent.find((c) => c.type === "instructionText");
|
|
1108
|
+
if (instrText) {
|
|
1109
|
+
instruction += instrText.value || "";
|
|
1110
|
+
}
|
|
1111
|
+
const fieldCharToken = runContent.find((c) => c.type === "fieldChar");
|
|
1112
|
+
if (fieldCharToken?.fieldCharType === "separate") {
|
|
1113
|
+
hasSeparate = true;
|
|
1114
|
+
}
|
|
1115
|
+
const textContent = runContent.find((c) => c.type === "text");
|
|
1116
|
+
if (textContent && hasSeparate) {
|
|
1117
|
+
resultText += textContent.value || "";
|
|
1118
|
+
resultFormatting = run.getFormatting();
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
instruction = instruction.trim();
|
|
1122
|
+
if ((0, FieldHelpers_1.isHyperlinkInstruction)(instruction)) {
|
|
1123
|
+
const parsed = (0, FieldHelpers_1.parseHyperlinkInstruction)(instruction);
|
|
1124
|
+
if (parsed && resultText) {
|
|
1125
|
+
let hyperlink;
|
|
1126
|
+
if (parsed.url && parsed.url.trim() !== "") {
|
|
1127
|
+
hyperlink = Hyperlink_1.Hyperlink.createExternal(parsed.fullUrl, resultText, {
|
|
1128
|
+
...resultFormatting,
|
|
1129
|
+
color: resultFormatting?.color || "0000FF",
|
|
1130
|
+
underline: resultFormatting?.underline || "single",
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
else if (parsed.anchor) {
|
|
1134
|
+
hyperlink = Hyperlink_1.Hyperlink.createInternal(parsed.anchor, resultText, {
|
|
1135
|
+
...resultFormatting,
|
|
1136
|
+
color: resultFormatting?.color || "0000FF",
|
|
1137
|
+
underline: resultFormatting?.underline || "single",
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
else {
|
|
1141
|
+
const complexField = this.createComplexFieldFromRuns(fieldRuns);
|
|
1142
|
+
if (complexField) {
|
|
1143
|
+
groupedContent.push(complexField);
|
|
1144
|
+
}
|
|
1145
|
+
else {
|
|
1146
|
+
fieldRuns.forEach((run) => groupedContent.push(run));
|
|
1147
|
+
}
|
|
1148
|
+
for (const revision of fieldRevisions) {
|
|
1149
|
+
groupedContent.push(revision);
|
|
1150
|
+
}
|
|
1151
|
+
fieldRuns = [];
|
|
1152
|
+
fieldRevisions = [];
|
|
1153
|
+
fieldState = null;
|
|
1154
|
+
break;
|
|
1155
|
+
}
|
|
1156
|
+
if (parsed.tooltip) {
|
|
1157
|
+
hyperlink.setTooltip(parsed.tooltip);
|
|
1158
|
+
}
|
|
1159
|
+
groupedContent.push(hyperlink);
|
|
1160
|
+
for (const revision of fieldRevisions) {
|
|
1161
|
+
groupedContent.push(revision);
|
|
1162
|
+
}
|
|
1163
|
+
logger_1.defaultLogger.debug(`Converted single-paragraph HYPERLINK field to Hyperlink element`);
|
|
1164
|
+
fieldRuns = [];
|
|
1165
|
+
fieldRevisions = [];
|
|
1166
|
+
fieldState = null;
|
|
1167
|
+
break;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1063
1170
|
const complexField = this.createComplexFieldFromRuns(fieldRuns);
|
|
1064
1171
|
if (complexField) {
|
|
1065
1172
|
groupedContent.push(complexField);
|
|
@@ -1247,6 +1354,102 @@ class DocumentParser {
|
|
|
1247
1354
|
}
|
|
1248
1355
|
processMultiParagraphField(fieldTracker, allParagraphs) {
|
|
1249
1356
|
const runs = fieldTracker.fieldRuns.map((fr) => fr.run);
|
|
1357
|
+
let instruction = "";
|
|
1358
|
+
let resultText = "";
|
|
1359
|
+
let resultFormatting;
|
|
1360
|
+
let hasSeparate = false;
|
|
1361
|
+
let resultParagraphIndex;
|
|
1362
|
+
for (let i = 0; i < fieldTracker.fieldRuns.length; i++) {
|
|
1363
|
+
const fr = fieldTracker.fieldRuns[i];
|
|
1364
|
+
const runContent = fr.run.getContent();
|
|
1365
|
+
const fieldCharToken = runContent.find((c) => c.type === "fieldChar");
|
|
1366
|
+
if (fieldCharToken) {
|
|
1367
|
+
if (fieldCharToken.fieldCharType === "separate") {
|
|
1368
|
+
hasSeparate = true;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
const instrText = runContent.find((c) => c.type === "instructionText");
|
|
1372
|
+
if (instrText) {
|
|
1373
|
+
instruction += instrText.value || "";
|
|
1374
|
+
}
|
|
1375
|
+
const textContent = runContent.find((c) => c.type === "text");
|
|
1376
|
+
if (textContent && hasSeparate) {
|
|
1377
|
+
resultText += textContent.value || "";
|
|
1378
|
+
resultFormatting = fr.run.getFormatting();
|
|
1379
|
+
resultParagraphIndex = fr.paragraphIndex;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
instruction = instruction.trim();
|
|
1383
|
+
if ((0, FieldHelpers_1.isHyperlinkInstruction)(instruction)) {
|
|
1384
|
+
const parsed = (0, FieldHelpers_1.parseHyperlinkInstruction)(instruction);
|
|
1385
|
+
if (parsed && resultText) {
|
|
1386
|
+
const targetParagraphIndex = resultParagraphIndex ?? fieldTracker.startParagraphIndex;
|
|
1387
|
+
const targetParagraph = allParagraphs[targetParagraphIndex];
|
|
1388
|
+
if (targetParagraph) {
|
|
1389
|
+
let hyperlink;
|
|
1390
|
+
if (parsed.url && parsed.url.trim() !== "") {
|
|
1391
|
+
hyperlink = Hyperlink_1.Hyperlink.createExternal(parsed.fullUrl, resultText, {
|
|
1392
|
+
...resultFormatting,
|
|
1393
|
+
color: resultFormatting?.color || "0000FF",
|
|
1394
|
+
underline: resultFormatting?.underline || "single",
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
else if (parsed.anchor) {
|
|
1398
|
+
hyperlink = Hyperlink_1.Hyperlink.createInternal(parsed.anchor, resultText, {
|
|
1399
|
+
...resultFormatting,
|
|
1400
|
+
color: resultFormatting?.color || "0000FF",
|
|
1401
|
+
underline: resultFormatting?.underline || "single",
|
|
1402
|
+
});
|
|
1403
|
+
}
|
|
1404
|
+
else {
|
|
1405
|
+
logger_1.defaultLogger.debug("HYPERLINK field missing URL and anchor, falling back to ComplexField");
|
|
1406
|
+
this.processMultiParagraphFieldAsComplexField(fieldTracker, allParagraphs, runs);
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
if (parsed.tooltip) {
|
|
1410
|
+
hyperlink.setTooltip(parsed.tooltip);
|
|
1411
|
+
}
|
|
1412
|
+
const runsByParagraph = new Map();
|
|
1413
|
+
for (const fr of fieldTracker.fieldRuns) {
|
|
1414
|
+
if (!runsByParagraph.has(fr.paragraphIndex)) {
|
|
1415
|
+
runsByParagraph.set(fr.paragraphIndex, new Set());
|
|
1416
|
+
}
|
|
1417
|
+
runsByParagraph.get(fr.paragraphIndex).add(fr.runIndex);
|
|
1418
|
+
}
|
|
1419
|
+
const affectedParagraphIndices = Array.from(runsByParagraph.keys()).sort((a, b) => a - b);
|
|
1420
|
+
for (const pIdx of affectedParagraphIndices) {
|
|
1421
|
+
const paragraph = allParagraphs[pIdx];
|
|
1422
|
+
const runIndicesToRemove = runsByParagraph.get(pIdx);
|
|
1423
|
+
const content = paragraph.getContent();
|
|
1424
|
+
if (pIdx === targetParagraphIndex) {
|
|
1425
|
+
const newContent = [];
|
|
1426
|
+
let hyperlinkInserted = false;
|
|
1427
|
+
for (let rIdx = 0; rIdx < content.length; rIdx++) {
|
|
1428
|
+
if (runIndicesToRemove.has(rIdx)) {
|
|
1429
|
+
if (!hyperlinkInserted) {
|
|
1430
|
+
newContent.push(hyperlink);
|
|
1431
|
+
hyperlinkInserted = true;
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
else {
|
|
1435
|
+
newContent.push(content[rIdx]);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
paragraph.setContent(newContent);
|
|
1439
|
+
}
|
|
1440
|
+
else {
|
|
1441
|
+
const newContent = content.filter((_, rIdx) => !runIndicesToRemove.has(rIdx));
|
|
1442
|
+
paragraph.setContent(newContent);
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
logger_1.defaultLogger.debug(`Converted multi-paragraph HYPERLINK field to Hyperlink element in paragraph ${targetParagraphIndex}`);
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
this.processMultiParagraphFieldAsComplexField(fieldTracker, allParagraphs, runs);
|
|
1451
|
+
}
|
|
1452
|
+
processMultiParagraphFieldAsComplexField(fieldTracker, allParagraphs, runs) {
|
|
1250
1453
|
const complexField = this.createComplexFieldFromRuns(runs);
|
|
1251
1454
|
if (!complexField) {
|
|
1252
1455
|
logger_1.defaultLogger.debug("Failed to create ComplexField from multi-paragraph runs");
|