CKEditor忽略具有类的标签

时间:2014-04-02 00:11:01

标签: 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”类。有没有办法让它忽略带有类的强标签,只要不管它们有什么其他属性就可以做到这一点?我猜这与“高级内容过滤器”有什么关系,但我无法弄清楚是什么。

2 个答案:

答案 0 :(得分:0)

经过多次脱毛后,我(想)我有了答案。在CKEDITOR样式定义中,应用样式(例如,强标记)需要通过内容过滤器解析其所有属性。如果在从样式标记中实际删除textNode并将其替换回父元素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(为什么定义,而不是样式本身,我不知道)。

长话短说,一小段代码将强制删除所有样式标记,即使它们的属性与过滤器不完全匹配。希望它不会在其他地方引起错误...

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

答案 1 :(得分:0)

如上一个答案,只需在配置中添加:

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

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