【发布时间】:2018-02-11 15:25:40
【问题描述】:
我在解析 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,
}
我在写消息时使用了以下内容:'
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
谢谢你
【问题讨论】:
-
检查数据库中的数据是否也是html编码的。此外,没有 htmlDecodeOutput 配置选项。
-
HI 向导,我删除了 htmlDecodeOutput 选项,但仍然是同样的问题。您对如何正确显示和格式化文本有任何(其他)想法吗?谢谢
-
既然您已经检查了数据库中的数据是好的,那么您使用什么命令来输出数据?您是否使用 PHP 和
htmlspecialchars或htmlentities? -
当我获取数据时,我只是将它发送到视图引擎(车把)。我没有做任何特别的事情。我正在使用 NodeJS、Handlebars 和 MongoDB。下面是渲染数据的promise。
-
你能把Handlebars模板中影响
msgContent的部分贴出来吗?