Fix style being missed on patchDocument

There were scenarios in which patching a document would result in loss
of style for the template runs and, possibly, their right-adjacent run
as well (post-splitting). That was due to the run style elements not
being added to the newly created runs.

This commit addresses this issue by introducing a new, optional, flag
for the `patchDocument` function: `keepOriginalStyles`. It defaults to
`false` (current behavior) and, when `true`, ensures that there is no
loss of styling.

This should address https://github.com/dolanmiu/docx/issues/2293.
This commit is contained in:
Wilk Maia
2023-10-18 12:58:01 -03:00
parent d5d80550e7
commit a89ee463e6
3 changed files with 134 additions and 2 deletions

View File

@ -49,6 +49,7 @@ export type IPatch = ParagraphPatch | FilePatch;
export interface PatchDocumentOptions {
readonly patches: { readonly [key: string]: IPatch };
readonly keepOriginalStyles?: boolean;
}
const imageReplacer = new ImageReplacer();
@ -128,6 +129,7 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
patchText,
renderedParagraphs,
context,
options.keepOriginalStyles,
);
}