carbone icon indicating copy to clipboard operation
carbone copied to clipboard

[Bug Report]: space removed from between template fields

Open grahampcharles opened this issue 3 years ago • 4 comments

Environment Carbone Version: 3.2.3 Node Version: 14.17.3 Browsers: none Desktop OS: Win10

Expected Behaviour When two fields are separated by a space in the template, the space should be preserved in the rendered output.

Hello, {d.firstname} {d.lastname} => Hello, John Doe

Actual Behaviour This works correctly using .odt templates. (This is, in fact, the sample.odt template from node_modules.) When the template is recreated as a .docx, using the same syntax, the space between the two fields is removed.

Hello, {d.firstname} {d.lastname} => Hello, JohnDoe

Steps to reproduce Steps to reproduce the bug:

  1. Create a .docx file with the contents Hello, {d.firstname} {d.lastname}
  2. Use carbone to render it using a sample object like {firstname: 'John', lastname: 'Doe'}
  3. The output removes the space in between the two fields.

Workaround Use a non-breaking-space (Control+Shift+Space) between the fields.

grahampcharles avatar Jul 14 '21 21:07 grahampcharles

Hello @grahampcharles, it's working on my side, can you share a template example to replicate the issue? We have to analyze the XML.

steevepay avatar Aug 24 '21 08:08 steevepay

Hi, @steevepay!

I'm experiencing this exact same issue. The template used is attached and it was created on a Mac (Word v16.55, License Microsoft 365 Subscription).

Thanks!

template.docx

rapcal avatar Dec 05 '21 23:12 rapcal

Hello @grahampcharles @rapcal

I've been having the same issue, it has something to do with how spaces between fields are parsed in the documents xml structure and for some reason leading & trailing spaces in <w:t> tags are ignored when the document is rendered/converted to pdf. I've created a workaround by replacing these space characters by no-break spaces which are not ignored, hope it helps. https://github.com/MattyTesar/carbone/ https://github.com/carboneio/carbone/pull/157

MattyTesar avatar Apr 25 '22 15:04 MattyTesar

Hello @grahampcharles @rapcal

I've been having the same issue, it has something to do with how spaces between fields are parsed in the documents xml structure and for some reason leading & trailing spaces in <w:t> tags are ignored when the document is rendered/converted to pdf. I've created a workaround by replacing these space characters by no-break spaces which are not ignored, hope it helps. https://github.com/MattyTesar/carbone/ https://github.com/carboneio/carbone/pull/157

Great! Thanks - will give it a go. Hope your PR gets merged

rapcal avatar Apr 25 '22 15:04 rapcal