docxRaw helper
-
Inspired by https://github.com/jsreport/jsreport/issues/713, here's a
docxRaw
helper that allows to insert raw dynamic content:function docxRaw(d) { return new Handlebars.SafeString(d) }
Can then be used in docx template as:
{{docxRaw mydata}}
With sample data:
{ "mydata": "<w:r><w:rPr><w:color w:val=\"FF0000\"/></w:rPr><w:t>Red</w:t></w:r>"}
-
Thank you for sharing.
Maybe just{{{myData}}}
would work for you the same? The triple brackets avoid escaping in the Handlebars templating engine.
-
Indeed, it does work the same :facepalm:. Thanks!
-
Turns out this way of doing is not compatible with every docx editor, e.g. Word Online displays a broken table and Libreoffice drops the <w:r> tag altogether as it is in a <w:t>.
I've submitted a PR to try and implement an real docxRaw helper: https://github.com/jsreport/jsreport-docx/pull/23
Feedback welcome :)