Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKEditor strips inline attributes

I have been using CKEditor for some time and it has worked great. I've pretty much gotten rid of any problems that ive had but this one i cant seem to figure out. When i add inline attributes to elements for instance style = "color: #ff0;" on a <p></p> tag they are stripped out when i switch from wysiwyg to source view. No saving or submission is done and ckeditor is has been added to my site which is my own script. Any ideas as to what would cause this. All of the search results i can find correspond to this happening in Drupal but Drupal seems to be the problem not the editor in all instances. Thanks again!

like image 236
tiantang Avatar asked Apr 02 '13 00:04

tiantang


People also ask

Why is my inline editor not working with CKEditor?

This means that inline editors ignore default CKEditor content styles provided through the CKEDITOR.config.contentsCss configuration option and use the styles from the page that CKEditor is rendered on. Inline Editing is enabled directly on HTML elements through the HTML5 contenteditable attribute.

How do I inline edit a textarea in CKEditor?

When you call the CKEDITOR.inline method on a <textarea>, an additional <div> element with inline editing enabled will replace the original <textarea>. There is also an optional Div Editing Area plugin that allows to mimic the classic, <iframe> -based editor’s UI with inline editing.

How to add placeholder in CKEditor 5?

The command for the placeholder feature will insert a <placeholder> element (if allowed by the schema) at the selection. The command will accept the options.value parameter (other CKEditor 5 commands also use this pattern) to set the placeholder name. Import the created command and add it to the editor commands:

How to enable JavaScript in CKEditor?

Go to "Admin >> Configuration >> CKEditor"; under Profiles, choose your profile (e.g. Full). Edit that profile, and on "Advanced Options >> Custom JavaScript configuration" add config.allowedContent = true;. Show activity on this post. Since CKEditor v4.1, you can do this in config.js of CKEditor:


5 Answers

It feels like you're using CKEditor 4.1+ that comes with Advanced Content Filter (ACF). If so, you need to specify config.allowedContent and configure it to get your things working. You may also be interested in config.extraAllowedContent.

See this answer for more details.

like image 106
oleq Avatar answered Sep 23 '22 13:09

oleq


For anyone looking for a simple sample on how to enabled additional markup in CKEditor without disabling ACF completely, here is a short snippet:

CKEDITOR.replace( 'editor1', {
    extraAllowedContent: 'style;*[id,rel](*){*}'
} );

extraAllowedContent here enables the <style> element, allows two additional attributes (in square brackets) for all (* is a wildcard) already allowed elements, allows usage of any class names (*) for them and allows usage of any inline styles {*}

like image 41
Wiktor Walc Avatar answered Sep 26 '22 13:09

Wiktor Walc


hi you can stop ACF easily . by default your configaration is---

function ckeditor($name,$value='',$height=300){
    return '<textarea name="'.addslashes($name).'">'.htmlspecialchars($value).'</textarea>
<script>$(function(){CKEDITOR.replace("'.addslashes($name).'",{});});</script>';
} 

just add this in the curly brackets:

allowedContent: true

now your configuration will be:

function ckeditor($name,$value='',$height=300){
    return '<textarea name="'.addslashes($name).'">'.htmlspecialchars($value).'</textarea>
<script>$(function(){CKEDITOR.replace("'.addslashes($name).'",{allowedContent: true});});</script>';
}
like image 45
Chayon Shaah Avatar answered Sep 22 '22 13:09

Chayon Shaah


I faced the same issue and below answer solved my problem:

config.allowedContent = true;
config.extraAllowedContent = '*(*);*{*}';
config.extraAllowedContent = 'span;ul;li;table;td;style;*[id];*(*);*{*}';
like image 34
Rakhi Prajapati Avatar answered Sep 26 '22 13:09

Rakhi Prajapati


I had the same problem, that ck was stripping not only some attributes, but whole elements when pasting a block element, inside a block element (div with some attributes pasted inside a p) while using this method:

editor.insertHtml(html);

what solved the problem was using this workaround instead:

editor.insertElement(CKEDITOR.dom.element.createFromHtml(html));
like image 38
st'sahib Avatar answered Sep 25 '22 13:09

st'sahib