In CKEditor 4 with the automatic mode, I would like to allow only one style attribute for the elements, namely float for the <img> tags. All the other styles in the code should be disallowed.
For managing images I use Enhanced Image plugin (image2). With no specific ACF applied, the float attribute works just fine. The problem is that all the other styles are kept in the code too.
So I tried to disallow all the styles using *{*} with extra allowing img{float}, but apparently it does not work this way, since the float attribute is removed too, despite of extraAllowedContent settings.
Do you know why this does not work? Or do you have another idea how to achieve that, please?
This is my editor settings:
CKEDITOR.replace( 'editor', {
toolbar: [
{ name: 'styles', items: [ 'Format' ] },
{ name: 'basicstyles', items: [ 'Bold', 'Italic', 'Underline' ] },
{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
{ name: 'indexes', items: [ 'Subscript', 'Superscript' ] },
{ name: 'paragraph', items : [ 'NumberedList', 'BulletedList' ] },
{ name: 'media', items: [ 'Image' ] },
{ name: 'iframe', items : [ 'Iframe'] },
{ name: 'tools', items : [ 'Find'] },
{ name: 'document', items: [ 'Source'] },
],
format_tags: 'h2;h3;p',
width: 820,
height: 500,
entities_latin: false,
removePlugins: 'image, exportpdf',
extraPlugins: 'image2, find',
tabSpaces: 6,
disallowedContent: '*{*}',
extraAllowedContent: 'img{float}',
});
If you want to ignore all styles except float then make sure you don't include anything that sets styles in the CKEditor4's menu. HTML elements & styles that are not menu options are stripped out automatically.
Image2overrides that default behavior forfloatsettings onimgtags.Using https://cdn.ckeditor.com/4.13.1/full-all/ckeditor.js, the following settings:
Starting with:
Results in: