我正面临着CKEditor 4的问题,我需要一个没有任何html实体的输出,所以我config.entities = false;在我的配置中添加了,但有些 出现在
偶数config.forcePasteAsPlainText = true;您可以通过键入来检查任何演示
试验测试
例如.
你知道我怎么能防止这种行为吗?
谢谢!
Rei*_*mar 10
这些实体:
// Base HTML entities.
var htmlbase = 'nbsp,gt,lt,amp';
Run Code Online (Sandbox Code Playgroud)
是一个例外.要摆脱它们你可以设置basicEntities: false.但正如文档所说,这是一种不安全的设置.所以,如果你只是想去掉 的话,我应该只使用输出数据的正则表达式(例如,通过添加监听#getData),或者,如果你想更精确,添加自己的规则,htmlFilter就像entities插件在这里所做的.
lme*_*urs 10
基于Reinmars接受的答案和实体插件我创建了一个小插件与HTML过滤器去除多余的 实体.正则表达式可以改进以适应其他情况,所以请编辑这个答案.
/*
* Remove entities which were inserted ie. when removing a space and
* immediately inputting a space.
*
* NB: We could also set config.basicEntities to false, but this is stongly
* adviced against since this also does not turn ie. < into <.
* @link http://stackoverflow.com/a/16468264/328272
*
* Based on StackOverflow answer.
* @link http://stackoverflow.com/a/14549010/328272
*/
CKEDITOR.plugins.add('removeRedundantNBSP', {
afterInit: function(editor) {
var config = editor.config,
dataProcessor = editor.dataProcessor,
htmlFilter = dataProcessor && dataProcessor.htmlFilter;
if (htmlFilter) {
htmlFilter.addRules({
text: function(text) {
return text.replace(/(\w) /g, '$1 ');
}
}, {
applyToAll: true,
excludeNestedEditable: true
});
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16247 次 |
| 最近记录: |