I am using DocxTemplater library by edi9999 as a solution for creating .docx reports from template and JSON data, and I am happy with this.
However, now I have to highlight some words in my reports. For example, I need to substitute {contents}
with some large text, where few words are highlighted.
It means that I have 2 solutions here:
- Use some kind of markers inside of my data (like
in this data one {highlight(red)}{word} is red
, which are then interpreted by DocxTemplater. - Directly substitute tag with desired xml. For example, I substitute
{contents}
with this xml (stored in my JSON data as"contents"
field):<w:r> <w:rPr> <w:highlight w:val="cyan"/> </w:rPr> <w:t>lol</w:t> </w:r>
. If I do this now, I get my XML embedded in<w:r><w:t>HERE</w:t></w:r>
, so that MS Word thinks that file is corrupt.
For "raw" xml data I want to use some kind of special tag like {@myXmlData}
, which will prevent library from surrounding contents with <w:r><w:t></w:t></w:r>
.
I think that second solution is many ways superior and it is very flexible: it allows users to use DocxTemplater even if it doesn't satisfy some of their needs. They can just use XML for their very specific needs.
I think it is really great new feature for DocxTemplater library.
However, now I just want to solve my problem and I don't have time to thoroughly study or modify library's code.
It would be great if someone will point to places in library's code and ideas of how to easily extend it to add this feature.
EDIT: now this feature is supported! Check out https://github.com/edi9999/docxtemplater/issues/7