最近项目需要拿ueditor做一些个性化功能,在此特意把修改的内容记录在这,一来方便自己知道改动过的地方,二来也是希望后来者如何需要做到类似的功能可以直接拿去用了。
在ueditor.config.js中找到“filterTxtRules”配置,并修改为以下代码
1 filterTxtRules : function(){ 2 function transP(node){ 3 node.tagName = ‘p‘; 4 node.attrs=‘‘; //清空所有属性 5 node.setStyle(); 6 } 7 return { 8 //直接删除及其字节点内容 9 ‘-‘ : ‘script style object iframe embed input select‘, 10 ‘p‘: function(node){ 11 node.attrs=‘‘; //清空粘贴内容中p元素所带的属性 12 }, 13 ‘img‘:function(node){ 14 node.attrs[‘class‘]=‘‘;//清除class属性,此处不能使用node.attrs.class=‘‘,在ie8下报错,因为class是关键字 15 node.attrs[‘style‘]=‘‘;//清除style属性 16 node.setStyle(); 17 }, 18 ‘br‘:{‘$‘:{}}, 19 ‘div‘:{‘$‘:{}}, 20 ‘li‘:{‘$‘:{}}, 21 ‘caption‘:transP, 22 ‘th‘:transP, 23 ‘tr‘:transP, 24 ‘h1‘:transP,‘h2‘:transP,‘h3‘:transP,‘h4‘:transP,‘h5‘:transP,‘h6‘:transP, 25 ‘td‘:function(node){ 26 //没有内容的td直接删掉 27 var txt = !!node.innerText(); 28 if(txt){ 29 node.parentNode.insertAfter(UE.uNode.createText(‘ ‘),node); 30 } 31 node.parentNode.removeChild(node,node.innerText()) 32 } 33 } 34 }()
原文:http://www.cnblogs.com/zhouzone/p/4866131.html