在 CKEditor5 中更改视图架构的优雅方式

Elegant way to change view schema in CKEditor5

我正在寻找一种方法来更改 CKE5 使用的视图 schema/tags,同时尽量不重新实现所有内容。所以基本上问题是在编辑器中将 <strong> 元素更改为 <b> 的最佳方法是什么。

我目前的解决方案是更改 *editing.js 文件和基本插件文件以包含修改后的编辑插件而不是原始插件。这很好用,但是,我想知道是否有办法减少完成此任务所需的代码行数。

所以我的解决方案目前是这样的:

newbold.js:

static get requires() {
    return [ NewBoldEditing, BoldUI ];
}

newboldediting.js:

editor.conversion.attributeToElement({
    model: 'bold',
    view: 'b'
});

是否有更好的方法(最好不涉及重新实现这么多 类)?

您只能提供一个非常简单的插件来覆盖默认的 bold 属性转换。

class BoldToB extends Plugin {
    init() {
        this.editor.conversion.attributeToElement( {
            model: 'bold',
            view: 'b',
            converterPriority: 'high'
        } );
    }
}

这里有一个fiddle供你测试:https://jsfiddle.net/u3zyw67v/

请注意,在 fiddle 中我无法访问 Plugin class,所以我不得不添加 constructor()。如果扩展 Plugin class.

,则不需要这样做