Nunjucks has built-in shielding. If you set {autoescape: true} when configuring Nunjucks, you donβt need to do anything. Otherwise, you can use the escape filter.
If you just want to change the newlines, do the following:
env.addFilter('nl2br', function(str) { return str.replace(/\r|\n|\r\n/g, '<br />') })
and use the newly created nl2br filter.
Note: env is your Nunjucks environment.
somebody
source share