简体   繁体   English

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

[英]Elegant way to change view schema in CKEditor5

I'm looking for a way to change the view schema/tags used by CKE5 while trying not to reimplement everything.我正在寻找一种方法来更改 CKE5 使用的视图架构/标签,同时尽量不重新实现所有内容。 So basically the question is what is the best way to change for example the <strong> element to <b> in the editor.所以基本上问题是在编辑器中将<strong>元素更改为<b>的最佳方法是什么。

My current solution is to change the *editing.js file, and the base plugin file to include the modified Editing plugin instead of the original.我目前的解决方案是更改*editing.js文件和基本插件文件,以包含修改后的 Editing 插件而不是原始插件。 This works nicely, however, I'm wondering if there is a way to reduce the number of lines of code needed to accomplish this task.这很好用,但是,我想知道是否有办法减少完成此任务所需的代码行数。

So my solution currently looks like this:所以我的解决方案目前看起来像这样:

newbold.js : newbold.js

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

and newboldediting.js :newboldediting.js

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

Is there a better way of doing this (that preferably wouldn't involve reimplementing this many classes)?有没有更好的方法来做到这一点(最好不涉及重新实现这么多类)?

You could provide only a very simple plugin that overwrites the default bold attribute conversion.您只能提供一个非常简单的插件来覆盖默认的bold属性转换。

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

Here's a fiddle for you to test: https://jsfiddle.net/u3zyw67v/这是一个供您测试的小提琴: https : //jsfiddle.net/u3zyw67v/

Note that in the fiddle I don't have access to Plugin class so I had to add constructor() .请注意,在小提琴中我无权访问Plugin类,所以我不得不添加constructor() You don't need to do that if you extend Plugin class.如果您扩展Plugin类,则不需要这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM