javascript Mustache:全局禁用 html 转义?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22910428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mustache: Globally disable html escaping?
提问by Christopher Klewes
Is there a way how I can (without modifying the sources of mustache) disable the HTML escaping? I'm using mustache for other things and dont want to have the following entities escaped.
有没有办法(不修改胡子的来源)禁用 HTML 转义?我正在将小胡子用于其他用途,并且不想让以下实体逃脱。
var entityMap = {
"&": "&",
"<": "<",
">": ">",
'"': '"',
"'": ''',
"/": '/'
};
Given a template like foo '{{bar}}'
and a view { bar : 1 }
will produce foo '1'
.
给定一个像这样的模板foo '{{bar}}'
,一个视图{ bar : 1 }
将产生foo '1'
.
回答by Andrew Newby
If you are trying to just NOT HTML escape some strings, you just do {{{xx}}}instead of {{xx}}
如果您只是想不使用 HTML 转义某些字符串,则只需执行{{{xx}}}而不是{{xx}}
As per:
按照:
http://mustache.github.io/mustache.5.html
http://mustache.github.io/mustache.5.html
So if you had a string that consisted of:
因此,如果您有一个包含以下内容的字符串:
test => Q & A
测试 => 问答
Calling with:
打电话给:
{{ test }}
would give you:
会给你:
Q & A
..but calling with:
..但是打电话给:
{{{ test }}} or {{ &test }}
Would give you just:
会给你:
q & a
回答by Christopher Klewes
It's actually pretty simple, mustache
is offering the escape
function to be overridden. The following line disables the escaping of mustache templates.
它实际上非常简单,mustache
就是提供escape
要覆盖的功能。以下行禁用了 mustache 模板的转义。
mustache.escape = function (value)
{
return value;
};