dustjs html从dusthelper逃脱输出

时间:2016-08-17 07:52:41

标签: dust.js

我希望html从@pre中删除内容。来自{@pre key =" property-key" type =" content" /}是这包含"和'在句子中。我希望将其转义为此包含& #34;和& #39;在句子中

我试过{@pre key =" property-key"类型="内容"过滤器=" h" /}但不起作用。

1 个答案:

答案 0 :(得分:0)

因为{@pre}(我假设this one)返回一个Chunk,你不能直接修改输出。

您可以将此助手包装在您自己的助手中,以便HTML转义返回值。

dust.helpers.escapePre = function(chunk, context, bodies, params) {
  return chunk.tap(function(data) {
    return dust.escapeHtml(data);
  }).helper('pre', context, bodies, params);
}

{@escapePre key="property-key" type="content" /}

此示例帮助程序只调用pre帮助程序,并通过一个函数来点击输出,该函数会转义传递给它的所有数据。