senny / sablon

Ruby Document Template Processor based on docx templates and Mail Merge fields.
MIT License
443 stars 126 forks source link

template members get automatically stripped #160

Closed ainjoonas-ainsus closed 4 years ago

ainjoonas-ainsus commented 4 years ago

1) Add a string with the content of " " and connect it to template member 2) Attempt to find the added space at template position in your generated document

The raw string should find its way to the generated document. Currently it does not.

It becomes very frustrating when you need to do advanced templating. Yes, you can get by by adding in conditionals for these occurences, but there seriously is no need to strip these strings. Unless it is a language specific thing. My testing shows though that the stripping happens while the document is parsed by Sablon. Please let me know if there's a fix otherwise or direct me to where the action happens.

stadelmanma commented 4 years ago

@ainjoonas-ainsus I looked through the code and I don't see anywhere that context strings are explicitly stripped. MS Word being an XML format doesn't necessarily honor whitespace as it appears in the document so it could be "there" but not in a way that it appears in the document as expected. I would suggest creating a small simple template and trying to inject a bare space into it and see if you can find it in the expected location inside the document.xml file. You could also try to inject the desired whitspace as an inline WordML tag, i.e. <w:r><w:t xml:space="preserve"> </w:t></w:r>

ainjoonas-ainsus commented 4 years ago

I will try to inject the inline tag. I myself was debating if it was because of WordML specific instances or Sablon stripping members, but decided to look for help where this sort of help could be found.

ainjoonas-ainsus commented 4 years ago

Injecting inline wordML works like a charm. Thank you!

For future reference Sablon.content(:word_ml, ' </w:t></w:r>')