如何使用Handlebars解码HTML实体 [英] How to decode HTML entity with Handlebars
问题描述
我知道它会转义HTML值默认情况下,您必须使用三元括号 {{{text}}}
才能使用文本:< p>示例< / p> ;
问题是,如果我收到的数据(包括HTML标记)已经逃脱了?
因此,如果我收到类似的数据:
$ b
文字:& lt; p& gt;范例& lt; / p& gt;
如何强制句柄翻译并将其呈现为普通HTML?
您必须先解码,然后将其传递给带有三个方括号的句柄。我知道一个用jQuery来解码html实体的小技巧:
//编码是& lt; p& gt;示例& amp ('< textarea />>')。html(encoded).val();在你的例子中$ lt; / p& gt;
//解码后现在应该返回< p>示例< / p>
I'm using the Handlebars templating engine on the app I'm building to render the data I get from the server.
I know that it escapes HTML values by default and that you have to use the triple brackets {{{text}}}
in order for text: <p>Example</p>
to be rendered as an HTML element.
The problem is, what do I do if the data I receive, including the HTML tags, is already escaped?
So, if I receive data like:
text: <p>Example</p>
How do I force handlebars to translate it and render it as normal HTML?
You have to decode it first, then pass it to handlebars with triple brackets. I know a small tip to decode html entities with jQuery:
// encoded is "<p>Example</p>" in your example
var decoded = $('<textarea />').html(encoded).val();
// decoded should now return <p>Example</p>
这篇关于如何使用Handlebars解码HTML实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!