@json-to-office/core-docx 0.25.0 → 0.26.1
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/index.js +79 -119
- package/dist/index.js.map +1 -1
- package/dist/plugin/example/index.js +79 -119
- package/dist/plugin/example/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/placeholderProcessor.d.ts.map +1 -1
- package/dist/utils/textParser.d.ts +37 -0
- package/dist/utils/textParser.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3686,8 +3686,7 @@ function normalizeUnicodeText(text) {
|
|
|
3686
3686
|
// src/utils/placeholderProcessor.ts
|
|
3687
3687
|
import {
|
|
3688
3688
|
TextRun as TextRun2,
|
|
3689
|
-
PageNumber
|
|
3690
|
-
Tab as Tab2
|
|
3689
|
+
PageNumber
|
|
3691
3690
|
} from "docx";
|
|
3692
3691
|
|
|
3693
3692
|
// src/utils/textParser.ts
|
|
@@ -3794,74 +3793,90 @@ function parseTextWithDecorators(text, baseStyle = {}, options = {}) {
|
|
|
3794
3793
|
}
|
|
3795
3794
|
return runs;
|
|
3796
3795
|
}
|
|
3797
|
-
function
|
|
3796
|
+
function buildRunCommonProps(baseStyle, overrides) {
|
|
3797
|
+
const bold = overrides?.bold ?? baseStyle.bold;
|
|
3798
|
+
const italics = overrides?.italics ?? baseStyle.italics;
|
|
3799
|
+
return {
|
|
3800
|
+
...baseStyle.font && { font: baseStyle.font },
|
|
3801
|
+
...baseStyle.size && { size: baseStyle.size },
|
|
3802
|
+
...baseStyle.color && {
|
|
3803
|
+
color: bold && overrides?.boldColor ? overrides.boldColor : baseStyle.color
|
|
3804
|
+
},
|
|
3805
|
+
...bold !== void 0 && { bold },
|
|
3806
|
+
...italics !== void 0 && { italics },
|
|
3807
|
+
...baseStyle.underline && { underline: baseStyle.underline },
|
|
3808
|
+
...baseStyle.scale && { scale: baseStyle.scale },
|
|
3809
|
+
...baseStyle.characterSpacing && {
|
|
3810
|
+
characterSpacing: baseStyle.characterSpacing
|
|
3811
|
+
},
|
|
3812
|
+
...baseStyle.language && { language: baseStyle.language }
|
|
3813
|
+
};
|
|
3814
|
+
}
|
|
3815
|
+
function buildLineRuns(line, commonProps, opts) {
|
|
3816
|
+
const { needsLineBreak, noProof } = opts;
|
|
3817
|
+
const wholeRunNoProof = noProof === true;
|
|
3818
|
+
const wordsForLine = wholeRunNoProof ? void 0 : opts.noProofWords;
|
|
3819
|
+
let firstSegment = true;
|
|
3820
|
+
const lineRuns = [];
|
|
3821
|
+
const tabSegments = line.split(" ");
|
|
3822
|
+
tabSegments.forEach((tabSegment, tabIndex) => {
|
|
3823
|
+
if (tabIndex > 0) {
|
|
3824
|
+
lineRuns.push(
|
|
3825
|
+
new TextRun({
|
|
3826
|
+
children: [new Tab()],
|
|
3827
|
+
...commonProps,
|
|
3828
|
+
...needsLineBreak && firstSegment && { break: 1 }
|
|
3829
|
+
})
|
|
3830
|
+
);
|
|
3831
|
+
firstSegment = false;
|
|
3832
|
+
}
|
|
3833
|
+
if (!tabSegment && tabSegments.length > 1) return;
|
|
3834
|
+
lineRuns.push(
|
|
3835
|
+
...splitByNoProofWords(
|
|
3836
|
+
tabSegment,
|
|
3837
|
+
(segment, matched) => {
|
|
3838
|
+
const run = new TextRun({
|
|
3839
|
+
text: segment,
|
|
3840
|
+
...commonProps,
|
|
3841
|
+
...(matched || noProof !== void 0) && {
|
|
3842
|
+
noProof: matched || wholeRunNoProof
|
|
3843
|
+
},
|
|
3844
|
+
...needsLineBreak && firstSegment && { break: 1 }
|
|
3845
|
+
});
|
|
3846
|
+
firstSegment = false;
|
|
3847
|
+
return run;
|
|
3848
|
+
},
|
|
3849
|
+
wordsForLine
|
|
3850
|
+
)
|
|
3851
|
+
);
|
|
3852
|
+
});
|
|
3853
|
+
return lineRuns;
|
|
3854
|
+
}
|
|
3855
|
+
function buildTextRuns(text, commonProps, opts = {}) {
|
|
3798
3856
|
const runs = [];
|
|
3799
3857
|
const lines = text.split("\n");
|
|
3800
3858
|
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
3801
3859
|
const line = lines[lineIndex];
|
|
3802
3860
|
const needsLineBreak = lineIndex > 0;
|
|
3803
3861
|
if (line || needsLineBreak) {
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
};
|
|
3808
|
-
const commonProps = {
|
|
3809
|
-
...baseStyle.font && { font: baseStyle.font },
|
|
3810
|
-
...baseStyle.size && { size: baseStyle.size },
|
|
3811
|
-
...baseStyle.color && {
|
|
3812
|
-
color: runStyle.bold && options.boldColor ? options.boldColor : baseStyle.color
|
|
3813
|
-
},
|
|
3814
|
-
...runStyle.bold !== void 0 && { bold: runStyle.bold },
|
|
3815
|
-
...runStyle.italics !== void 0 && { italics: runStyle.italics },
|
|
3816
|
-
...baseStyle.underline && { underline: baseStyle.underline },
|
|
3817
|
-
...baseStyle.scale && { scale: baseStyle.scale },
|
|
3818
|
-
...baseStyle.characterSpacing && {
|
|
3819
|
-
characterSpacing: baseStyle.characterSpacing
|
|
3820
|
-
},
|
|
3821
|
-
...baseStyle.language && { language: baseStyle.language }
|
|
3822
|
-
};
|
|
3823
|
-
const wholeRunNoProof = baseStyle.noProof === true;
|
|
3824
|
-
const wordsForLine = wholeRunNoProof ? void 0 : options.noProofWords;
|
|
3825
|
-
let firstSegment = true;
|
|
3826
|
-
const lineRuns = [];
|
|
3827
|
-
const tabSegments = line.split(" ");
|
|
3828
|
-
tabSegments.forEach((tabSegment, tabIndex) => {
|
|
3829
|
-
if (tabIndex > 0) {
|
|
3830
|
-
lineRuns.push(
|
|
3831
|
-
new TextRun({
|
|
3832
|
-
children: [new Tab()],
|
|
3833
|
-
...commonProps,
|
|
3834
|
-
...needsLineBreak && firstSegment && { break: 1 }
|
|
3835
|
-
})
|
|
3836
|
-
);
|
|
3837
|
-
firstSegment = false;
|
|
3838
|
-
}
|
|
3839
|
-
if (!tabSegment && tabSegments.length > 1) return;
|
|
3840
|
-
lineRuns.push(
|
|
3841
|
-
...splitByNoProofWords(
|
|
3842
|
-
tabSegment,
|
|
3843
|
-
(segment, matched) => {
|
|
3844
|
-
const segNoProof = matched || wholeRunNoProof;
|
|
3845
|
-
const run = new TextRun({
|
|
3846
|
-
text: segment,
|
|
3847
|
-
...commonProps,
|
|
3848
|
-
...(matched || baseStyle.noProof !== void 0) && {
|
|
3849
|
-
noProof: segNoProof
|
|
3850
|
-
},
|
|
3851
|
-
...needsLineBreak && firstSegment && { break: 1 }
|
|
3852
|
-
});
|
|
3853
|
-
firstSegment = false;
|
|
3854
|
-
return run;
|
|
3855
|
-
},
|
|
3856
|
-
wordsForLine
|
|
3857
|
-
)
|
|
3858
|
-
);
|
|
3859
|
-
});
|
|
3860
|
-
runs.push(...lineRuns);
|
|
3862
|
+
runs.push(
|
|
3863
|
+
...buildLineRuns(line, commonProps, { needsLineBreak, ...opts })
|
|
3864
|
+
);
|
|
3861
3865
|
}
|
|
3862
3866
|
}
|
|
3863
3867
|
return runs;
|
|
3864
3868
|
}
|
|
3869
|
+
function createTextRunsWithNewlines(text, baseStyle, options, overrideStyle) {
|
|
3870
|
+
return buildTextRuns(
|
|
3871
|
+
text,
|
|
3872
|
+
buildRunCommonProps(baseStyle, {
|
|
3873
|
+
bold: overrideStyle?.bold,
|
|
3874
|
+
italics: overrideStyle?.italics,
|
|
3875
|
+
boldColor: options.boldColor
|
|
3876
|
+
}),
|
|
3877
|
+
{ noProof: baseStyle.noProof, noProofWords: options.noProofWords }
|
|
3878
|
+
);
|
|
3879
|
+
}
|
|
3865
3880
|
function parseTextWithHyperlinks(text, baseStyle = {}, options = {}) {
|
|
3866
3881
|
const normalizedText = normalizeUnicodeText(text);
|
|
3867
3882
|
const runs = [];
|
|
@@ -4078,65 +4093,10 @@ function processTextWithPlaceholders(text, baseStyle = {}, context = {}, noProof
|
|
|
4078
4093
|
return result;
|
|
4079
4094
|
}
|
|
4080
4095
|
function createTextRunsWithNewlines2(text, baseStyle, noProofWords) {
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
const needsLineBreak = lineIndex > 0;
|
|
4086
|
-
if (line || needsLineBreak) {
|
|
4087
|
-
const commonProps = {
|
|
4088
|
-
font: baseStyle.font,
|
|
4089
|
-
size: baseStyle.size,
|
|
4090
|
-
color: baseStyle.color,
|
|
4091
|
-
bold: baseStyle.bold,
|
|
4092
|
-
italics: baseStyle.italics,
|
|
4093
|
-
underline: baseStyle.underline,
|
|
4094
|
-
...baseStyle.scale && { scale: baseStyle.scale },
|
|
4095
|
-
...baseStyle.characterSpacing && {
|
|
4096
|
-
characterSpacing: baseStyle.characterSpacing
|
|
4097
|
-
},
|
|
4098
|
-
...baseStyle.language && { language: baseStyle.language }
|
|
4099
|
-
};
|
|
4100
|
-
const wholeRunNoProof = baseStyle.noProof === true;
|
|
4101
|
-
const wordsForLine = wholeRunNoProof ? void 0 : noProofWords;
|
|
4102
|
-
let firstSegment = true;
|
|
4103
|
-
const lineRuns = [];
|
|
4104
|
-
const tabSegments = line.split(" ");
|
|
4105
|
-
tabSegments.forEach((tabSegment, tabIndex) => {
|
|
4106
|
-
if (tabIndex > 0) {
|
|
4107
|
-
lineRuns.push(
|
|
4108
|
-
new TextRun2({
|
|
4109
|
-
children: [new Tab2()],
|
|
4110
|
-
...commonProps,
|
|
4111
|
-
break: needsLineBreak && firstSegment ? 1 : void 0
|
|
4112
|
-
})
|
|
4113
|
-
);
|
|
4114
|
-
firstSegment = false;
|
|
4115
|
-
}
|
|
4116
|
-
if (!tabSegment && tabSegments.length > 1) return;
|
|
4117
|
-
lineRuns.push(
|
|
4118
|
-
...splitByNoProofWords(
|
|
4119
|
-
tabSegment,
|
|
4120
|
-
(segment, matched) => {
|
|
4121
|
-
const run = new TextRun2({
|
|
4122
|
-
text: segment,
|
|
4123
|
-
...commonProps,
|
|
4124
|
-
...(matched || baseStyle.noProof !== void 0) && {
|
|
4125
|
-
noProof: matched || wholeRunNoProof
|
|
4126
|
-
},
|
|
4127
|
-
break: needsLineBreak && firstSegment ? 1 : void 0
|
|
4128
|
-
});
|
|
4129
|
-
firstSegment = false;
|
|
4130
|
-
return run;
|
|
4131
|
-
},
|
|
4132
|
-
wordsForLine
|
|
4133
|
-
)
|
|
4134
|
-
);
|
|
4135
|
-
});
|
|
4136
|
-
runs.push(...lineRuns);
|
|
4137
|
-
}
|
|
4138
|
-
}
|
|
4139
|
-
return runs;
|
|
4096
|
+
return buildTextRuns(text, buildRunCommonProps(baseStyle), {
|
|
4097
|
+
noProof: baseStyle.noProof,
|
|
4098
|
+
noProofWords
|
|
4099
|
+
});
|
|
4140
4100
|
}
|
|
4141
4101
|
function initializeBuiltinPlaceholders() {
|
|
4142
4102
|
PlaceholderRegistry.register("PAGE", (context) => {
|