2014-04-02 56 views
0

如果事情我在CKEDITOR编写源看起来是这样的标签: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”级。有没有办法让它忽略带有类的强标签,并且只要做到这一点,而不管它们具有什么其他属性?我猜它必须与“高级内容过滤器”有关,但我无法弄清楚。

回答

0

经过大量的发片,我(想)我有答案。在CKEDITOR样式定义中,应用样式(例如,强标签)需要通过内容过滤器分析其所有属性。如果某个属性未被此过滤器处理,则需要从样式标记中实际删除textNode并将其替换回父元素。有一个(非常糟糕的)解决方法:alwaysRemoveElement属性可以是set to true on the style DEFINITION(为什么定义,而不是风格本身,我不知道)。

长话短说,一小段代码将强制删除所有样式标记,即使它们的属性与过滤器不完全匹配。但愿它不会导致错误别的地方...

//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)); 
0

由于以前的答案,只需添加这在配置:

CKEDITOR.config.coreStyles_bold : { element: 'strong', overrides: 'b' ,alwaysRemoveElement: true}, 

这也是我很难找到这种解决方法,在我的情况是我为强壮的元素添加了一个id。