惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 三生石上(FineUI控件)
云风的 BLOG
云风的 BLOG
C
Check Point Blog
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Forbes - Security
Forbes - Security
IT之家
IT之家
L
LINUX DO - 最新话题
N
News and Events Feed by Topic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
雷峰网
雷峰网
N
News | PayPal Newsroom
The Last Watchdog
The Last Watchdog
V
Visual Studio Blog
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
TaoSecurity Blog
TaoSecurity Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Schneier on Security
Schneier on Security
P
Privacy International News Feed
G
Google Developers Blog
博客园 - 聂微东
博客园 - 叶小钗
M
MIT News - Artificial intelligence
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Simon Willison's Weblog
Simon Willison's Weblog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
H
Hacker News: Front Page
Martin Fowler
Martin Fowler
L
Lohrmann on Cybersecurity
G
GRAHAM CLULEY
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
T
The Exploit Database - CXSecurity.com
S
Security @ Cisco Blogs
博客园_首页
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
T
Threatpost

博客园 - 努力前上

button按回车触发后台 - 努力前上 - 博客园 Connectionstrings - 努力前上 - 博客园 [C#]包含DataSet类的XML架构怎么不自动生成CS文件了(XSD和CS文件不能合并) Asp.Net 备份和恢复SQL SERVER 数据库 提取HTML代码中文字的C#函数 (转) - 努力前上 - 博客园 危险字符过滤的类(最新完善版)(1) Tree使用 常用的一些javascript小技巧(转) 利用TreeView控件动态生成无限级树(续:通过绑定动态xml文件)(转) - 努力前上 - 博客园 利用TreeView控件动态生成无限级树(转) - 努力前上 - 博客园 Microsfot.Web.UI.WebControls.TreeView JavaScript控制方法研究(转) (二)execCommand()函数可用参数大解析 JavaScript--execCommand指令集 JS 无刷新排序 js 技巧杂引(转) DataGrid 颜色交替 DataGrid双击事件 javascript调用webservice [垃圾猪]防盗链IHttpHandler源码
HTML代码过滤函数
努力前上 · 2005-12-15 · via 博客园 - 努力前上

/////////////////////////////////////////////////////////////////////
//
//  在线编辑器过滤函数:FiltrationHTML
//  作用:把从word、IE拷贝来的数据过滤,保留需要的标记及属性,去掉多
//        余,统一页面样式。
//  过滤:保留<p><sup><sub><table><tr><td><img><br>标记,以及<td>中的
//        colspan、rowspan属性,其它标记及属性全部清除。为表格替换统
//        一样式。
//  原理:先用特殊字符串"『〈"和"〉』"替换需要保留的标记"<"和">",然
//        后去掉不需要的,再把特殊字符恢复原状。这种字符串组合基本可
//        以避免被用户误输入,也可换成其它的。
//  缺点:过滤还不是特别全面。因为要复制的内容千变万化,有些特殊情况
//        没有解决。
//        在线编辑器会自动产生某些标记,<TBODY><a>,无法解决。
//  最后修改时间:2004.7.26 土狗
//
/////////////////////////////////////////////////////////////////////
function FiltrationHTML(HTML)
{
 var temp = HTML;
 temp = temp.replace(/<script[^>]*?>(.|\n)*?<\/script>/gim,""); //过滤<script></script>块
 temp = temp.replace(/<(p |p>)/gi,  "『〈$1"); //分段  <p>
 temp = temp.replace(/<(\/p)/gi,   "『〈$1"); //分段  </p>
 temp = temp.replace(/<(sup>)/gi,  "『〈$1"); //上标  <sup>
 temp = temp.replace(/<(\/sup)/gi,  "『〈$1"); //上标末 </sup>
 temp = temp.replace(/<(sub)/gi,   "『〈$1"); //下标  <sub>
 temp = temp.replace(/<(\/sub)/gi,  "『〈$1"); //下标末 </sub>
 temp = temp.replace(/<(table)/gi,  "『〈$1"); //表格  <table>
 temp = temp.replace(/<(\/table)/gi, "『〈$1"); //表格末 </table>
 temp = temp.replace(/<(tr |tr>)/gi, "『〈$1"); //行   <tr>
 temp = temp.replace(/<(\/tr)/gi,  "『〈$1"); //行末  </tr>
 temp = temp.replace(/<(td |td>)/gi, "『〈$1");//列    <td>
 temp = temp.replace(/<(\/td)/gi,  "『〈$1"); //列末  </td>
 temp = temp.replace(/<(img )/gi,  "『〈$1"); //图片  <img>
 temp = temp.replace(/<(br)/gi,   "『〈$1"); //换行符 <br>
 temp = temp.replace(/(『〈[^>]*)>/gi,"$1〉』"); //右括号

 temp = temp.replace(/<[^>]*>/gi,"");   //过滤其它所有"<...>"标签
 temp = temp.replace(/\&nbsp;/gi," ");   //替换所有&nbsp;为空格

 temp = temp.replace(/『〈/gi,"<");    //恢复<
 temp = temp.replace(/〉』/gi,">");    //恢复>

 temp = temp.replace(/(<table)[^>]*(>)/gi,"$1 border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"border-collapse: collapse\" bordercolor=\"#333333\" width=\"100\%\"$2"); //清除表格属性并加样式
 temp = temp.replace(/(<[^>]*)colspan(=[^\s>]*)/gi,"$1 『col$2』"); //给<td>中需要的属性加『』
 temp = temp.replace(/(<[^>]*)rowspan(=[^\s>]*)/gi,"$1 『row$2』"); //给<td>中需要的属性加『』

 temp = temp.replace(/(<tr)[^>]*(>)/gi,"$1$2");    //清除TR属性
 temp = temp.replace(/(<td)[^>『]*(>)/gi,"$1$2");   //清除不包含『』的TD的属性
 temp = temp.replace(/(<td)[^>『]*『/gi,"$1『");    //替换 <td...『之间内容
 temp = temp.replace(/(<[^>』]*』)[^>]*(『[^>『]*>)/gi,"$1$2");  //替换『』...『』之间内容
 temp = temp.replace(/(』)[^>』]*(>)/gi,"$1$2");    //替换『』...>之间内容
 temp = temp.replace(/<p[^>]*>/gi,"<p>");    //清除<p>中多余属性

 temp = temp.replace(/『(col)(=\d{1,4})』/gi," $1"+"span"+"$2");  //还原  colspan
 temp = temp.replace(/『(row)(=\d{1,4})』/gi," $1"+"span"+"$2");  //还原  rowspan
 temp = temp.replace(/(<img)[^>]*(>)/gi,"$1 src=\"\""+"$2");  //替换  <img>
 
 return temp;
}