CKEditor escape html

不羁岁月 提交于 2020-01-24 00:40:15

问题


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>

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


回答1:


<pre>
<code class="html">
<img src="path/to/img.jpg" />
</code>
</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>

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

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().



来源:https://stackoverflow.com/questions/28907988/ckeditor-escape-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!