【问题标题】:The jade template can't render content that have html tag?翡翠模板不能渲染带有html标签的内容?
【发布时间】:2012-12-17 15:41:56
【问题描述】:

我的玉模板是

div.article
 #{content}

内容为<p>Sample Test</p>

所以渲染结果应该是

<div class="article">
  <p>Sample Text</p>
</div>

但是渲染结果是

   <div class="artichle">
    <<p>Sample Text</p>></<p>Sample Text</p>>
   </div>

为什么会这样?如何正确渲染带有 html 标签的内容?

【问题讨论】:

    标签: html tags render pug


    【解决方案1】:

    使用标签文本的未转义变体:

    - var html = "<script></script>"
    | !{html}    
    

    查看https://github.com/visionmedia/jade#tag-text了解完整说明

    在你的例子中你会写:

    div.article
      !{content}
    

    请注意,在注入 html 非转义代码时应该小心。根据您的用例,它可能包含跨站点攻击(在评论中注入重定向)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-24
      相关资源
      最近更新 更多