|
最新版才支持的功能,请先更新 aardio 再测试,
先看看写的这么任性的HTML,解析并格式化的效果:
import console;
var html = /*
<table>
<caption>37547 TEE Electric Powered Rail Car Train Functions (Abbreviated)
<colgroup><col><col><col>
<thead>
<tr>
<th>Function
<th>Control Unit
<th>Central Station
<tbody>
<tr>
<td>Headlights
<td>✔
<td>✔
<tr>
<td>Interior Lights
<td>✔
<td>✔
<tr>
<td>Electric locomotive operating sounds
<td>✔
<td>✔
<tr>
<td>Engineer’s cab lighting
<td>
<td>✔
<tr>
<td>Station Announcements - Swiss
<td>
<td>✔
</table>
*/
import string.html;
var htmlDoc = string.html( html )
console.log( htmlDoc.outerXml(true) )
console.more(1)
再来一个: import console;
var html = /*
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <style type="text/css">
html,body{ height:100%; margin:0; }
</style> <script type="text/javascript"></script>
<body><div id="header"></div> <div id="container">
<br>
<div class="lside">
<span>aaaaaaaaaa<span>aaaaaaaaaaaaaaaaaaaaa</span>aaaaaaaaaaa</span>
</div> <div class="rside"> </div>
</div>
*/
import string.html;
var htmlDoc = string.html( html )
console.log( htmlDoc.outerXml(true) )
console.more(1)
来个大的: import win.ui;
/*DSG{{*/
var winform = win.form(text="格式化HTML";right=759;bottom=469)
winform.add(
button={cls="button";text="格式化HTML";left=504;top=432;right=704;bottom=464;db=1;dr=1;z=2};
richedit={cls="richedit";left=16;top=8;right=752;bottom=424;db=1;dl=1;dr=1;dt=1;edge=1;hscroll=1;multiline=1;vscroll=1;z=1}
)
/*}}*/
winform.button.oncommand = function(id,event){
import web.rest.client;
import string.html;
var html = web.rest.client().get("http://www.qq.com");
var doc = string.html(html)
winform.richedit.text = doc.outerXml(true)
}
winform.show()
win.loopMessage();
注意,只要反过来用 htmlDoc.outerXml(false,"") 就可以实现压缩HTML的功能
|
|