Warm tip: This article is reproduced from serverfault.com, please click

How to disable automatic style to img in ckeditor?

发布于 2015-11-21 19:09:26

There is one problem when I work with ckeditor. I press on icon for adding images, then modal window appears and I put direct image link in the special field, in this moment width and height detected automatically and it writes to style for ex:

<img src='#some images direct link' style='width:SOME WIDTH;height:SOME HEIGHT'>

Can I disable this automatic function? Or I have to delete this style by myself every time?

Questioner
Jerome
Viewed
0
Ben 2015-11-22 03:17:41

You could write a rule for your config that would remove the style tag on elements.

  var editorRulesObject = {
    elements: {
      img: function( el ) {
        if(el.attributes.style) {
          el.attributes.style = '';
        }
      }
    }
  };

  CKEDITOR.on('instanceReady', function( e ) {
    // Ensures that any non-styled text, or text input without any tags will be correctly styled.
    CKEDITOR.instances[e.editor.name].dataProcessor.dataFilter.addRules( editorRulesObject );
    CKEDITOR.instances[e.editor.name].dataProcessor.htmlFilter.addRules( editorRulesObject );
  });