Allow for it to work with all xml files under word/
This commit is contained in:
@ -36,6 +36,16 @@ patchDocument(fs.readFileSync("demo/assets/simple-template.docx"), {
|
|||||||
children: [new Paragraph("Lorem ipsum paragraph"), new Paragraph("Another paragraph")],
|
children: [new Paragraph("Lorem ipsum paragraph"), new Paragraph("Another paragraph")],
|
||||||
text: "{{ paragraph_replace }}",
|
text: "{{ paragraph_replace }}",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: PatchType.PARAGRAPH,
|
||||||
|
children: [new TextRun("Delightful Header")],
|
||||||
|
text: "{{ header_adjective }}",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: PatchType.PARAGRAPH,
|
||||||
|
children: [new TextRun("replaced just as well")],
|
||||||
|
text: "{{ footer_text }}",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: PatchType.DOCUMENT,
|
type: PatchType.DOCUMENT,
|
||||||
children: [
|
children: [
|
||||||
|
Binary file not shown.
@ -41,7 +41,7 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
|
|||||||
|
|
||||||
for (const [key, value] of Object.entries(zipContent.files)) {
|
for (const [key, value] of Object.entries(zipContent.files)) {
|
||||||
const json = toJson(await value.async("text"));
|
const json = toJson(await value.async("text"));
|
||||||
if (key === "word/document.xml") {
|
if (key.startsWith("word/")) {
|
||||||
for (const patch of options.patches) {
|
for (const patch of options.patches) {
|
||||||
const renderedParagraphs = findLocationOfText(json, patch.text);
|
const renderedParagraphs = findLocationOfText(json, patch.text);
|
||||||
replacer(json, patch, renderedParagraphs);
|
replacer(json, patch, renderedParagraphs);
|
||||||
|
Reference in New Issue
Block a user