gpt4 book ai didi

javascript - 使用 CKEDITOR.style.addCustomHandler 修改格式插件样式

转载 作者:行者123 更新时间:2023-11-29 19:38:30 25 4
gpt4 key购买 nike

CKEditor 文档及其源代码中的注释暗示可以使用 addCustomHandler 对样式的应用方式进行一些控制。 ,包括现有样式。例如,在 line 665 上的 core/style.js 中我们有:

The style handling job, which includes such tasks as applying, removing, checking state, and checking if a style can be applied, is very complex. Therefore without deep knowledge about DOM and especially {@link CKEDITOR.dom.range ranges} and {@link CKEDITOR.dom.walker DOM walker} it is impossible to implement a completely custom style handler able to handle block, inline, and object type styles. However, it is possible to customize the default implementation by overriding default methods and reusing them.

最后一句话让我觉得我应该能够修改发生的事情,例如,当 the format plugin用于应用样式更改以使用类似以下内容将文本转换为 h1 标题:

CKEDITOR.style.addCustomHandler({
element: 'h1',
type: 1,
apply: function( editor ) {
console.log( 'apply' );
},
remove: function( editor ) {
console.log( 'remove' );
}
});

但是上面的内容以及它的几个变体(具有不同或省略的 elementtype 属性)没有效果。

我想这不可能,或者我做错了什么,但我不知道是哪一个。任何帮助将不胜感激。

(请注意,我可以从文档中看到如何使用 type 属性创建全新样式并使用 addCustomHandler 修改它,但是格式插件使用 element 属性而不是 type 属性创建其样式。)

谢谢!

最佳答案

However, it is possible to customize the default implementation by overriding default methods and reusing them.

你误解了这句话(为此道歉,因为我是作者 :D)。使用CKEDITOR.style.addCustomHandler您只能添加新类型。我所说的覆盖是指访问 CKEDITOR.style.prototype。例如:

var originalApply = CKEDITOR.style.prototype.apply;
CKEDITOR.style.prototype.apply = function( editor ) {
originalApply.call( this, editor );
};

关于javascript - 使用 CKEDITOR.style.addCustomHandler 修改格式插件样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24364091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com