I’m trying to generate a Microsoft Word Document using docxtemplater library https://www.npmjs.com/package/docxtemplater. Here is how my code would look like (using in browser):
<script src="https://cdnjs.cloudflare.com/ajax/libs/docxtemplater/3.49.0/docxtemplater.js"></script>
<script src="https://unpkg.com/[email protected]/dist/pizzip.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
<script src="https://unpkg.com/[email protected]/dist/pizzip-utils.js"></script>
<script>
function loadFile(url, callback) {
PizZipUtils.getBinaryContent(url, callback);
}
window.onload = function generate() {
const data = "<i>some text with italic</i>";
const file = "http://file-url";
loadFile(file, function (error, content) {
if (error) {
throw error;
}
const zip = new PizZip(content);
const doc = new window.docxtemplater(zip, {
paragraphLoop: true,
linebreaks: true,
});
doc.render({
"data":data
});
const blob = doc.getZip().generate({
type: "blob",
mimeType:
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
compression: "DEFLATE",
});
saveAs(blob, "output.docx");
});
}
</script>
When i look at the word output, i expect it to look like “some text with italic”, instead of
<i>some text with italic</i>
How can i make text in the word output italic using docxtemplater library?