Giter Club home page Giter Club logo

Comments (3)

edi9999 avatar edi9999 commented on August 15, 2024

Hi,

Yep I think you have found the best solution I can think of for the problem you encounter.

In a HTML Templating Language, I think new lines are never converted automatically into <br> and I think that would be outside of the scope of docxtemplater.

However the fact that it says the output is invalid should lead to this: maybe docxtemplater should throw an error itself when they are some new lines in the text you want to enter.

An other solution for this would be to convert the text the user entered into valid XML (Like <w:p><w:t> .... </w:t> </w:p>) and using the {@rawXml} notation. You would have to make that conversion accordingly.

from docxtemplater.

emgee3 avatar emgee3 commented on August 15, 2024

So I thought I was passing in \n line breaks and that was causing the corrupted docx file, but in fact forgot the /g in my regex, so was indeed passing in some <br>s.

As far as docxtemplater throwing errors, you might consider automatic escaping characters that will result in invalid XML, with an option to override for someone intentionally passing in valid XML. Or, just note in the readme that tags may result in an invalid XML file.

But regardless, it's working perfectly for me now. Thank you!

from docxtemplater.

edi9999 avatar edi9999 commented on August 15, 2024

The @ notation : {@text} does exactly this. It will replace the current paragraph by the XML you pass into text.

I will probably escape the XML content with the normal notation {text}

from docxtemplater.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.