Skip to content

Commit 5a093c2

Browse files
Vladimir Bulygadolanmiu
Vladimir Bulyga
authored andcommitted
fix: patching goes on the second circle over patched document
added parameter `recursive`(= true by default) to be able to disable this behavior
1 parent f772b2c commit 5a093c2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/patcher/from-docx.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export type PatchDocumentOptions<T extends PatchDocumentOutputType = PatchDocume
5959
readonly start: string;
6060
readonly end: string;
6161
}>;
62+
readonly recursive?: boolean;
6263
};
6364

6465
const imageReplacer = new ImageReplacer();
@@ -71,6 +72,10 @@ export const patchDocument = async <T extends PatchDocumentOutputType = PatchDoc
7172
patches,
7273
keepOriginalStyles,
7374
placeholderDelimiters = { start: "{{", end: "}}" } as const,
75+
/**
76+
* Search for occurrences over patched document
77+
*/
78+
recursive = true,
7479
}: PatchDocumentOptions<T>): Promise<OutputByType[T]> => {
7580
const zipContent = data instanceof JSZip ? data : await JSZip.loadAsync(data);
7681
const contexts = new Map<string, IContext>();
@@ -188,7 +193,8 @@ export const patchDocument = async <T extends PatchDocumentOutputType = PatchDoc
188193
context,
189194
keepOriginalStyles,
190195
});
191-
if (!didFindOccurrence) {
196+
// What the reason doing that? Once document is patched - it search over patched json again, that takes too long if patched document has big and deep structure.
197+
if (!recursive || !didFindOccurrence) {
192198
break;
193199
}
194200
}

0 commit comments

Comments
 (0)