禁止CKEditor中的特殊字符

时间:2015-05-28 11:27:47

标签: ckeditor

是否可以在CKEditor中禁用一些特殊字符,如♦(♦)或•(•)?
因此用户不应该完全插入它们

1 个答案:

答案 0 :(得分:0)

最后我为此创建了一个自定义插件,希望对某人有所帮助

CKEDITOR.plugins.add('customcontentfilter', {
afterInit: function (editor) {
    var dataProcessor = editor.dataProcessor,
        dataFilter = dataProcessor && dataProcessor.dataFilter,
        htmlFilter = dataProcessor && dataProcessor.htmlFilter,
        legalCharacters = editor.config.customValues && editor.config.customValues.CKEditorLegalCharacters,
        illegalCharactersRegex = new RegExp("[^" + legalCharacters + "]", "g");

    if (dataFilter) {
        dataFilter.addRules({
            text: function (text) {
                return text.replace(illegalCharactersRegex, '');
            }
        });
    }

    if (htmlFilter) {
        htmlFilter.addRules({
            text: function (text) {
                return text.replace(illegalCharactersRegex, '');
            }
        });
    }
}

});

CKEDITOR.replace('Description', {
    customValues: { CKEditorLegalCharacters: "\u0020-\u02AF\" }
});