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

推荐订阅源

T
Troy Hunt's Blog
T
The Blog of Author Tim Ferriss
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
博客园 - 【当耐特】
D
DataBreaches.Net
Vercel News
Vercel News
IT之家
IT之家
博客园_首页
aimingoo的专栏
aimingoo的专栏
GbyAI
GbyAI
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
爱范儿
爱范儿
The Cloudflare Blog
V
Visual Studio Blog
大猫的无限游戏
大猫的无限游戏
Last Week in AI
Last Week in AI
小众软件
小众软件
V
V2EX
SecWiki News
SecWiki News
L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
A
About on SuperTechFans
博客园 - 司徒正美
雷峰网
雷峰网
Cloudbric
Cloudbric
Engineering at Meta
Engineering at Meta
Apple Machine Learning Research
Apple Machine Learning Research
T
The Exploit Database - CXSecurity.com
Google DeepMind News
Google DeepMind News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cisco Talos Blog
Cisco Talos Blog
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
PCI Perspectives
PCI Perspectives
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
P
Privacy & Cybersecurity Law Blog
The Register - Security
The Register - Security
N
Netflix TechBlog - Medium
C
Cyber Attacks, Cyber Crime and Cyber Security
U
Unit 42
The GitHub Blog
The GitHub Blog
P
Privacy International News Feed
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - 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;
}