解析 ckeditor 内容并应用标签而不是将它们显示在屏幕上

parse ckeditor content and apply tags instead of displaying them on the screen

我在解析 CKEditor 的内容时遇到问题。我已将数据保存到 mongoDB 中,但是当我检索要显示的内容时,它会显示标签而不是解析它们。

内容在我保存时有 s 格式 。这就是当我从数据库中检索它时我希望它显示的方式

但这是我从数据库中检索时得到的内容。我希望它应用标签但不显示它们。这样我就可以使用与输入时相同的格式。

<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;">&lt;p&gt;The &lt;strong&gt;content had thi&lt;/strong&gt;s formatting &lt;em&gt;when I saved it. This is how&lt;/em&gt; I want it to display &lt;strong&gt;&lt;em&gt;when I retrieve it from the database&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;</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

暂时谢谢你

根据 Handlebars 文档:

Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{.

因此,在您的模板中将 {{message.content}} 更改为 {{{message.content}}}