CKEditor转义html [英] CKEditor escape html

查看:123
本文介绍了CKEditor转义html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在要插入html代码的帖子文本上有CKEditor。像这样的东西:

I have CKEditor on post text where I want to insert html-code. Something like this:

<pre>
<code class="html">
<img src="path/to/img.jpg" />
</code>
</pre>

但是当我保存文本时,CKEditor会将img-tag解释为实际的html-image并显示损坏的图像。如何防止这种情况并告诉您在 pre-code 块中转义html代码

But when I save the text, CKEditor interprets img-tag as actual html-image and shows broken image. How I can prevent that and tell to escape html-code in pre-code block

推荐答案

<pre>
<code class="html">
<img src="path/to/img.jpg" />
</code>
</pre>

这是 pre 元素。您要创建的是:

This is an image inside a pre element. What you want to create is:

<pre>
<code class="html">
&lt;img src="path/to/img.jpg" /&gt;
</code>
</pre>

如果您写< img ... /> 在CKEditor的 pre 元素内,然后CKEditor将返回此(有效)HTML。

And if you write <img .../> inside pre element in CKEditor, then CKEditor will return this (valid) HTML.

什么开发人员通常不知道的是,当他们将这些内容从数据库加载到< textarea> 时,可能需要对这些内容进行编码(取决于如何保存)。例如,在PHP中,足以将其通过 htmlspecialchars()

What developers often don't know is that when they load that content from their database into <textarea> this content may need to be encoded (depends on how it's saved). In PHP for instance it's enough to pass it through htmlspecialchars().

这篇关于CKEditor转义html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆