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



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

内容在我保存时具有Thi 格式。这就是我希望它从数据库 。

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

<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>rn

谢谢您

根据车把文档:

车把html-escapes值由{{expression}}返回。如果你 不想让车把逃脱一个值,使用"三重 - 静止",{{{。

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

最新更新