Nunjucks nl2br does not exist?
Nunjucks nl2br does not exist?
我需要一个像Jinja"nl2br"这样的过滤器,但在Nunjucks中。在文档中提到了(https://mozilla.github.io/nunjucks/templating.html),但我在双节棍代码(https://github.com/mozilla/nunjucks/blob/master/src/filters.js)中搜索了它,它不存在。
有人知道如何用等效的过滤器或其他解决方案来解决它吗?或者我需要创建过滤器?
Nunjucks 具有内置的转义功能。如果您在设置双节棍时设置{autoescape: true}
,则无需执行任何操作。否则,您可以使用escape
筛选器。
如果您只想转义换行符,请执行以下操作:
env.addFilter('nl2br', function(str) {
return str.replace(/'r|'n|'r'n/g, '<br />')
})
,然后使用新创建的nl2br
过滤器。
注意:env
是您的双节棍环境。
现在双
节棍中有一个nl2br
过滤器(参见文档)
所以我有一些不安全的文本,但你仍然想将新行更改为<br/>
标签,你可以对文档使用以下示例
{{ "foo'nbar" | striptags(true) | escape | nl2br }}
将输出
foo<br />'nbar
并显示为
foo
bar
相关文章:
- jQuery is not loaded
- AngularJS JSON not arriving php
- $rootScope not working
- reactRedux is not defined
- jQuery document.ready not working
- Javascript/Jquery Blob not showing Chrome PDF
- ReferenceError: not defined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- Javascript getElementsByTagName not working?
- jQuery's trim()的前缀为not运算符
- Javascript - element.childNodes does not see an append.newch
- SemanticUI模态not onDeny/onApprove事件未激发
- WebkitTransform not fluent
- JQuery.val( ) not working
- Tomcat websocket is not working
- Nunjucks nl2br does not exist?
- YDN-DB getting Store: null not exist
- Mapbox {"message":"Tileset does not exist&quo
- Angular 2 - 'imports' does not exist in type 'Co
- angular2 d3.event.sourceEvent does not exist