Insert HTML codes in CKEditor textarea

混江龙づ霸主 提交于 2019-12-10 12:09:17

问题


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

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

Anthony

EDIT1 ----- INSERTPRE Plugin -------

Query when I add the post :

    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);

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

    <pre class="prettyprint">

    &nbsp;</pre>

    <div>toto</div>

    <p>dqsdqs</p>

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

EDIT2 ----- Escape HTML -------

Screenshot : http://grab.by/m8bs

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.


回答1:


Check these two plugins:

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

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

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

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;

Note: &amp;lt; is an encoded &lt;.




回答2:


You can use source menu in ck editor header to add your html

Use this tutorial demo link




回答3:


Okay Try This

for added Post

addslashes($_POST['post_from_textarea']);

to Edit

stripslashes($yourvairablegetRowsQuery)


来源:https://stackoverflow.com/questions/16292733/insert-html-codes-in-ckeditor-textarea

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