Trying to use handlebars.js for templating but the library seems to ignore newlines.
What is the correct way to deal with newlines? Should they be replaced manually
I've used the code posted by @Uri and it was very useful.
But I realised that when I register the helper, the function parameter that it receives is not the text, but the function that is called inside the Handlebars template. So first I had to call it to get the text.
In order to clarify, I had to do:
Handlebars.registerHelper('breaklines', function(descriptionFunction) {
text = descriptionFunction();
text = Handlebars.Utils.escapeExpression(text);
text = text.toString();
text = text.replace(/(\r\n|\n|\r)/gm, '
');
return new Handlebars.SafeString(text);
});
This is the only way I could make it work.