简体   繁体   English

MongoDB发出纯文本格式的HTML

[英]MongoDB emits HTML as plain text

Why isn't my html being rendered whenever I output the result from a query. 每当我从查询中输出结果时,为什么我的html不被渲染。

This is how I save the document: 这是我保存文档的方式:

data = {
    title: "Article title",
    body: "<b>This</b> is the content!!"
};

var article = new Article(data);

article.save();

And this is how I display it: 这就是我的显示方式:

h2.articleTitle(style="font-style: italic;") #{article.title}
p.articleBody(style="margin-top: 20px;") #{article.body}

The out of the article body should be: This is the content!! 文章正文中的内容应为: 是内容!!

But instead it outputs everything, including the html tag: <b>This</b> is the content!! 但是相反,它输出所有内容,包括html标签:<b>这</ b>是内容!

I was reading another similar question asked that told me to add a dash (-) before article.body. 我正在阅读另一个类似的问题,要求我在article.body之前添加一个破折号(-)。 This is what I tried: 这是我尝试的:

h2.articleTitle(style="font-style: italic;") #{article.title}
p.articleBody(style="margin-top: 20px;") 
    - article.body

But this didn't output anything when I tried it this way. 但这在我以这种方式尝试时没有输出任何内容。 Any help is greatly appreciated. 任何帮助是极大的赞赏。 Thanks. 谢谢。

Ok so the problem was how I was outputting with Jade, the template engine I'm using. 好的,问题是我如何使用Jade(我正在使用的模板引擎)进行输出。 I managed to fix this replacing the # to the ! 我设法解决此问题,将#替换为! symbol. 符号。

h2.articleTitle(style="font-style: italic;") #{article.title}
p.articleBody(style="margin-top: 20px;") !{article.body}

Original answer: Rendering HTML in variable using Jade 原始答案: 使用Jade在变量中呈现HTML

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM