JS代码格式化和语法着色V2

2019-06-03 18:16:39王旭

{ outputLn(str); str=" "; }   stopExec();  }
} function outputLn(theStr)
{  var seq, txt, fn;  if(html2txt(theStr).match(/^[ trn]*$/))
return;  seq=document.createElement
("p");  seq.innerHTML=theStr;  curRe.appendChild
(seq);    txt=html2txt(theStr);  if(!txt)return;  fn=txt.match
(/function[ trn]+([.w]+?)[ trn]*(.*?)[ trn]*{/);  if(fn)
{   glbFuntionNames.push(fn[1]);   selJSExport.options[selJSExport.options.length]
=new Option(fn[0]+"}",fn[1]);   selJSExport.options[selJSExport.options.length-
1].obj=seq;  }  fn=txt.match(/([.w]+?)[ trn]*=[ trn]*functionW*(.*?)
[ trn]*{/);  if(fn){   glbFuntionNames.push(fn
[1]);   selJSExport.options[selJSExport.options.length]=new Option(fn[0]+"}",fn
[1]);   selJSExport.options[selJSExport.options.length-1].obj=seq;  } }
function clKW(str){ return(str.charAt(0)
+"<span class="keyWord">"+str.substring(1)+"</span>"); }
function clObj(str){ return(str.charAt(0)
+"<span class="object">"+str.substring(1)+"</span>"); }
function clMP(str){ return(str.charAt(0)
+"<span class="method_property">"+str.substring(1)+"</span>"); }
function clOP(str){ return(str.charAt(0)
+"<span class="operator">"+str.substring(1)+"</span>"); }
//------------------ // global scripts //------------------
function maximizeWindow(){  window.moveTo(0,0);  window.resizeTo
(screen.availWidth,screen.availHeight); } function htmlEncode(strS){  return
(strS.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace
(/>/g,"&gt;").replace(/ /g,"&nbsp;").replace(/
rn/g,"<br/>")); } function html2txt(strS){  return
(strS.replace(/<.+?>/g,"").replace(/&lt;/g,"<").replace
(/&gt;/g,">").replace(/&nbsp;/g," ").replace(/<br/?>/g,"rn").replace
(/&amp;/g,"&")); }