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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Darknet – Hacking Tools, Hacker News & Cyber Security
N
News and Events Feed by Topic
N
News | PayPal Newsroom
SecWiki News
SecWiki News
P
Privacy International News Feed
T
Troy Hunt's Blog
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
L
LINUX DO - 热门话题
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Security Latest
Security Latest
AWS News Blog
AWS News Blog
S
Secure Thoughts
W
WeLiveSecurity
H
Heimdal Security Blog
T
Threat Research - Cisco Blogs
I
Intezer
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Security @ Cisco Blogs
G
GRAHAM CLULEY
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Spread Privacy
Spread Privacy
L
Lohrmann on Cybersecurity
C
CERT Recently Published Vulnerability Notes
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google Online Security Blog
Google Online Security Blog
Cisco Talos Blog
Cisco Talos Blog
雷峰网
雷峰网
Cloudbric
Cloudbric
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google DeepMind News
Google DeepMind News
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
Latest news
Latest news
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
D
Docker
Recent Announcements
Recent Announcements
博客园 - 【当耐特】
H
Help Net Security
博客园 - 司徒正美
TaoSecurity Blog
TaoSecurity Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Check Point Blog
博客园 - 叶小钗

博客园 - 努力前上

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;
}