我在解析CKEditor的内容时遇到问题。我已将数据保存到mongoDB中,但是当我检索要显示的内容时,它会显示标记而不是解析它们。
内容在我保存时具有格式。这就是我希望它从数据库中检索 时显示。
但这是我从数据库中检索时得到的内容。我希望它应用标签但不显示它们。所以我可以使用与我输入相同的格式。
<p>The <strong>content had thi</strong>s formatting <em>when I saved it. This is how</em> I want it to display <strong><em>when I retrieve it from the database</em></strong>.</p>
当我尝试显示内容时,我的html页面如下:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="https://cdn.ckeditor.com/4.8.0/standard/ckeditor.js"></script>
</head>
<body>
<div id="pgContent">
<div class="container">
<span class="line"></span>
<div id="msgContent" style="max-width:800px; font-size:16px;"><p>The <strong>content had thi</strong>s formatting <em>when I saved it. This is how</em> I want it to display <strong><em>when I retrieve it from the database</em></strong>.</p></div></div></div>
</body>
没有添加jquery / javascript。我添加了javascript,但它再次将div转换为编辑器:
CKEDITOR.replace('msgContent',
{
entities: false,
basicEntities: false,
entities_greek: false,
entities_latin: false,
htmlDecodeOutput:true,
}
我在撰写邮件时使用了以下内容:&#39;
CKEDITOR.replace('msgEditor')
更新 数据库(mongoDB)中的数据如下所示:
<p>The <strong>content had thi</strong>s formatting <em>when I saved it. This is how</em> I want it to display <strong><em>when I retrieve it from the database</em></strong>.</p>\r\n
现在谢谢你
答案 0 :(得分:0)
根据Handlebars文档:
Handlebars HTML-escapes {{expression}}返回的值。如果你 不希望Handlebars逃脱价值,使用&#34; triple-stash&#34;,{{{。
因此,在您的模板中将{{message.content}}
更改为{{{message.content}}}