fix: Missing text property for patchDocument (#2760)

* fix: Missing text property

Ignore <br /> for patched files

* Fix spelling issues
This commit is contained in:
Dolan
2024-10-13 01:29:32 +01:00
committed by GitHub
parent 0cadec7f58
commit 2d2e4cdab2
7 changed files with 751 additions and 2 deletions

View File

@ -200,5 +200,454 @@ describe("replacer", () => {
expect(JSON.stringify(output)).to.contain("Lorem ipsum paragraph");
});
it("should replace", () => {
// cspell:disable
const output = replacer({
json: {
elements: [
{
type: "element",
name: "w:hdr",
elements: [
{
type: "element",
name: "w:p",
elements: [
{
type: "element",
name: "w:r",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rPr",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rFonts",
attributes: { "w:eastAsia": "Times New Roman" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:kern",
attributes: { "w:val": "0" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:sz",
attributes: { "w:val": "20" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:lang",
attributes: {
"w:val": "en-US",
"w:eastAsia": "en-US",
"w:bidi": "ar-SA",
},
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: "{{" }],
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:r",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rPr",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rFonts",
attributes: { "w:eastAsia": "Times New Roman" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:kern",
attributes: { "w:val": "0" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:sz",
attributes: { "w:val": "20" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:lang",
attributes: {
"w:val": "en-US",
"w:eastAsia": "en-US",
"w:bidi": "ar-SA",
},
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: "s" }],
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:r",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rPr",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rFonts",
attributes: { "w:eastAsia": "Times New Roman" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:kern",
attributes: { "w:val": "0" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:sz",
attributes: { "w:val": "20" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:lang",
attributes: {
"w:val": "en-US",
"w:eastAsia": "en-US",
"w:bidi": "ar-SA",
},
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: "chool_" }],
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:r",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rPr",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rFonts",
attributes: { "w:eastAsia": "Times New Roman" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:kern",
attributes: { "w:val": "0" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:sz",
attributes: { "w:val": "20" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:lang",
attributes: {
"w:val": "en-US",
"w:eastAsia": "en-US",
"w:bidi": "ar-SA",
},
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: "n" }],
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:r",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: "{{" }],
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:r",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rPr",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rFonts",
attributes: { "w:eastAsia": "Times New Roman" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:kern",
attributes: { "w:val": "0" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:sz",
attributes: { "w:val": "20" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:lang",
attributes: {
"w:val": "en-US",
"w:eastAsia": "en-US",
"w:bidi": "ar-SA",
},
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: "a" }],
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:r",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rPr",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rFonts",
attributes: { "w:eastAsia": "Times New Roman" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:kern",
attributes: { "w:val": "0" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:sz",
attributes: { "w:val": "20" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:lang",
attributes: {
"w:val": "en-US",
"w:eastAsia": "en-US",
"w:bidi": "ar-SA",
},
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: "ddr" }],
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:r",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rPr",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rFonts",
attributes: { "w:eastAsia": "Times New Roman" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:kern",
attributes: { "w:val": "0" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:sz",
attributes: { "w:val": "20" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:lang",
attributes: {
"w:val": "en-US",
"w:eastAsia": "en-US",
"w:bidi": "ar-SA",
},
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: "ess" }],
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:r",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rPr",
elements: [
{ type: "text", text: "\n " },
{
type: "element",
name: "w:rFonts",
attributes: { "w:eastAsia": "Times New Roman" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:kern",
attributes: { "w:val": "0" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:sz",
attributes: { "w:val": "20" },
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:lang",
attributes: {
"w:val": "en-US",
"w:eastAsia": "en-US",
"w:bidi": "ar-SA",
},
},
{ type: "text", text: "\n " },
],
},
{ type: "text", text: "\n " },
{
type: "element",
name: "w:t",
elements: [{ type: "text", text: "}}" }],
},
],
},
],
},
],
},
],
},
// cspell:enable
patch: {
type: PatchType.PARAGRAPH,
children: [new Paragraph("Lorem ipsum paragraph")],
},
patchText: "{{address}}",
context: {
file: {} as unknown as File,
viewWrapper: {
Relationships: {},
} as unknown as IViewWrapper,
stack: [],
},
});
expect(JSON.stringify(output)).to.contain("Lorem ipsum paragraph");
});
});
});