我在" config.js"中配置了 extraAllowedContent 根据正在运行的Advanced Content Filtering指南,允许具有特定类的div元素。
但是,我需要删除任何没有属性的div元素。这可能吗?
答案 0 :(得分:2)
您可以使用匹配功能指定config.disallowedContent
:
CKEDITOR.replace( 'editor1', {
disallowedContent: {
div: {
match: function( el ) {
return CKEDITOR.tools.isEmpty( el.attributes );
}
}
}
} );
虽然它正确地过滤了内容,但出于某种原因(一个错误),它还会禁用Div插件及其对话框。因此,我现在宁愿建议这样的事情:
CKEDITOR.replace( 'editor1', {
on: {
pluginsLoaded: function( evt ) {
var editor = evt.editor,
rules = {
elements: {
div: function( el ) {
if ( CKEDITOR.tools.isEmpty( el.attributes ) ) {
// Return false to get rid of an element with children.
return false;
// The element can also be removed preserving children.
// el.replaceWithChildren();
}
},
}
};
// Filter what comes out of an editor.
editor.dataProcessor.htmlFilter.addRules( rules );
// Filter what comes into an editor.
editor.dataProcessor.dataFilter.addRules( rules );
}
}
} );