如果我在CKEDITOR中写的东西的源代码是这样的:
This is my text. <strong>This part is bold.</strong> This part isn't.我可以通过按CTRL+B来突出显示加粗的部分并取消加粗。但是,如果我向该强标记添加一个类(由于我正在开发的另一个插件),我只能取消加粗清除强标记-没有属性、样式或类。例如,考虑以下场景:
This is my text. <strong>This part is bold.</strong> This part isn't. <strong class="whatever">This part is bolded AND has a custom class.</strong>只有第一个加粗的分段是不加粗的--第二个被卡住了,直到我删除了".whatever“类。有没有办法让它忽略带有类的强标签,而不管它们有什么其他属性?我猜这和“高级内容过滤器”或者别的什么有关,但是我不知道是什么。
发布于 2014-04-02 14:02:48
几经思索,我想我找到了答案。在CKEDITOR样式定义中,应用的样式(例如,强标记)需要通过内容过滤器解析其所有属性。如果某个未被此过滤器处理的属性在实际从样式标记中删除样式并将其替换回父元素the tags (and thus the style) will NOT be removed if there are any attributes remaining on the element时仍然存在。对此有一个(文档非常少)的解决方法: alwaysRemoveElement属性可以是set to true on the style DEFINITION (为什么是定义,而不是样式本身,我不知道)。
长话短说,这是一小段代码,它将强制删除所有样式标记,即使它们的属性与过滤器不完全匹配。希望它不会在其他地方引起bug……
//this = Your Editor Instance
this.data.editor.on( 'instanceReady', function(){
//Filter through the existing contentRules, looking for styleCommands
$.each(this.activeFilter.allowedContent, function(i,v) {
var name = v.featureName, command = this.commands[v.featureName];
if (name && command && command.contentForms && command.style) {
command.style._.definition.alwaysRemoveElement = true;
}
}.bind(this));
}.bind(this));发布于 2017-09-27 21:38:32
与前面的答案一样,只需在配置中添加以下内容:
CKEDITOR.config.coreStyles_bold : { element: 'strong', overrides: 'b' ,alwaysRemoveElement: true},我也很难找到这个变通方法,在我的例子中,我向强元素添加了一个id。
https://stackoverflow.com/questions/22799264
复制相似问题