如何防止CKEditor向img标签添加行内高度、宽度样式?

How to prevent CKEditor from adding inline height, width styles to img tags?

我的配置如下:

config.allowedContent = true;
config.disallowedContent = 'img {width,height}';

不过,在添加图像、保存表格并查看结果 HTML 时,我看到:

<img src="/uploads/ckeditor/pictures/759/image.jpg" style="width: 227px; height: 300px;">

根据我读过的所有文档,and answers I've seen on SO,那两条配置行应该会处理它,但它们不会。

正如 Disallowed Content documentation 解释的那样:

It is not possible to disallow content when the Advanced Content Filter is disabled by setting CKEDITOR.config.allowedContent to true.

如果您想以这种方式继续 ("allow everything, except inline width and height styles on images"),请检查 How to Allow Everything Except... 部分。

但是,更好的解决方案是仅扩展 automatic mode and disallow what you need as described in the Automatic mode but disallow certain tags/properties 场景。