在CKEditor textarea中插入HTML代码 [英] Insert HTML codes in CKEditor textarea

查看:373
本文介绍了在CKEditor textarea中插入HTML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一个插件为了插入HTML代码在CKEditor textarea?

I would like to know if there is a plugin in order to insert HTML codes in a CKEditor textarea?

我试图安装PBCKCode插件,因为HTML在我的文本区域中执行。

I tried to install the PBCKCode plugin but it doens't work because the HTML is executed in my textarea.

Anthony

我在添加帖子时查询:

    INSERT INTO `Posts` (`slug`,`title`,`thumbnail`,`content`,`tags`,`state`,`click`,`createdAt`,`updatedAt`,`id`) VALUES ('dsq','dsq','http://4.bp.blogspot.com/-knCgLUMOkJc/TeMY2jkmACI/AAAAAAAAAV0/VByHmoMa2N8/s1600/first+blog+posting.jpg','<pre class="prettyprint">\r\n&lt;div&gt;toto&lt;/div&gt;</pre>\r\n\r\n<p>dqsdqs</p>\r\n','toto','0',0,'2013-04-30 12:15:46','2013-04-30 12:15:46',NULL);

当我尝试编辑帖子时,我的textarea中的结果:

The result in my textarea when I try to edit the post :

    <pre class="prettyprint">

    &nbsp;</pre>

    <div>toto</div>

    <p>dqsdqs</p>

正如你可以看到div已经改变了地方。

As you can see the "div" have changed of place.

屏幕截图: http://grab.by/m8bs

正如你所看到的,它可以在P标签上面的lug),但它不工作在我的textarea。我认为CKEditor编码我的内容,但我不知道什么时候和为什么...在我的数据库一切正常,我有代码到PRE标签。

As you can see it works in a P tag (just above the slug) but it doesn't work in my textarea. I think CKEditor encode my content but I don't know when and why... In my database everything is ok, I have the codes into the PRE tag.

推荐答案

检查这两个插件:

  • http://ckeditor.com/addon/insertpre
  • http://ckeditor.com/addon/syntaxhighlight

我们使用第一个一个在 http://ckeditor.com/forum 上,效果非常好。

We use the first one on http://ckeditor.com/forum and it works very well.

更新:这是因为您不是在将HTML传递给textarea之前对其进行编码。

Update: That's because you're not encoding HTML before you pass it to textarea. Use htmlspecialchars (or other similar function if you're not using PHP) to do that.

Update2:使用htmlspecialchars(或其他类似的函数,如果你不使用PHP)我不知道在什么阶段。具有一个< pre> 元素的编辑器的输出数据( editor.getData() p>

Update2: You are doing something wrong, but I don't know on what stage. The output data (editor.getData()) from the editor with one <pre> element is:

<pre class="prettyprint">&lt;div&gt;</pre>

查看< pre> 编码,但< div> 里面。你的例子告诉我你扁平化了这个结构 - 你已经编码了两个事情,应该是平等的:

See that <pre> is not encoded, but <div> inside it is. Your examples show me that you "flattened" that structure - you have encoded both things equally when it should be:

&lt;pre class=&quot;prettyprint&quot;&gt;&amp;lt;div&amp;gt;&lt;/pre&gt;

注意:& amp; lt; 是一个编码的& lt;

这篇关于在CKEditor textarea中插入HTML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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