docx-templates: New line character inside a variable does not work
Hello,
I’m trying to replace a variable that contains newline character \n.
But this line break is not rendered in the output file, it’s just ignored.
const content = fs.readFileSync('/tmp/address.docx');
const wordBuffer = await createReport({
template: content,
cmdDelimiter: ['{{ ', ' }}'],
data: { address: 'City\nCountry'},
// processLineBreaks: true,
});
fs.writeFileSync('/tmp/test.docx', wordBuffer);
Expected output
City
Country
Actual output
CityCountry
I even tried to specify processLineBreaks: true (though it should be a default value) but without any change.
Thanks for help!
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 17
Commits related to this issue
- Added test case in an attempt to reproduce issue #143 (reproduction failed) — committed to guigrpa/docx-templates by jjhbw 4 years ago
- Second reproduction case for #143 based on template supplied by @nickdunn. Couldn't reproduce issue as test. See https://github.com/guigrpa/docx-templates/issues/143#issuecomment-694940845 — committed to guigrpa/docx-templates by jjhbw 4 years ago
- Second reproduction case for #143 based on template supplied by @nickdunn. Does not work in LibreOffice. See https://github.com/guigrpa/docx-templates/issues/143#issuecomment-694940845 — committed to guigrpa/docx-templates by jjhbw 4 years ago
- Second reproduction case for #143 based on template supplied by @nickdunn. Does not work in LibreOffice. See https://github.com/guigrpa/docx-templates/issues/143#issuecomment-694940845 — committed to guigrpa/docx-templates by jjhbw 4 years ago
- Turn regression test for #143 into a snapshot test. — committed to guigrpa/docx-templates by jjhbw a year ago
- Make the processLineBreaks behavior introduced for #143 the new default (i.e. processLineBreaksAsNewText is now always set to true). — committed to guigrpa/docx-templates by jjhbw a year ago
- Make the processLineBreaks behavior introduced for #143 the new default (i.e. processLineBreaksAsNewText is now always set to true). — committed to guigrpa/docx-templates by jjhbw a year ago
I have merged #182 into
master. You can now add set theprocessLineBreaksAsNewTextoption totrueto use the new line break injection behaviour. If no issues arise, we can probably make this the default behaviour in 5.x as it seems to improve compatibility with LibreOffice and Google Docs.I can’t push a new release to NPM now, because @guigrpa and I are working out some NPM permissions issues. Pulling the latest master commit into your package.json from GitHub is an alternative until the release is pushed.
I faced the same issue. LibreOffice completely ignored line breaks and Google drive lost some of the text. As a workaround I did this:
With settings: cmdDelimiter: [‘{{’, ‘}}’] processLineBreaks: false