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
>
|
本文转自曾祥展博客园博客,原文链接:http://www.cnblogs.com/zengxiangzhan/p/3312579.html,如需转载请自行联系原作者