首页 > 开发 > HTML > 正文

清除word粘多html代的ClearWord函

2020-10-03 17:39:04
字体:
来源:转载
供稿:网友
我在利用FckEditor器的候有一清除Word粘的多html代的功能,它是利用javascript的。有了功能以後,我的容可以直接Word拷粘而不用心容有一大堆多的西料空影行的性能了。

那,我照了Fckeditor的javascript功能了CFScript功能版本的ClearWord函,利用函在面容添加入可以直接行清除冗操作了。

<!--- 
/***********************************************************
* 面功能         : 清除word粘多html代 
* 作者                : 子心(方恩) 
* 版本                : 1.0 
* 建         : 2005-11-29 
* 作者主         : http://www.cfcodes.com 
* 箱         : chinavane@msn.com 
* Msn          : chinavane@msn.com 
* Oicq         : 13525442
* 史版本         : 

 *                 :[html] 有Word冗代的html容 
***********************************************************/ 
--->
<cfscript>
    function CleanWord(html) 
    { 
        html = REReplaceNocase(html,'<o:p>s*</o:p>','','all'); 
        html = REReplaceNocase(html,'<o:p>.*?</o:p>','&nbsp;','all'); 
        html = REReplaceNocase(html,'s*mso-[^:]+:[^;"]+;?','','all'); 
        html = REReplaceNocase(html,'s*MARGIN: 0cm 0cm 0pts*;','','all'); 
        html = REReplaceNocase(html,'s*MARGIN: 0cm 0cm 0pts*"','""','all'); 
        html = REReplaceNocase(html,'s*TEXT-INDENT: 0cms*;','','all'); 
        html = REReplaceNocase(html,'s*TEXT-INDENT: 0cms*"','""','all'); 
        html = REReplaceNocase(html,'s*TEXT-ALIGN: [^s;]+;?"','""','all'); 
        html = REReplaceNocase(html,'s*PAGE-BREAK-BEFORE: [^s;]+;?"','""','all'); 
        html = REReplaceNocase(html,'s*FONT-VARIANT: [^s;]+;?"','""','all'); 
        html = REReplaceNocase(html,'s*tab-stops:[^;"]*;?','','all'); 
        html = REReplaceNocase(html,'s*tab-stops:[^"]*','','all'); 
        html = REReplaceNocase(html,'s*face="[^"]*"','','all'); 
        html = REReplaceNocase(html,'s*face=[^ >]*','','all'); 
        html = REReplaceNocase(html,'s*FONT-FAMILY:[^;"]*;?','','all'); 
        html = REReplaceNocase(html,'<(w[^>]*) class=([^ |>]*)([^>]*)','<1','all'); 
        html = REReplaceNocase(html,'<(w[^>]*) style="([^""]*)"([^>]*)','<1','all'); 
        html = REReplaceNocase(html,'s*style="s*"','','all'); 
        html = REReplaceNocase(html,'<SPANs*[^>]*>s*&nbsp;s*</SPAN>','&nbsp;','all'); 
        html = REReplaceNocase(html,'<SPANs*[^>]*></SPAN>','','all'); 
        html = REReplaceNocase(html,'<(w[^>]*) lang=([^ |>]*)([^>]*)','<1','all'); 
        html = REReplaceNocase(html,'<SPANs*>(.*?)</SPAN>','1','all'); 
        html = REReplaceNocase(html,'<FONTs*>(.*?)</FONT>','1','all'); 
        html = REReplaceNocase(html,'</??xml[^>]*>','','all'); 
        html = REReplaceNocase(html,'</?w+:[^>]*>','','all'); 
        html = REReplaceNocase(html,'<Hd>s*</Hd>','','all');   
        html = REReplaceNocase(html,'<H1([^>]*)>','<div1><b><font size="6">','all'); 
        html = REReplaceNocase(html,'<H2([^>]*)>','<div1><b><font size="5">','all'); 
        html = REReplaceNocase(html,'<H3([^>]*)>','<div1><b><font size="4">','all'); 
        html = REReplaceNocase(html,'<H4([^>]*)>','<div1><b><font size="3">','all'); 
        html = REReplaceNocase(html,'<H5([^>]*)>','<div1><b><font size="2">','all'); 
        html = REReplaceNocase(html,'<H6([^>]*)>','<div1><b><font size="1">','all');            
        html = REReplaceNocase(html,'</Hd>','</font></b></div>','all'); 
        html = REReplaceNocase(html,'<(U|I|STRIKE)>&nbsp;</1>','&nbsp;','all'); 
        html = REReplaceNocase(html,'<([^s>]+)[^>]*>s*</1>','','all'); 
        html = REReplaceNocase(html,'<([^s>]+)[^>]*>s*</1>','','all'); 
        html = REReplaceNocase(html,'<([^s>]+)[^>]*>s*</1>','','all'); 
        html = REReplaceNocase(html,'(<P)([^>]*>.*?)(</P>)','<div2</div>','all'); 
        return html; 
    }
</cfscript>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表