pugtemplate-enginepugjs

Outputting a string into a JADE/PUG file


So I have an issue where the string I'm reading in contains newlines, and I'm parsing the newlines in my JS file like so

var str = post.content.replace(/(?:\r\n|\r|\n)/g, '<br/>;');

For example, I want my text:

Hello World! How's it going?

to become

Hello World!

How's it going?

But instead, I'm getting

Hello World! <br/> How's it going?

How would I best approach this? It seems the logic I imported from HTML will not work in JADE/PUG


Solution

  • I think you are stuck with the variable interpolation issue. Please see the pugjs documentation regarding the same.

    For eg. when putting the str value to a tag, mark it as a safe string in pug template:

    - var str = post.content.replace(/[\r\n]/g, '<br/>;');
    p !{str}
    //- or
    p= str