CKEditor removes the div class even though it is specified in extraAllowedContent

CKEditor removes CLASS div attributes when switching to / from the original view.

This is the configuration:

$('.cke-editor-restrictive').ckeditor({ extraAllowedContent: [ "*[class,id]", "a[*]", "img[*]", "strong", "em", "small", "u", "s", "i", "b", "p", "blockquote[class,id]", "div[class,id,data-href]", "ul", "ol", "li", "br", "hr", "h1", "h2", "h3", "h4", "h5", "h6", "script[src,charset,async]", "iframe[*]", "embed[*]", "object[*]", "cite", "mark", "time", "dd", "dl", "dt", "table", "th", "tr", "td", "tbody", "thead", "tfoot" ].join("; ") }) 

And the global configuration of CKEditor:

 CKEDITOR.editorConfig = function(config) { config.extraPlugins = 'mediaembed,codemirror,autosave'; config.codemirror = { ... }; config.toolbar = [['Bold', 'Italic', 'Underline', "RemoveFormat"], ['NumberedList', 'BulletedList', 'Blockquote'], ['Link', 'Unlink', 'Image', 'MediaEmbed'], ['Find', 'Paste'], ['Source', 'Maximize']]; config.bodyClass = 'ckeditor-body'; config.contentsCss = "/assets/application.css"; config.baseHref = "http://www.website.org/"; config.forcePasteAsPlainText = true; }; 

What am I missing? I was over the documentation for valid content rules , and it doesn't look like I'm doing something wrong. Even if I change the rule to div[*] , it will delete the class.

+4
source share
2 answers

Classes and styles are not processed along with other attributes. They have their place in the ACF rules. To include all styles, you should write:

 'div{*}' 

And to include all classes:

 'div(*)' 

And include everything:

 'div(*){*}[*]' 
+20
source

when I write

 config.extraAllowedContent = 'div(class);ul(class)[id]'; 

div , and ul save the concrete class , but id always deleted.

is there any way to resolve "id"?

edit: got it! for ALLOW ID β†’

 config.extraAllowedContent = 'div(rslides_container);ul(rslides)[id]'; 

If you want ckeditor to keep your identifier, do not change [id] (do not use your ID! Simple write [id], and ckeditor will not delete your identifier!

+2
source

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


All Articles