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:
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user