javascript - Nunjucks nl2br does not exist? -


i need filter jinja "nl2br", in nunjucks. in documentation mention (https://mozilla.github.io/nunjucks/templating.html), searched in nunjucks code (https://github.com/mozilla/nunjucks/blob/master/src/filters.js) , not exist.

somebody knows how solve equivalent filter or solution? or need create filter?

nunjucks has built-in escaping. if set {autoescape: true} when settings nunjucks, don't need anything. otherwise, can use escape filter.

if want escape newlines, this:

env.addfilter('nl2br', function(str) {     return str.replace(/\r|\n|\r\n/g, '<br />') }) 

and use newly created nl2br filter.

note: env nunjucks environment.


Comments