guigrpa / docx-templates

Template-based docx report creation
MIT License
882 stars 145 forks source link

Preprocessing of docx template? #359

Closed koosvanderkolk closed 5 months ago

koosvanderkolk commented 6 months ago

My use case is that I would like to let 'less technical' end-users create their own templates.

E.g. let them create

image

Which should then be converted to:

image

I also have quite some variables which contain HTML. For those, I want the end-user to just add

image

Which should then be converted to

image

So the feature request would be to have a preprocess function, in which I can alter the template before it is being interpreted.

jjhbw commented 5 months ago

I don't think it is wise to implement this in docx-templates, as that would add yet another layer of configuration and complexity.

You can probably do 90% of what you want by using a custom runJs function. See e.g. https://github.com/guigrpa/docx-templates/blob/5ad3cfd40866961a99a3772b07ad1cdea8b9b23c/examples/example-vm2/index.js#L40