将html转化成UBB(windy2000)

<script Language="JavaScript1.2">
//coded by windy_sk <windy_sk@126.com> 20031218

function html_trans(str) {
    str = str.replace(//r/g,"");
    str = str.replace(/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/ig,"");
    str = str.replace(/<script[^>]*?>([/w/W]*?)<//script>/ig,"");
   
    str = str.replace(/<a[^>]+href="([^"]+)"[^>]*>(.*?)<//a>/ig,"/n[url=$1]$2[/url]/n");
   
    str = str.replace(/<font[^>]+color=([^ >]+)[^>]*>(.*?)<//font>/ig,"/n[color=$1]$2[/color]/n");
   
    str = str.replace(/<img[^>]+src="([^"]+)"[^>]*>/ig,"/n[img]$1[/img]/n");
   
    str = str.replace(/<([//]?)b>/ig,"[$1b]");
    str = str.replace(/<([//]?)strong>/ig,"[$1b]");
    str = str.replace(/<([//]?)u>/ig,"[$1u]");
    str = str.replace(/<([//]?)i>/ig,"[$1i]");
   
    str = str.replace(/&nbsp;/g," ");
    str = str.replace(/&amp;/g,"&");
    str = str.replace(/&quot;/g,"/"");
    str = str.replace(/&lt;/g,"<");
    str = str.replace(/&gt;/g,">");
   
    str = str.replace(/<br>/ig,"/n");
    str = str.replace(/<[^>]*?>/g,"");
    str = str.replace(//[url=([^/]]+)/]/n(/[img/]/1/[//img/])/n/[//url/]/g,"$2");
    str = str.replace(//n+/g,"/n");
   
    return str;
}

function trans(){
    var str = "";
    rtf.focus();
    rtf.document.body.innerHTML = "";
    rtf.document.execCommand("paste");
    str = rtf.document.body.innerHTML;
    if(str.length == 0) {
        alert("剪切版不存在超文本数据!");
        return "";
    }
    return html_trans(str);
}
</script>

<textarea style="width:100%; height:200px" id="text" class="textarea" onbeforepaste="if(document.getElementById('x_paste').checked){window.clipboardData.setData('text',trans());this.focus();}"></textarea><br />
<iframe scrolling="no" id="rtf" src="about:blank" MARGINHEIGHT="0" MARGINWIDTH="0" style="width:0px; height:0px;"></iframe>
<input type="button" value="转换剪切版超文本数据" οnclick="document.getElementById('text').value += trans()">
<input type="checkbox" id="x_paste"> <label for="x_paste">启用超文本粘贴转换</label>
<script>
rtf.document.designMode="On";
</script>

 

<script Language="JavaScript1.2">
//coded by windy_sk <windy_sk@126.com> 20031218

function trans() {
    var str = "";
    str = rtf.document.body.innerHTML;
   
    str = str.replace(//s*=/s*/ig,"=");
    str = str.replace(/on(load|click|dbclick|mouseover|mousedown|mouseup)="[^"]+"/ig,"");
    str = str.replace(/<br[ //]?>/ig,"/n");
   
    str = str.replace(/<a[^>]+href="([^"]+)"[^>]*>/ig,"/n[url=$1]");
    str = str.replace(/<//a>/ig,"[/url]/n");
   
    str = str.replace(/<font[^>]+color=([^ >]+)[^>]*>/ig,"/n[color=$1]");
    str = str.replace(/<//font>/ig,"[/color]/n");
   
    str = str.replace(/<img[^>]+src="([^"]+)"[^>]*>/ig,"/n[img]$1[//img]/n");
   
    str = str.replace(/<([//]?)b>/ig,"[$1b]");
    str = str.replace(/<([//]?)strong>/ig,"[$1b]");
    str = str.replace(/<([//]?)u>/ig,"[$1u]");
    str = str.replace(/<([//]?)i>/ig,"[$1i]");
   

    str = str.replace(/&nbsp;/g," ");
    str = str.replace(/&amp;/g,"&");
    str = str.replace(/&quot;/g,"/"");
    str = str.replace(/&lt;/g,"<");
    str = str.replace(/&gt;/g,">");
   
    str = str.replace(/<[^>]*?>/g,"");
    str = str.replace(//r/g,"");
    str = str.replace(//n+/g,"/n");
   
    document.getElementById("txt").value = str;
}
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="45%">请将 copy 的网页粘贴到这里:<br />
      <iframe scrolling="yes" id="rtf" src="about:blank" MARGINHEIGHT="1" MARGINWIDTH="1" class="textarea" style="width:100%; height:200px;"></iframe>
    </td>
    <td width="10%">
      <input type="button" οnclick="trans()" value="转换" />
    </td>
    <td width="45%">
        <textarea style="width:100%; height:200px" id="txt" class="textarea"></textarea>
    </td>
  </tr>
</table>
<script refer>
rtf.document.designMode="On";
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值