2017-06-19 81 views
1
[whamlet| 

      <h2> Here's the ES results: 
      <h1> 
      <ul> 
       $forall EsHighlight high <- highlights re 
        <li> 
         <br> 
         #{toHtml high} 

     |] 

高是这样的:耶索德Whamlet呈现为HTML不被转义

"large <em>bamboo</em>, and a crotched stick. Throwing these down, he poked under a pile of rubbish, and brought out a rough block of wood, pierced through and through with a hole, which was immediately clapped on the top of the jar. Then planting the crotched stick upright about two yards distant, and making it sustain one end of the <em>bamboo</em>, he inserted the other end of the latter into the hole in the block: concluding these arrangements by placing an old calabash under the farther end of the <em>bamboo</em>." 

的问题是,<em>不会被渲染成HTML,但仍字符串。所以网页显示<em>本身。 我能做什么?

+0

使用^ {...}取而代之。 – mb14

+0

@ mb14 thx但它不工作 – osager

+0

使用^ {..}你需要一个小部件而不是字符串(或文本)。你需要以某种方式将'high'转换成一个小部件(也许使用'[whamlet | .. |]'生成''。 – mb14

回答

2

作为防止XSS攻击的保护措施,Hamlet(和底层的blaze-html库)的默认行为是通过toHtml函数转义所有HTML实体。如果你想避免逃跑,你可以使用preEscapedToHtml。请注意,在用户提供的数据上使用此功能是高度危险