@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
|
@@ -3855,8 +3855,7 @@ function normalizeUnicodeText(text) {
|
|
|
3855
3855
|
// src/utils/placeholderProcessor.ts
|
|
3856
3856
|
import {
|
|
3857
3857
|
TextRun as TextRun2,
|
|
3858
|
-
PageNumber
|
|
3859
|
-
Tab as Tab2
|
|
3858
|
+
PageNumber
|
|
3860
3859
|
} from "docx";
|
|
3861
3860
|
|
|
3862
3861
|
// src/utils/textParser.ts
|
|
@@ -3963,74 +3962,90 @@ function parseTextWithDecorators(text, baseStyle = {}, options = {}) {
|
|
|
3963
3962
|
}
|
|
3964
3963
|
return runs;
|
|
3965
3964
|
}
|
|
3966
|
-
function
|
|
3965
|
+
function buildRunCommonProps(baseStyle, overrides) {
|
|
3966
|
+
const bold = overrides?.bold ?? baseStyle.bold;
|
|
3967
|
+
const italics = overrides?.italics ?? baseStyle.italics;
|
|
3968
|
+
return {
|
|
3969
|
+
...baseStyle.font && { font: baseStyle.font },
|
|
3970
|
+
...baseStyle.size && { size: baseStyle.size },
|
|
3971
|
+
...baseStyle.color && {
|
|
3972
|
+
color: bold && overrides?.boldColor ? overrides.boldColor : baseStyle.color
|
|
3973
|
+
},
|
|
3974
|
+
...bold !== void 0 && { bold },
|
|
3975
|
+
...italics !== void 0 && { italics },
|
|
3976
|
+
...baseStyle.underline && { underline: baseStyle.underline },
|
|
3977
|
+
...baseStyle.scale && { scale: baseStyle.scale },
|
|
3978
|
+
...baseStyle.characterSpacing && {
|
|
3979
|
+
characterSpacing: baseStyle.characterSpacing
|
|
3980
|
+
},
|
|
3981
|
+
...baseStyle.language && { language: baseStyle.language }
|
|
3982
|
+
};
|
|
3983
|
+
}
|
|
3984
|
+
function buildLineRuns(line, commonProps, opts) {
|
|
3985
|
+
const { needsLineBreak, noProof } = opts;
|
|
3986
|
+
const wholeRunNoProof = noProof === true;
|
|
3987
|
+
const wordsForLine = wholeRunNoProof ? void 0 : opts.noProofWords;
|
|
3988
|
+
let firstSegment = true;
|
|
3989
|
+
const lineRuns = [];
|
|
3990
|
+
const tabSegments = line.split(" ");
|
|
3991
|
+
tabSegments.forEach((tabSegment, tabIndex) => {
|
|
3992
|
+
if (tabIndex > 0) {
|
|
3993
|
+
lineRuns.push(
|
|
3994
|
+
new TextRun({
|
|
3995
|
+
children: [new Tab()],
|
|
3996
|
+
...commonProps,
|
|
3997
|
+
...needsLineBreak && firstSegment && { break: 1 }
|
|
3998
|
+
})
|
|
3999
|
+
);
|
|
4000
|
+
firstSegment = false;
|
|
4001
|
+
}
|
|
4002
|
+
if (!tabSegment && tabSegments.length > 1) return;
|
|
4003
|
+
lineRuns.push(
|
|
4004
|
+
...splitByNoProofWords(
|
|
4005
|
+
tabSegment,
|
|
4006
|
+
(segment, matched) => {
|
|
4007
|
+
const run = new TextRun({
|
|
4008
|
+
text: segment,
|
|
4009
|
+
...commonProps,
|
|
4010
|
+
...(matched || noProof !== void 0) && {
|
|
4011
|
+
noProof: matched || wholeRunNoProof
|
|
4012
|
+
},
|
|
4013
|
+
...needsLineBreak && firstSegment && { break: 1 }
|
|
4014
|
+
});
|
|
4015
|
+
firstSegment = false;
|
|
4016
|
+
return run;
|
|
4017
|
+
},
|
|
4018
|
+
wordsForLine
|
|
4019
|
+
)
|
|
4020
|
+
);
|
|
4021
|
+
});
|
|
4022
|
+
return lineRuns;
|
|
4023
|
+
}
|
|
4024
|
+
function buildTextRuns(text, commonProps, opts = {}) {
|
|
3967
4025
|
const runs = [];
|
|
3968
4026
|
const lines = text.split("\n");
|
|
3969
4027
|
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
3970
4028
|
const line = lines[lineIndex];
|
|
3971
4029
|
const needsLineBreak = lineIndex > 0;
|
|
3972
4030
|
if (line || needsLineBreak) {
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
};
|
|
3977
|
-
const commonProps = {
|
|
3978
|
-
...baseStyle.font && { font: baseStyle.font },
|
|
3979
|
-
...baseStyle.size && { size: baseStyle.size },
|
|
3980
|
-
...baseStyle.color && {
|
|
3981
|
-
color: runStyle.bold && options.boldColor ? options.boldColor : baseStyle.color
|
|
3982
|
-
},
|
|
3983
|
-
...runStyle.bold !== void 0 && { bold: runStyle.bold },
|
|
3984
|
-
...runStyle.italics !== void 0 && { italics: runStyle.italics },
|
|
3985
|
-
...baseStyle.underline && { underline: baseStyle.underline },
|
|
3986
|
-
...baseStyle.scale && { scale: baseStyle.scale },
|
|
3987
|
-
...baseStyle.characterSpacing && {
|
|
3988
|
-
characterSpacing: baseStyle.characterSpacing
|
|
3989
|
-
},
|
|
3990
|
-
...baseStyle.language && { language: baseStyle.language }
|
|
3991
|
-
};
|
|
3992
|
-
const wholeRunNoProof = baseStyle.noProof === true;
|
|
3993
|
-
const wordsForLine = wholeRunNoProof ? void 0 : options.noProofWords;
|
|
3994
|
-
let firstSegment = true;
|
|
3995
|
-
const lineRuns = [];
|
|
3996
|
-
const tabSegments = line.split(" ");
|
|
3997
|
-
tabSegments.forEach((tabSegment, tabIndex) => {
|
|
3998
|
-
if (tabIndex > 0) {
|
|
3999
|
-
lineRuns.push(
|
|
4000
|
-
new TextRun({
|
|
4001
|
-
children: [new Tab()],
|
|
4002
|
-
...commonProps,
|
|
4003
|
-
...needsLineBreak && firstSegment && { break: 1 }
|
|
4004
|
-
})
|
|
4005
|
-
);
|
|
4006
|
-
firstSegment = false;
|
|
4007
|
-
}
|
|
4008
|
-
if (!tabSegment && tabSegments.length > 1) return;
|
|
4009
|
-
lineRuns.push(
|
|
4010
|
-
...splitByNoProofWords(
|
|
4011
|
-
tabSegment,
|
|
4012
|
-
(segment, matched) => {
|
|
4013
|
-
const segNoProof = matched || wholeRunNoProof;
|
|
4014
|
-
const run = new TextRun({
|
|
4015
|
-
text: segment,
|
|
4016
|
-
...commonProps,
|
|
4017
|
-
...(matched || baseStyle.noProof !== void 0) && {
|
|
4018
|
-
noProof: segNoProof
|
|
4019
|
-
},
|
|
4020
|
-
...needsLineBreak && firstSegment && { break: 1 }
|
|
4021
|
-
});
|
|
4022
|
-
firstSegment = false;
|
|
4023
|
-
return run;
|
|
4024
|
-
},
|
|
4025
|
-
wordsForLine
|
|
4026
|
-
)
|
|
4027
|
-
);
|
|
4028
|
-
});
|
|
4029
|
-
runs.push(...lineRuns);
|
|
4031
|
+
runs.push(
|
|
4032
|
+
...buildLineRuns(line, commonProps, { needsLineBreak, ...opts })
|
|
4033
|
+
);
|
|
4030
4034
|
}
|
|
4031
4035
|
}
|
|
4032
4036
|
return runs;
|
|
4033
4037
|
}
|
|
4038
|
+
function createTextRunsWithNewlines(text, baseStyle, options, overrideStyle) {
|
|
4039
|
+
return buildTextRuns(
|
|
4040
|
+
text,
|
|
4041
|
+
buildRunCommonProps(baseStyle, {
|
|
4042
|
+
bold: overrideStyle?.bold,
|
|
4043
|
+
italics: overrideStyle?.italics,
|
|
4044
|
+
boldColor: options.boldColor
|
|
4045
|
+
}),
|
|
4046
|
+
{ noProof: baseStyle.noProof, noProofWords: options.noProofWords }
|
|
4047
|
+
);
|
|
4048
|
+
}
|
|
4034
4049
|
function parseTextWithHyperlinks(text, baseStyle = {}, options = {}) {
|
|
4035
4050
|
const normalizedText = normalizeUnicodeText(text);
|
|
4036
4051
|
const runs = [];
|
|
@@ -4247,65 +4262,10 @@ function processTextWithPlaceholders(text, baseStyle = {}, context = {}, noProof
|
|
|
4247
4262
|
return result;
|
|
4248
4263
|
}
|
|
4249
4264
|
function createTextRunsWithNewlines2(text, baseStyle, noProofWords) {
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
const needsLineBreak = lineIndex > 0;
|
|
4255
|
-
if (line || needsLineBreak) {
|
|
4256
|
-
const commonProps = {
|
|
4257
|
-
font: baseStyle.font,
|
|
4258
|
-
size: baseStyle.size,
|
|
4259
|
-
color: baseStyle.color,
|
|
4260
|
-
bold: baseStyle.bold,
|
|
4261
|
-
italics: baseStyle.italics,
|
|
4262
|
-
underline: baseStyle.underline,
|
|
4263
|
-
...baseStyle.scale && { scale: baseStyle.scale },
|
|
4264
|
-
...baseStyle.characterSpacing && {
|
|
4265
|
-
characterSpacing: baseStyle.characterSpacing
|
|
4266
|
-
},
|
|
4267
|
-
...baseStyle.language && { language: baseStyle.language }
|
|
4268
|
-
};
|
|
4269
|
-
const wholeRunNoProof = baseStyle.noProof === true;
|
|
4270
|
-
const wordsForLine = wholeRunNoProof ? void 0 : noProofWords;
|
|
4271
|
-
let firstSegment = true;
|
|
4272
|
-
const lineRuns = [];
|
|
4273
|
-
const tabSegments = line.split(" ");
|
|
4274
|
-
tabSegments.forEach((tabSegment, tabIndex) => {
|
|
4275
|
-
if (tabIndex > 0) {
|
|
4276
|
-
lineRuns.push(
|
|
4277
|
-
new TextRun2({
|
|
4278
|
-
children: [new Tab2()],
|
|
4279
|
-
...commonProps,
|
|
4280
|
-
break: needsLineBreak && firstSegment ? 1 : void 0
|
|
4281
|
-
})
|
|
4282
|
-
);
|
|
4283
|
-
firstSegment = false;
|
|
4284
|
-
}
|
|
4285
|
-
if (!tabSegment && tabSegments.length > 1) return;
|
|
4286
|
-
lineRuns.push(
|
|
4287
|
-
...splitByNoProofWords(
|
|
4288
|
-
tabSegment,
|
|
4289
|
-
(segment, matched) => {
|
|
4290
|
-
const run = new TextRun2({
|
|
4291
|
-
text: segment,
|
|
4292
|
-
...commonProps,
|
|
4293
|
-
...(matched || baseStyle.noProof !== void 0) && {
|
|
4294
|
-
noProof: matched || wholeRunNoProof
|
|
4295
|
-
},
|
|
4296
|
-
break: needsLineBreak && firstSegment ? 1 : void 0
|
|
4297
|
-
});
|
|
4298
|
-
firstSegment = false;
|
|
4299
|
-
return run;
|
|
4300
|
-
},
|
|
4301
|
-
wordsForLine
|
|
4302
|
-
)
|
|
4303
|
-
);
|
|
4304
|
-
});
|
|
4305
|
-
runs.push(...lineRuns);
|
|
4306
|
-
}
|
|
4307
|
-
}
|
|
4308
|
-
return runs;
|
|
4265
|
+
return buildTextRuns(text, buildRunCommonProps(baseStyle), {
|
|
4266
|
+
noProof: baseStyle.noProof,
|
|
4267
|
+
noProofWords
|
|
4268
|
+
});
|
|
4309
4269
|
}
|
|
4310
4270
|
function initializeBuiltinPlaceholders() {
|
|
4311
4271
|
PlaceholderRegistry.register("PAGE", (context) => {
|