0

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.

Community
  • 1
  • 1
tonymx227
  • 5,293
  • 16
  • 48
  • 91
  • What do you mean by "insert HTML codes in a CKEditor textarea"? And note that CKEditor replaces textarea with an iframe containing editable element. Textarea is only a source of data. – Reinmar Apr 30 '13 at 16:59
  • I wanna add some codes like "PHP Code", "Javascript Code", "HTML Code", ect... In order to explain something in web development. – tonymx227 Apr 30 '13 at 17:25
  • **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. – Reinmar Apr 30 '13 at 21:20

3 Answers3

3

Check these two plugins:

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

Reinmar
  • 21,729
  • 4
  • 67
  • 78
  • Update in my post. I got an issue with INSERTPRE. – tonymx227 Apr 30 '13 at 19:20
  • I use NodeJS and ExpressJS. So it's in Javascript. – tonymx227 Apr 30 '13 at 21:52
  • http://stackoverflow.com/questions/1787322/htmlspecialchars-equivalent-in-javascript – Reinmar Apr 30 '13 at 22:16
  • I tried to use your function but I got the same thing. The most impressive is that I can show the HTML content in a P tag. See above #EDIT2. – tonymx227 May 01 '13 at 00:13
  • @Reinmar: I'm trying "insertpre" with version 4.3 of the editor, but it seems to do nothing, presumably because its last known compatible version was 4.1. Any suggestions on alternatives to edit a `
    ` without having to write a widget-based editor from scratch? I am guessing "syntaxhighlight" doesn't actually offer an editor, and at the time of writing, their online demo is broken. Thanks for any suggestions you might be able to offer!
    – halfer Feb 07 '14 at 19:36
  • 1
    CKEditor 4.4 will introduce official [code snippet](http://dev.ckeditor.com/ticket/11480) plugin. It's pretty ready now, but 4.4 will be released within 2 months. I don't know anyting about [insertpre](http://ckeditor.com/addon/insertpre)'s compatibility with 4.3, although I see that it works on http://ckeditor.com/forums. Try contacting its author. – Reinmar Feb 08 '14 at 15:12
  • Thanks @Reinmar - didn't get a notification of your comment. I'll make a note to get in touch with the author, good idea. – halfer Feb 17 '14 at 23:59
0

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

Use this tutorial demo link

Padmanathan J
  • 4,614
  • 5
  • 37
  • 75
  • I wanna add some codes in my article, I mean, I don't want that the HTML will be executate in my article. – tonymx227 Apr 30 '13 at 16:50
0

Okay Try This

for added Post

addslashes($_POST['post_from_textarea']);

to Edit

stripslashes($yourvairablegetRowsQuery)
Baby Groot
  • 4,637
  • 39
  • 52
  • 71