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

其他-如何禁用ckeditor中的img自动样式?

(其他 - How to disable automatic style to img in ckeditor?)

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

当我与ckeditor合作时,有一个问题。我按下添加图像的图标,然后出现模态窗口,并将直接图像链接放在特殊字段中,此刻自动检测到宽度和高度,并为ex编写样式:

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

我可以禁用此自动功能吗?还是我每次都必须自己删除此样式?

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

你可以为配置编写一条规则,该规则将删除元素上的样式标签。

  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 );
  });