从WORD或者从网络上复制带表格的文章,会带大量的垃圾代码,而且表格还会变形
虽然编辑器有自带清除格式功能,但会把表格一起清除掉。
我改了编辑器 “清除格式” 的功能,可以过滤大部分的垃圾代码,还可以保留表格。
觉得有用可以看看:
打开images/edit.js
查找- html = html.replace(/\<p>/gi,"[$p]");
- html = html.replace(/\<\/p>/gi,"[$\/p]");
- html = html.replace(/\<br[^>]*>/gi,"[$br]");
- html = html.replace(/\<[^>]*>/g,"");
- html = html.replace(/\[\$p\]/gi,"<p>");
- html = html.replace(/\[\$\/p\]/gi,"<\/p>");
- html = html.replace(/\[\$br\]/gi,"<br>");
- oRTE.document.body.innerHTML = html;
复制代码 用下面代码替换- html = html.replace(/<script[^>]*?>(.|\n)*?<\/script>/gim,"");
- html = html.replace(/<(p |p>)/gi, "『〈$1");
- html = html.replace(/<(\/p)/gi, "『〈$1");
- html = html.replace(/<(sup>)/gi, "『〈$1");
- html = html.replace(/<(\/sup)/gi, "『〈$1");
- html = html.replace(/<(sub)/gi, "『〈$1");
- html = html.replace(/<(\/sub)/gi, "『〈$1");
- html = html.replace(/<(table)/gi, "『〈$1");
- html = html.replace(/<(\/table)/gi, "『〈$1");
- html = html.replace(/<(tr |tr>)/gi, "『〈$1");
- html = html.replace(/<(\/tr)/gi, "『〈$1");
- html = html.replace(/<(td |td>)/gi, "『〈$1");
- html = html.replace(/<(\/td)/gi, "『〈$1");
- html = html.replace(/<(img )/gi, "『〈$1");
- html = html.replace(/<(br)/gi, "『〈$1");
- html = html.replace(/(『〈[^>]*)>/gi,"$1〉』");
- html = html.replace(/<[^>]*>/gi,"");
- html = html.replace(/\ /gi," ");
- html = html.replace(/『〈/gi,"<");
- html = html.replace(/〉』/gi,">");
- html = html.replace(/(<table)[^>]*(>)/gi,"$1 border="1" cellpadding="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#333333" width="100\%"$2");
- html = html.replace(/(<[^>]*)colspan(=[^\s>]*)/gi,"$1 『col$2』");
- html = html.replace(/(<[^>]*)rowspan(=[^\s>]*)/gi,"$1 『row$2』");
- html = html.replace(/(<tr)[^>]*(>)/gi,"$1$2");
- html = html.replace(/(<td)[^>『]*(>)/gi,"$1$2");
- html = html.replace(/(<td)[^>『]*『/gi,"$1『");
- html = html.replace(/(<[^>』]*』)[^>]*(『[^>『]*>)/gi,"$1$2");
- html = html.replace(/(』)[^>』]*(>)/gi,"$1$2");
- html = html.replace(/<p[^>]*>/gi,"<p>");
- html = html.replace(/『(col)(=\d{1,4})』/gi," $1"+"span"+"$2");
- html = html.replace(/『(row)(=\d{1,4})』/gi," $1"+"span"+"$2");
- html = html.replace(/(<img)[^>]*(>)/gi,"$1 src="""+"$2");
复制代码 |