From dece0f58e151360936235a5bdf4e4902c7486c6e Mon Sep 17 00:00:00 2001 From: SebKranz <33868262+SebKranz@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:19:25 +0100 Subject: [PATCH] Fix duplicated br tags (#2717) * Adjust test to demo duplicated br tags * Fix patchDocument duplicating br tags * Only include w:Pr * Fix tag condition --------- Co-authored-by: Dolan --- src/patcher/replacer.spec.ts | 8 ++++++++ src/patcher/replacer.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/patcher/replacer.spec.ts b/src/patcher/replacer.spec.ts index f1e9650fcc..5b56cace6e 100644 --- a/src/patcher/replacer.spec.ts +++ b/src/patcher/replacer.spec.ts @@ -62,6 +62,10 @@ export const MOCK_JSON = { name: "w:t", elements: [{ type: "text", text: "What a {{bold}} text!" }], }, + { + type: "element", + name: "w:br", + }, ], }, ], @@ -176,6 +180,10 @@ describe("replacer", () => { name: "w:t", elements: [{ type: "text", text: " text!" }], }, + { + name: "w:br", + type: "element", + }, ], }, ]); diff --git a/src/patcher/replacer.ts b/src/patcher/replacer.ts index ba4dc4334a..49b206db3d 100644 --- a/src/patcher/replacer.ts +++ b/src/patcher/replacer.ts @@ -64,7 +64,7 @@ export const replacer = ({ if (keepOriginalStyles) { const runElementNonTextualElements = runElementToBeReplaced.elements!.filter( - (e) => e.type === "element" && e.name !== "w:t" && e.name !== "w:br" && e.name !== "w:tab", + (e) => e.type === "element" && e.name === "w:rPr", ); newRunElements = textJson.map((e) => ({