This is similar to Jade - convert new lines to <br/> and keep the content encoded
so is there easy way to do the same in ejs:
<%- escape(foo).replace(/\n/g, '<br/>') %>
This could be possible by extracting escape method from ejs and assign to res.locals, but I'm looking for something more elegant if it's possible
I had a similar problem, when I had to display git commit message in my page. I had a look at how GitLab formats commit messages and found out that they use white-space: pre-wrap. https://developer.mozilla.org/en-US/docs/Web/CSS/white-space
So in my .ejs file I use:
<div style="white-space: pre-wrap"><%= commit.body %></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With