-
-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impossible to multiple patches of a key in a same paragraph #2267
Comments
I'm using this fix but I'm not really proud of it 🥲 const patchTheDocument = async (data: Buffer) => await patchDocument(data, {
patches: {
company_name: {
children: [new TextRun('MY_COMPANY')],
type: PatchType.PARAGRAPH,
},
},
})
// Patch the document a first time:
let patchedDocxTemplate = await patchTheDocument(baseDocxTemplate)
// Patch the document 10 times to avoid the case where multiple same keys are in the template (not patched), see https://github.com/dolanmiu/docx/issues/2267
for (let i = 0; i < 10; i++) {
patchedDocxTemplate = await patchTheDocument(Buffer.from(patchedDocxTemplate))
} |
* Turn patch document into options object Add outputType to options * Set keep styles to true by default * Simplify method * Rename variable * #2267 Multiple patches of same key * Remove path which won't be visited
Im still having the same issue when the same word to be patched is multiple times in the same paragraph, using your fix worked but is there a better solution now? |
I'm also running into this 🤔 |
I don't really understand why my issue was closed.. 😞 |
Ok @Suniron I'm going to attempt to debug this issue and provide a solution – if possible. Don't know when I'll be able to find the time to familiarise myself with the codebase but, yeah. It's the "open source thing" to do in this situation. Very happy to contribute! If I'm able to solve it. To state the obvious: I guess it's a logical issue where subsequent occurrences of a If we put our minds together at some point, we really should be able to get to the bottom of this. |
Thanks @carlgleisner If you need any help im down, I also really want this fixed :) |
I started looking into this, I am pretty sure it has already been fixed lol. I think this is the problem #2605 It isnt released in the latest npm version. When I cloned the project and started running some tests it was actually working and replacing all patches in the same paragraph. |
This makes a lot of sense 🙂 Amazing library – would have loved to contribute! I guess new opportunities will present themselves. |
Hey there!
I can't do multiple patches of the same key in one sentence.
For example, in the following text, only the first key will be patched:
I'm using the code above to patch my docx files:
The text was updated successfully, but these errors were encountered: