Nunjucks nl2br does not exist?
I need a filter like the Jinja "nl2br", but in the Nunjucks. In the documentation are a mention (https://mozilla.github.io/nunjucks/templating.html), but I searched it in the nunjucks code (https://github.com/mozilla/nunjucks/blob/master/src/filters.js) and it does not exist.
Somebody knows how to solve it with a equivalent filter or another solution? Or I need to create the filter?
Nunjucks has built-in escaping. If you set {autoescape: true}
when settings up Nunjucks, then you don't need to do anything. Otherwise, you can use the escape
filter.
If you just want to escape newlines, then do this:
env.addFilter('nl2br', function(str) {
return str.replace(/r|n|rn/g, '<br />')
})
and use the newly created nl2br
filter.
Note: env
is your Nunjucks environment.
上一篇: 将列添加到包含图像的列表视图
下一篇: Nunjucks nl2br不存在?