docxmlater 2.2.1 → 2.2.2
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 +9 -7
- package/dist/core/DocumentParser.d.ts.map +1 -1
- package/dist/core/DocumentParser.js +223 -23
- package/dist/core/DocumentParser.js.map +1 -1
- package/dist/elements/Paragraph.d.ts +10 -8
- package/dist/elements/Paragraph.d.ts.map +1 -1
- package/dist/elements/Paragraph.js +19 -6
- package/dist/elements/Paragraph.js.map +1 -1
- package/dist/elements/Run.d.ts +4 -1
- package/dist/elements/Run.d.ts.map +1 -1
- package/dist/elements/Run.js +26 -3
- package/dist/elements/Run.js.map +1 -1
- package/dist/xml/XMLParser.d.ts.map +1 -1
- package/dist/xml/XMLParser.js +1 -2
- package/dist/xml/XMLParser.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ImageManager } from "../elements/ImageManager";
|
|
2
2
|
import { Paragraph } from "../elements/Paragraph";
|
|
3
|
+
import { Section } from "../elements/Section";
|
|
4
|
+
import { StructuredDocumentTag } from "../elements/StructuredDocumentTag";
|
|
3
5
|
import { Table } from "../elements/Table";
|
|
4
6
|
import { TableOfContentsElement } from "../elements/TableOfContentsElement";
|
|
5
|
-
import { StructuredDocumentTag } from "../elements/StructuredDocumentTag";
|
|
6
|
-
import { ImageManager } from "../elements/ImageManager";
|
|
7
|
-
import { Section } from "../elements/Section";
|
|
8
|
-
import { RelationshipManager } from "./RelationshipManager";
|
|
9
|
-
import { DocumentProperties } from "./Document";
|
|
10
|
-
import { Style } from "../formatting/Style";
|
|
11
7
|
import { AbstractNumbering } from "../formatting/AbstractNumbering";
|
|
12
8
|
import { NumberingInstance } from "../formatting/NumberingInstance";
|
|
9
|
+
import { Style } from "../formatting/Style";
|
|
10
|
+
import { ZipHandler } from "../zip/ZipHandler";
|
|
11
|
+
import { DocumentProperties } from "./Document";
|
|
12
|
+
import { RelationshipManager } from "./RelationshipManager";
|
|
13
13
|
export interface ParseError {
|
|
14
14
|
element: string;
|
|
15
15
|
error: Error;
|
|
@@ -40,6 +40,8 @@ export declare class DocumentParser {
|
|
|
40
40
|
private parseParagraphWithOrder;
|
|
41
41
|
private parseParagraphFromObject;
|
|
42
42
|
private parseParagraphPropertiesFromObject;
|
|
43
|
+
private assembleComplexFields;
|
|
44
|
+
private createComplexFieldFromRuns;
|
|
43
45
|
private parseRunFromObject;
|
|
44
46
|
private parseHyperlinkFromObject;
|
|
45
47
|
private mergeConsecutiveHyperlinks;
|
|
@@ -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":"AAOA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,SAAS,EAAuB,MAAM,uBAAuB,CAAC;AAEvE,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,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,KAAK,EAA8B,MAAM,qBAAqB,CAAC;AAKxE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAK5D,MAAM,WAAW,UAAU;IACzB,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AAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IA6DF,OAAO,CAAC,eAAe;IAkCjB,sBAAsB,CAC1B,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,OAAO,GAAG,IAAI,EACvB,mBAAmB,EAAE,mBAAmB,EACxC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC;QACT,OAAO,EAAE,KAAK,CAAC;YAAE,MAAM,EAAE,OAAO,oBAAoB,EAAE,MAAM,CAAC;YAAC,cAAc,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAC1G,OAAO,EAAE,KAAK,CAAC;YAAE,MAAM,EAAE,OAAO,oBAAoB,EAAE,MAAM,CAAC;YAAC,cAAc,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC3G,CAAC;YAwEY,WAAW;YAkDX,WAAW;CAwC1B"}
|
|
@@ -34,27 +34,27 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.DocumentParser = void 0;
|
|
37
|
-
const types_1 = require("../zip/types");
|
|
38
|
-
const Paragraph_1 = require("../elements/Paragraph");
|
|
39
|
-
const Run_1 = require("../elements/Run");
|
|
40
37
|
const Field_1 = require("../elements/Field");
|
|
41
38
|
const Hyperlink_1 = require("../elements/Hyperlink");
|
|
39
|
+
const ImageRun_1 = require("../elements/ImageRun");
|
|
40
|
+
const Paragraph_1 = require("../elements/Paragraph");
|
|
41
|
+
const Run_1 = require("../elements/Run");
|
|
42
|
+
const Section_1 = require("../elements/Section");
|
|
43
|
+
const StructuredDocumentTag_1 = require("../elements/StructuredDocumentTag");
|
|
42
44
|
const Table_1 = require("../elements/Table");
|
|
43
|
-
const TableRow_1 = require("../elements/TableRow");
|
|
44
45
|
const TableCell_1 = require("../elements/TableCell");
|
|
45
|
-
const TableOfContentsElement_1 = require("../elements/TableOfContentsElement");
|
|
46
46
|
const TableOfContents_1 = require("../elements/TableOfContents");
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const Section_1 = require("../elements/Section");
|
|
50
|
-
const XMLBuilder_1 = require("../xml/XMLBuilder");
|
|
51
|
-
const XMLParser_1 = require("../xml/XMLParser");
|
|
52
|
-
const RelationshipManager_1 = require("./RelationshipManager");
|
|
53
|
-
const Style_1 = require("../formatting/Style");
|
|
47
|
+
const TableOfContentsElement_1 = require("../elements/TableOfContentsElement");
|
|
48
|
+
const TableRow_1 = require("../elements/TableRow");
|
|
54
49
|
const AbstractNumbering_1 = require("../formatting/AbstractNumbering");
|
|
55
50
|
const NumberingInstance_1 = require("../formatting/NumberingInstance");
|
|
51
|
+
const Style_1 = require("../formatting/Style");
|
|
56
52
|
const diagnostics_1 = require("../utils/diagnostics");
|
|
57
53
|
const logger_1 = require("../utils/logger");
|
|
54
|
+
const XMLBuilder_1 = require("../xml/XMLBuilder");
|
|
55
|
+
const XMLParser_1 = require("../xml/XMLParser");
|
|
56
|
+
const types_1 = require("../zip/types");
|
|
57
|
+
const RelationshipManager_1 = require("./RelationshipManager");
|
|
58
58
|
class DocumentParser {
|
|
59
59
|
parseErrors = [];
|
|
60
60
|
strictParsing;
|
|
@@ -347,6 +347,7 @@ class DocumentParser {
|
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
|
+
this.assembleComplexFields(paragraph);
|
|
350
351
|
const runs = paragraph.getRuns();
|
|
351
352
|
const runData = runs.map(run => ({
|
|
352
353
|
text: run.getText(),
|
|
@@ -716,33 +717,210 @@ class DocumentParser {
|
|
|
716
717
|
paragraph.setSectionProperties(pPrObj["w:sectPr"]);
|
|
717
718
|
}
|
|
718
719
|
}
|
|
720
|
+
assembleComplexFields(paragraph) {
|
|
721
|
+
const content = paragraph.getContent();
|
|
722
|
+
const groupedContent = [];
|
|
723
|
+
let fieldRuns = [];
|
|
724
|
+
let fieldState = null;
|
|
725
|
+
for (let i = 0; i < content.length; i++) {
|
|
726
|
+
const item = content[i];
|
|
727
|
+
if (item instanceof Run_1.Run) {
|
|
728
|
+
const runContent = item.getContent();
|
|
729
|
+
const hasFieldContent = runContent.some((c) => c.type === 'fieldChar' || c.type === 'instructionText');
|
|
730
|
+
if (hasFieldContent) {
|
|
731
|
+
fieldRuns.push(item);
|
|
732
|
+
const fieldChar = runContent.find((c) => c.type === 'fieldChar');
|
|
733
|
+
if (fieldChar) {
|
|
734
|
+
switch (fieldChar.fieldCharType) {
|
|
735
|
+
case 'begin':
|
|
736
|
+
fieldState = 'begin';
|
|
737
|
+
break;
|
|
738
|
+
case 'separate':
|
|
739
|
+
fieldState = 'separate';
|
|
740
|
+
break;
|
|
741
|
+
case 'end':
|
|
742
|
+
fieldState = 'end';
|
|
743
|
+
if (fieldState === 'end' && fieldRuns.length > 0) {
|
|
744
|
+
const complexField = this.createComplexFieldFromRuns(fieldRuns);
|
|
745
|
+
if (complexField) {
|
|
746
|
+
groupedContent.push(complexField);
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
fieldRuns.forEach(run => groupedContent.push(run));
|
|
750
|
+
}
|
|
751
|
+
fieldRuns = [];
|
|
752
|
+
fieldState = null;
|
|
753
|
+
}
|
|
754
|
+
break;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
else {
|
|
758
|
+
if (fieldState === 'begin' || fieldState === 'instruction') {
|
|
759
|
+
fieldState = 'instruction';
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
else {
|
|
764
|
+
if (fieldRuns.length > 0) {
|
|
765
|
+
fieldRuns.forEach(run => groupedContent.push(run));
|
|
766
|
+
fieldRuns = [];
|
|
767
|
+
}
|
|
768
|
+
groupedContent.push(item);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
if (fieldRuns.length > 0) {
|
|
773
|
+
fieldRuns.forEach(run => groupedContent.push(run));
|
|
774
|
+
fieldRuns = [];
|
|
775
|
+
}
|
|
776
|
+
groupedContent.push(item);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (fieldRuns.length > 0) {
|
|
780
|
+
fieldRuns.forEach(run => groupedContent.push(run));
|
|
781
|
+
}
|
|
782
|
+
if ('replaceContent' in paragraph) {
|
|
783
|
+
paragraph.replaceContent(groupedContent);
|
|
784
|
+
}
|
|
785
|
+
else {
|
|
786
|
+
paragraph.clearContent();
|
|
787
|
+
for (const item of groupedContent) {
|
|
788
|
+
if (item instanceof Run_1.Run) {
|
|
789
|
+
paragraph.addRun(item);
|
|
790
|
+
}
|
|
791
|
+
else if (item instanceof Field_1.ComplexField) {
|
|
792
|
+
paragraph.addField(item);
|
|
793
|
+
}
|
|
794
|
+
else if (item instanceof Hyperlink_1.Hyperlink) {
|
|
795
|
+
paragraph.addHyperlink(item);
|
|
796
|
+
}
|
|
797
|
+
else {
|
|
798
|
+
paragraph.addRun(item);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
logger_1.defaultLogger.debug(`Assembled ${groupedContent.length - content.length} complex fields in paragraph`);
|
|
803
|
+
}
|
|
804
|
+
createComplexFieldFromRuns(fieldRuns) {
|
|
805
|
+
if (fieldRuns.length < 2) {
|
|
806
|
+
logger_1.defaultLogger.warn('Insufficient runs for ComplexField (minimum 2: begin and instr)');
|
|
807
|
+
return null;
|
|
808
|
+
}
|
|
809
|
+
let instruction = '';
|
|
810
|
+
let resultText = '';
|
|
811
|
+
let instructionFormatting;
|
|
812
|
+
let resultFormatting;
|
|
813
|
+
let hasBegin = false;
|
|
814
|
+
let hasEnd = false;
|
|
815
|
+
let hasSeparate = false;
|
|
816
|
+
for (const run of fieldRuns) {
|
|
817
|
+
const runContent = run.getContent();
|
|
818
|
+
const fieldCharToken = runContent.find((c) => c.type === 'fieldChar');
|
|
819
|
+
if (fieldCharToken) {
|
|
820
|
+
switch (fieldCharToken.fieldCharType) {
|
|
821
|
+
case 'begin':
|
|
822
|
+
hasBegin = true;
|
|
823
|
+
instructionFormatting = run.getFormatting();
|
|
824
|
+
break;
|
|
825
|
+
case 'separate':
|
|
826
|
+
hasSeparate = true;
|
|
827
|
+
break;
|
|
828
|
+
case 'end':
|
|
829
|
+
hasEnd = true;
|
|
830
|
+
break;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
const instrText = runContent.find((c) => c.type === 'instructionText');
|
|
834
|
+
if (instrText) {
|
|
835
|
+
instruction += instrText.value || '';
|
|
836
|
+
}
|
|
837
|
+
const textContent = runContent.find((c) => c.type === 'text');
|
|
838
|
+
if (textContent && hasSeparate) {
|
|
839
|
+
resultText += textContent.value || '';
|
|
840
|
+
resultFormatting = run.getFormatting();
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (!hasBegin || !hasEnd || !instruction.trim()) {
|
|
844
|
+
logger_1.defaultLogger.warn('Invalid ComplexField structure: missing begin/end or instruction');
|
|
845
|
+
return null;
|
|
846
|
+
}
|
|
847
|
+
instruction = instruction.trim();
|
|
848
|
+
logger_1.defaultLogger.debug(`Created ComplexField: ${instruction.substring(0, 50)}... (result: "${resultText}")`);
|
|
849
|
+
const properties = {
|
|
850
|
+
instruction,
|
|
851
|
+
result: resultText,
|
|
852
|
+
instructionFormatting,
|
|
853
|
+
resultFormatting,
|
|
854
|
+
multiParagraph: false,
|
|
855
|
+
};
|
|
856
|
+
return new Field_1.ComplexField(properties);
|
|
857
|
+
}
|
|
719
858
|
parseRunFromObject(runObj) {
|
|
720
859
|
try {
|
|
721
860
|
const content = [];
|
|
861
|
+
const toArray = (value) => Array.isArray(value) ? value : value !== undefined && value !== null ? [value] : [];
|
|
862
|
+
const extractTextValue = (node) => {
|
|
863
|
+
if (node === undefined || node === null) {
|
|
864
|
+
return '';
|
|
865
|
+
}
|
|
866
|
+
if (typeof node === 'object') {
|
|
867
|
+
return XMLBuilder_1.XMLBuilder.unescapeXml(node['#text'] || '');
|
|
868
|
+
}
|
|
869
|
+
return XMLBuilder_1.XMLBuilder.unescapeXml(String(node));
|
|
870
|
+
};
|
|
871
|
+
const parseBooleanAttr = (value) => {
|
|
872
|
+
if (value === undefined || value === null) {
|
|
873
|
+
return undefined;
|
|
874
|
+
}
|
|
875
|
+
return value === '1' || value === 1 || value === true || value === 'true';
|
|
876
|
+
};
|
|
722
877
|
if (runObj["_orderedChildren"]) {
|
|
723
878
|
for (const child of runObj["_orderedChildren"]) {
|
|
724
879
|
const elementType = child.type;
|
|
725
880
|
const elementIndex = child.index;
|
|
726
881
|
switch (elementType) {
|
|
727
882
|
case 'w:t': {
|
|
728
|
-
const textElements =
|
|
883
|
+
const textElements = toArray(runObj["w:t"]);
|
|
729
884
|
const te = textElements[elementIndex];
|
|
730
885
|
if (te !== undefined && te !== null) {
|
|
731
|
-
|
|
732
|
-
? (te["#text"] || "")
|
|
733
|
-
: (te || "");
|
|
734
|
-
text = XMLBuilder_1.XMLBuilder.unescapeXml(text);
|
|
886
|
+
const text = extractTextValue(te);
|
|
735
887
|
if (text) {
|
|
736
888
|
content.push({ type: 'text', value: text });
|
|
737
889
|
}
|
|
738
890
|
}
|
|
739
891
|
break;
|
|
740
892
|
}
|
|
893
|
+
case 'w:instrText': {
|
|
894
|
+
const instrElements = toArray(runObj['w:instrText']);
|
|
895
|
+
const instr = instrElements[elementIndex];
|
|
896
|
+
if (instr !== undefined && instr !== null) {
|
|
897
|
+
const text = extractTextValue(instr);
|
|
898
|
+
content.push({ type: 'instructionText', value: text });
|
|
899
|
+
}
|
|
900
|
+
break;
|
|
901
|
+
}
|
|
902
|
+
case 'w:fldChar': {
|
|
903
|
+
const fldChars = toArray(runObj['w:fldChar']);
|
|
904
|
+
const fldChar = fldChars[elementIndex];
|
|
905
|
+
if (fldChar && typeof fldChar === 'object') {
|
|
906
|
+
const charType = (fldChar['@_w:fldCharType'] || fldChar['@_fldCharType']);
|
|
907
|
+
if (charType) {
|
|
908
|
+
content.push({
|
|
909
|
+
type: 'fieldChar',
|
|
910
|
+
fieldCharType: charType,
|
|
911
|
+
fieldCharDirty: parseBooleanAttr(fldChar['@_w:dirty']),
|
|
912
|
+
fieldCharLocked: parseBooleanAttr(fldChar['@_w:fldLock'] ?? fldChar['@_w:lock']),
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
741
918
|
case 'w:tab':
|
|
742
919
|
content.push({ type: 'tab' });
|
|
743
920
|
break;
|
|
744
921
|
case 'w:br': {
|
|
745
|
-
const
|
|
922
|
+
const brElements = toArray(runObj['w:br']);
|
|
923
|
+
const brElement = brElements[elementIndex] || brElements[0];
|
|
746
924
|
const breakType = brElement?.['@_w:type'];
|
|
747
925
|
content.push({ type: 'break', breakType });
|
|
748
926
|
break;
|
|
@@ -764,17 +942,39 @@ class DocumentParser {
|
|
|
764
942
|
else {
|
|
765
943
|
const textElement = runObj["w:t"];
|
|
766
944
|
if (textElement !== undefined && textElement !== null) {
|
|
767
|
-
const textElements =
|
|
945
|
+
const textElements = toArray(textElement);
|
|
768
946
|
for (const te of textElements) {
|
|
769
|
-
|
|
770
|
-
? (te["#text"] || "")
|
|
771
|
-
: (te || "");
|
|
772
|
-
text = XMLBuilder_1.XMLBuilder.unescapeXml(text);
|
|
947
|
+
const text = extractTextValue(te);
|
|
773
948
|
if (text) {
|
|
774
949
|
content.push({ type: 'text', value: text });
|
|
775
950
|
}
|
|
776
951
|
}
|
|
777
952
|
}
|
|
953
|
+
const instrTextElement = runObj['w:instrText'];
|
|
954
|
+
if (instrTextElement !== undefined && instrTextElement !== null) {
|
|
955
|
+
const instrElements = toArray(instrTextElement);
|
|
956
|
+
for (const instr of instrElements) {
|
|
957
|
+
const text = extractTextValue(instr);
|
|
958
|
+
content.push({ type: 'instructionText', value: text });
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
const fldCharElement = runObj['w:fldChar'];
|
|
962
|
+
if (fldCharElement !== undefined && fldCharElement !== null) {
|
|
963
|
+
const fldChars = toArray(fldCharElement);
|
|
964
|
+
for (const fldChar of fldChars) {
|
|
965
|
+
if (fldChar && typeof fldChar === 'object') {
|
|
966
|
+
const charType = (fldChar['@_w:fldCharType'] || fldChar['@_fldCharType']);
|
|
967
|
+
if (charType) {
|
|
968
|
+
content.push({
|
|
969
|
+
type: 'fieldChar',
|
|
970
|
+
fieldCharType: charType,
|
|
971
|
+
fieldCharDirty: parseBooleanAttr(fldChar['@_w:dirty']),
|
|
972
|
+
fieldCharLocked: parseBooleanAttr(fldChar['@_w:fldLock'] ?? fldChar['@_w:lock']),
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
}
|
|
778
978
|
if (runObj["w:tab"] !== undefined) {
|
|
779
979
|
content.push({ type: 'tab' });
|
|
780
980
|
}
|