如何在 allowedContent 配置的 img 标签上允许属性 class?

How allow attribute class on img tag for allowedContent config?

我写的是关于使用 allowedContent 配置选项的问题。 我使用此选项设置我的 ckeditor 实例:

        allowedContent: 'p; strong; em; u; s; sub; sup; ul; ol; li; blockquote; a [!href, title, target, rel]; hr; h2; h3; pre; img [!src, alt, height, width, title, id];',

如何允许为 img 标签插入 "class" 属性?在我从数据库读取的 html 代码中,我有这个:

        <img alt="xx" width="100" height="100" src="yyy" class="myclass" />

但是当我将它加载到 ckeditor 中时 class 属性被删除。

我试过了

        img [!src, alt, height, width, title, class, id]

        img (cke-xyz) [!src, alt, height, width, title, id]

但不起作用。

有什么想法吗?

谢谢

如果您想允许特定的 class 名称:

img(classname1, classname2)[attr1, attr2]

或者如果您想允许所有 classes:

img(*)[attr1, attr2]

在文档中阅读更多内容:Allowed Content Rules