hi would like to know whether sails has its own function to format string variable to html? I have this scenario...

in my controller, I have a variable whose value is something like this:

var str = "Pellentesque habitant \r\nmorbi tristique senectus et\nnetus et malesuada fames ac turpis \negestas.";

when I display it as html page it will display plain as this. (1 paragraph only)

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.

but in view source

Pellentesque habitant 
morbi tristique senectus et
netus et malesuada fames ac turpis
egestas.

I'm searching for the possible solutions for this, and found about Underscore string (https://www.npmjs.org/package/underscore.string) I havent tried it yet, I'm just thinking that there's other possible solutions out there without installing another module...

Or is there any sails equivalent of php function nl2br?

Thanks!

有帮助吗?

解决方案

You'll need to use white-space: pre-wrap or the equivalent to get the newlines. By default, line feeds in HTML text are just more white space.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top