handlebars.js 用 <br>替换掉 内容的换行符


JS:

Handlebars.registerHelper('breaklines', function(text) {
text = Handlebars.Utils.escapeExpression(text);
text = text.toString();
text = text.replace(/(\r\n|\n|\r)/gm, '<br>');
return new Handlebars.SafeString(text);
});


HTML template:

<div>
{{breaklines description}}
</div>