將html轉化成UBB(windy2000)

來源:互聯網
上載者:User

<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="轉換剪下版超文本資料" onclick="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" onclick="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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.