Skip to content

Commit 64961d8

Browse files
author
Arthur Marx
committed
feat(patcher): Add ability to provide patching pattern
1 parent b1f6765 commit 64961d8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/patcher/from-docx.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,17 @@ export type IPatch = ParagraphPatch | FilePatch;
5050

5151
export type PatchDocumentOutputType = OutputType;
5252

53+
export type PatchDocumentPatternOption = {
54+
readonly start: string
55+
readonly end: string
56+
}
57+
5358
export type PatchDocumentOptions<T extends PatchDocumentOutputType = PatchDocumentOutputType> = {
5459
readonly outputType: T;
5560
readonly data: InputDataType;
5661
readonly patches: Readonly<Record<string, IPatch>>;
5762
readonly keepOriginalStyles?: boolean;
63+
readonly pattern?: PatchDocumentPatternOption;
5864
};
5965

6066
const imageReplacer = new ImageReplacer();
@@ -64,6 +70,7 @@ export const patchDocument = async <T extends PatchDocumentOutputType = PatchDoc
6470
data,
6571
patches,
6672
keepOriginalStyles,
73+
pattern
6774
}: PatchDocumentOptions<T>): Promise<OutputByType[T]> => {
6875
const zipContent = await JSZip.loadAsync(data);
6976
const contexts = new Map<string, IContext>();
@@ -133,7 +140,7 @@ export const patchDocument = async <T extends PatchDocumentOutputType = PatchDoc
133140
contexts.set(key, context);
134141

135142
for (const [patchKey, patchValue] of Object.entries(patches)) {
136-
const patchText = `{{${patchKey}}}`;
143+
const patchText = `${pattern?.start || '{{'}${patchKey}${pattern?.end || '}}'}`;
137144
// TODO: mutates json. Make it immutable
138145
// We need to loop through to catch every occurrence of the patch text
139146
// It is possible that the patch text is in the same run

0 commit comments

Comments
 (0)