How to prevent CKEditor insertHtml from wrapping an element inside <p> in webkit browsers?

I am trying to create an interface page to allow my users to create smarty templates with the ckeditor wysiwyg editor.

Im using the insertHtml function to add a button with special attributes (you need to parse it in the smarty variable in the backend):

// initialize ckeditor
$('textarea.editor').ckeditor({
    contentsCss: '/css/test.css'
});
// get ckeditor instance
ckeditorInstance = $('textarea.editor').ckeditorGet();
// Use some elements (outside the textarea) to add buttons/tokens
// to wysiwyg textarea
$("a.tinymce.tinymce-insert-var").click(function(){
    ckeditorInstance.insertHtml(
        '<input type="button" readonly="readonly" var="{$user-&gt;name}" '
        + 'class="placeholder" value="User Name" />'
    );
});

This works fine in Firefox, IE8, and Opera, but with Chrome / Chromium / Safari a button is inserted between the element <p>.

Is there a way to avoid this or a callback that I can use to delete a paragraph?

+3
source share
3 answers

. ...

var editor = $('textarea[name=content]').ckeditorGet();
var element = CKEDITOR.dom.element.createFromHtml( '<p>I am a new paragraph</p>' );
editor.insertElement( element );
+2

, jQuery... p CKEditor.insertHtml, jQuery . , p?

0

in the main configuration file ckeditor it is possible to disable the automatic <p> Insert. try changing the values ​​of CKConfig.EnterMode and CKConfig.ShiftEnterMode, for example, to 'br'.

Felix

0
source

Source: https://habr.com/ru/post/1789780/


All Articles