Is html autoescaped in html/template?

agolangf · · 306 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>EDIT: can&#39;t edit the title, but it was supposed to be &#34;how to not autoescape html in templates&#34;</p> <p>I am using html/template for my webapp which uses a lib for doing html conversion from markdown, when I use html/template, the rendered template doesn&#39;t render the html, it injects an auto escaped html! (Earlier, by IDE auto imports, I was foolishly using text/template so this problem did not arise.)</p> <hr/>**评论:**<br/><br/>thewhitetulip: <pre><p>Found the solution:</p> <pre><code>vars := map[string] interface {} { &#34;Title&#34;:&#34;Test&#34;, &#34;Body&#34;:template.HTML(&#34;Hello &lt;b&gt;World&lt;/b&gt;&#34;), } </code></pre> <p>If we make the thing as not string but template.HTML, then we are good to go.</p> <p><a href="http://play.golang.org/p/Uw8l3M7Qvg" rel="nofollow">http://play.golang.org/p/Uw8l3M7Qvg</a></p></pre>neoasterisk: <pre><p>You could consider using a <code>struct</code> instead of a <code>map[string]interface{}</code>.</p></pre>thewhitetulip: <pre><p>Indeed, <a href="https://github.com/thewhitetulip/Tasks/blob/master/types/types.go#L14" rel="nofollow">https://github.com/thewhitetulip/Tasks/blob/master/types/types.go#L14</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

306 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传