//html 转换
namespace string.html
 
var rep = ..string.replace;
var removeTagAux ;
removeTagAux = function(html,tag,...){ 
    html = rep(html, "\<\s*"+tag+"[^\>]*?\s*\>.*?\<\s*/"+tag+"\s*>",""); 
    html = rep(html, "\<\s*"+tag+"[^\>]*?\s*\>.+",""); 
    if(!...)
     	return html;
    return removeTagAux( html,...);
}

removeTag = function(html,tag,...){
    html = removeTagAux( html,..string.lower(tag),..string.upper(tag) )
    if(!...)
     	return html;
    return removeTag(html,...);
} 

toText = function(html){ 

	//清除无效标记
	html = removeTag(html,"head","style","script");
	
	//转换所有空格换行
	html = rep(html, 
    	"\<\s*pre[^\>]*?\s*\>(.*?)\<\s*/pre\s*>",
    	function(c){
     		c = rep(c," ","&nbsp;");
     		c = rep(c,'\n',"<br>");
     		return c;
    	}
	);  
	html = rep(html,"\s+"," ");
	html = rep(html,"\<[bB][rR]\s*/*\>",'\r\n');
	html = rep(html,"\</*[pP]\>",'\r\n');
	html = rep(html,"\</div\>",'\r\n');
	html = rep(html,"\</DIV\>",'\r\n');
	
	//清除所有HTML标记
	html = rep(html,"\<.+?\>","");
	
	//转换特殊字符
	html = rep(html,"&amp;",'&');
	html = rep(html,"&nbsp;",' ');
	html = rep(html,"&quot;",'"');
	html = rep(html,"&lt;",'<');
	html = rep(html,"&gt;",'>'); 
	html = rep(html,"&iexcl;",'\xa1');
	html = rep(html,"&cent;",'\xa2');
	html = rep(html,"&pound;",'\xa3');
	html = rep(html,"&copy;",'\xa9');
	html = rep(html,"&frasl;","/")
	html = rep(html,"&raquo;","▼")
	html = rep(html,"&[a-zA-Z]+;","");     	
	html = rep(html,
    	"&#(\d+);",
    	function(c){
     		return ..string.pack((tonumber(c))) 
    	} 
	); 
	
	return html;
}

fromText = function(txt){
	txt = rep(txt,"@&",'&amp;');
	txt = rep(txt,'@<',"&lt;");
	txt = rep(txt,'@>',"&gt;");
	txt = rep(txt," ","&nbsp;");
	txt = rep(txt,'\n',"<br>");
	return txt;
}

/**intellisense(string.html)
toText(__/*HTML代码*/) = 将HTML代码转换为文本
fromText(__/*普通文本*/) = 将普通文本转换为HTML
removeTag(html,"script__") = 移除指定的html标记,支持不定个数的标记参数
end intellisense**/
