【问题标题】:Elegant way to change view schema in CKEditor5在 CKEditor5 中更改视图模式的优雅方法
【发布时间】:2019-05-22 18:49:56
【问题描述】:

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

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

所以我的解决方案目前看起来像这样:

newbold.js:

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

newboldediting.js:

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

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

【问题讨论】:

    标签: ckeditor ckeditor5


    【解决方案1】:

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

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

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

    请注意,在小提琴中,我无权访问 Plugin 类,因此我必须添加 constructor()。如果您扩展 Plugin 类,则不需要这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-07
      • 1970-01-01
      • 2015-04-12
      • 1970-01-01
      • 2014-11-10
      • 2011-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多