node.js 使用 Jade 在变量中呈现 HTML

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11191421/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 15:55:18  来源:igfitidea点击:

Rendering HTML in variable using Jade

node.jspug

提问by tofutim

I have some text stored in a variable which contains some HTML. For example, the <b>cat</b> in the hat. However, when I render it in Jade, it shows up with the tags instead of rendering the formatting. How can I fix this?

我有一些文本存储在一个包含一些 HTML 的变量中。例如,帽子上的 <b>cat</b>。但是,当我在 Jade 中呈现它时,它会显示标签而不是呈现格式。我怎样才能解决这个问题?

回答by agent-j

Code buffered by = is escaped by default for security, however to output unescaped return values you may use !=

为安全起见,由 = 缓冲的代码默认会转义,但是要输出未转义的返回值,您可以使用 !=

p!= aVarContainingHTML

Pug Doc

帕格文件

回答by akazemis

The syntax you need is :

您需要的语法是:

!{yourJsVariable}

if you use #{yourJsVariable}it shows < >, but with !{}it doesn't.

如果您使用#{yourJsVariable}它显示 < >,但使用!{}它不会。