直接轉為高亮版,IE+FF+Cr 測試通過:
代碼:
程式碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 過渡//EN"
「 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd 」 >
<html xmlns=" http://www.w3.org/1999/xhtml ">
<頭>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<標題>普雷(al)</標題>
<樣式類型=“文字/css”>
pre.preh{font-family:Consolas,"Lucida Console",monospace;}
pre.preh ol{邊框:1px 實心#ddd;邊距:0;填滿:0 0 0 4em;顏色:灰色;}
pre.preh ol li{行高:1.75em;邊框底部:1px實心#ddd;邊框左:1px實心#ddd;}
pre.preh ol li span{color:black;white-space:pre;}
pre.preh ol li span span.regexp{背景:綠色;顏色:白色}
pre.preh ol li span em{顏色:藍色;字體樣式:正常;}
pre.preh ol li span var.object{color:red}
pre.preh ol li span var.method_property{color:orange}
pre.preh ol li span.comments{color:#aaa}
pre.preh li var{顏色:藍色;字型樣式:正常;}
pre.preh li q{顏色:綠色;}
q:之前{內容:無;顯示:無;}
</風格>
<!--[如果是IE]> <style>pre.preh{font-family:fixedsys,monospace}</style> <![endif]-->
<腳本>
//關鍵字
var 關鍵字 = {js:{},html:{},css:{}};
keywords.js.keys="abstract break byte case catch char class const continue default delete do double else extends false Finalfinally float for function goto if 實作了 ininstanceof int 介面中的導入 pack none nactage longpprivates這拋出瞬態true try var void while with";
keywords.js.objects="錨點Applet 區域參數數組布林按鈕複選框集合加密日期字典文檔驅動器驅動器元素枚舉器事件文件FileObject FileSystemObject FileUpload 資料夾資料夾表單框架函數全域隱藏歷史記錄HTMLElement 圖像無限輸入JavaArray JavaClass JavaObject JavaPackage JSObject 層連結數學MimeType導航器 編號 物件 選項包 密碼外掛程式 PrivilegeManager 隨機正規表示式 螢幕選擇字串 提交文字 文字區域 URL VBArray 視窗 WScript";
keywords.js.properties =「上面abs acos操作activeElement警報alinkColor所有altKey錨點錨點appCodeName小程式應用appName appVersion參數arity asin分配atan atan2 atobvailHeightavailLeftavailTopavailWidthActiveaObjectbtoaltomobgColbids呼叫者呼叫者 cancelBubble captureEvents ceil charAt charCodeAt 字元集已檢查子類別 classNameclearclearIntervalclearTimeoutclickclientInformationclientXclientYcloseclosecolorDepth編譯完成concat設定建構函式包含上下文E Echo元素元素嵌入enabledPlugin enableExternalCapture enablePrivilege 編碼轉義eval 事件exec exp Expando FromPoint fgColor fileName 尋找固定底部焦點fontColor fontSize 表單表單轉送幀fromCharCode fromElement getAttribute get getClass getDate getDay getFullYear getHours getMember getMilliseconds getMinutes getMonth getSeconds getat getSeconds get getpixel get get getSeconds getool getSecondsd UTCHours getUTCMilliseconds getUTCMinutes getUTCMonth getUTCSeconds getWindow getYear global go HandleEvent Height hash 隱藏歷史記錄home host hostName href hspace id idsignoreCase images index IndexOf inside insideHTML insideText insideWidth insertAdjacentHTML insertAdjacentText isFinite isNAN italics java javaEnabled join keyCode 連結LN10 LN2 10Ep層layerX layerY left leftContext 長度連結linkColor 載入位置locationBar log lowsrc MAX_VALUE MIN_VALUE 邊距匹配最大選單列方法mimeTypes min 修飾符moveAbove moveBelow moveBy moveTo moveToAbsolute 多行NaN NEGATIVE_INFINITY 名稱導航navigator netscape next number offscreenBuffering setOffsetHeight setLeft blclick ondragdrop onerror onfocus onHelp onkeydown按鍵onkeyup onload onmousedown onmousemove onmouseout onmouseover onmouseup onmove onreset onresize onsubmit onunload 開啟開啟程式選項outerHeight outerHTML outerText outerWidth POSITIVE_INFINITY PI paddings pageX pageXOffset pageY yState原因引用者刷新releaseEvents重新載入removeAttribute刪除成員resizeBy resizeTo returnValue反轉右右上下文SQRT1_2 SQRT2 screenX screenY滾動捲動條scrollBy rollIntoView滾動搜尋選擇選定的selectedIndex self setAttribute setDay setFullYear setHotkeys setHours Intersetm Mursk setizersSm set sets setMurs sets 3thMurssets setTime setTimeout setUTCDate setUTCFullYear setUTCHours setUTCMillseconds setUTCMinutes setUTCMonth setUTCSeconds setYear setZOptionsshiftshiftKeysiblingAbovesiblingBelowsignTextsin切片smallsort原始碼sourceIndexsplicesplitsqrtsrcsrcElementsrcFilter狀態statusbarstopstrike樣式subsubsubstr子字串後綴sunsupsystemLanguageTYPEtagName標籤tainttaintEnabledtan目標測試文字標題toElementtoGMTStringtoLocaleStringtoLowerCaseTone StringtoUptoUpperCift tocTC unnad value valueOfvisibility vlinkColor vspace watch 哪個寬度視窗寫入 writeln zIndex";
函數 htmlEncode(strS){
return strS.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
}
函數 htmlEncodef(c){
返回 c=="&"?'&':(c=="<"?'<':(c=='>'?'>':c));
}
函數 htmlEncodefl(c){
返回 c=="&"?5:(c=="<"||c=='>'?4:1);
}
函數 html2txt(strS){
return strS.replace(/</g,"<").replace(/>/g,">").replace(/ /g," ").replace(/<br/?>/g," rn").replace(/&/g,"&").replace(/<.+?>/g,"");
}
var 詞法分析器 = {}
lexers.js = {
regKW:new RegExp("^("+keywords.js.keys.replace(/ /g,"|")+")$","g"),
regObj:new RegExp("^("+keywords.js.objects.replace(/ /g,"|")+")$","g"),
regMP:new RegExp("^("+keywords.js.properties.replace(/ /g,"|")+")$","g"),
clKW:'<em>$1</em>',
clObj:'<var class="object">$1</var>',
clMP:'<var class="method_property">$1</var>',
詞法:函數{
var str=" ", c="",word='',lastState="", seq, intNextQuote, intTemp, intCount, intWordStart,glbStr=s,i;
glbStr=glbStr.replace(/r|n/g,'rn');
glbStr=glbStr.replace(/rnrn/g,'rn');
for(i=0;i<glbStr.length;i++){
c=glbStr.charAt(i);
開關(c){
案件 ”””:
str+=htmlEncodef(c);
intNextQuote=i;
while(intNextQuote!=-1&&intNextQuote<glbStr.length){
intNextQuote=glbStr.indexOf(""",intNextQuote+1);
if(intNextQuote==-1||glbStr.charAt(intNextQuote-1)!=" \")break ;
整數計數=0; intTemp=intNextQuote;
while(glbStr.charAt(--intTemp)==" \")intCount ++;
if(intCount%2==0)break;
}
if(intNextQuote==-1)break;
str+="<q>"+htmlEncode(glbStr.substring(i+1,intNextQuote))+"</q>"";
我=intNextQuote;
最後狀態=“”;
休息;
案件 ”'”:
str+=htmlEncodef(c);
intNextQuote=i;
while(intNextQuote!=-1&&intNextQuote<glbStr.length){
intNextQuote=glbStr.indexOf("'",intNextQuote+1);
if(intNextQuote==-1||glbStr.charAt(intNextQuote-1)!=" \")break ;
整數計數=0; intTemp=intNextQuote;
while(glbStr.charAt(--intTemp)==" \")intCount ++;
if(intCount%2==0)break;
}
if(intNextQuote==-1)break;
str+="<q>"+htmlEncode(glbStr.substring(i+1,intNextQuote))+"</q>'";
我=intNextQuote;
最後狀態=“”;
休息;
案件 ”/”:
str+=htmlEncodef(c);
if(glbStr.charAt(i+1)=="/"){
intNextQuote=i;
intNextQuote=glbStr.indexOf('rn',intNextQuote+1);
if(intNextQuote==-1)intNextQuote=glbStr.length;
str=str.substring(0,str.length-1);
str+="<span class="comments">/"+htmlEncode(glbStr.substring(i+1,intNextQuote))+"</span>";
我=intNextQuote;
}否則 if(glbStr.charAt(i+1)=="*"){
intNextQuote=i;
intNextQuote=glbStr.indexOf("*/",intNextQuote+1);
if(intNextQuote==-1)回傳;
str=str.substring(0,str.length-1);
str+="<span class="comments">/"+htmlEncode(glbStr.substring(i+1,intNextQuote))+"*/</span>";
i=intNextQuote+1;
}else if(str.match(/(?:(?:[!=(]|</var>|[|,|n|:)[ t]*/$)|^ n?[t]*/$/)){
intNextQuote=i;
while(intNextQuote!=-1&&intNextQuote<glbStr.length){
intNextQuote=glbStr.indexOf("/",intNextQuote+1);
if(intNextQuote==-1||glbStr.charAt(intNextQuote-1)!=" \")break ;
intCount=0;intTemp=intNextQuote;
while(glbStr.charAt(--intTemp)==" \")intCount ++;
if(intCount%2==0)break;
}
if(intNextQuote==-1)break;
str+="<span class="regexp">"+htmlEncode(glbStr.substring(i+1,intNextQuote))+"</span>/";
我=intNextQuote;
最後狀態=“”;
}
最後狀態=“”;
休息;
預設:
if(c.match(/w/))word+=c; //一句話
if(c.match(/W/)){
如果(字!='')
str+=word.replace(this.regKW,this.clKW).replace(this.regObj,this.clObj).replace(this.regMP,this.clMP) + htmlEncodef(c)
否則 str+=htmlEncodef(c);
字='';
}
最後狀態=“”;
休息;
}
}
return str.replace(/(s*r?n)+$/,'');
}
};
函數 str2styled(x,語言){
var _A = 詞法分析器[語言].lex(html2txt(x)).split(/n/);
for(i=0;i<_A.length;i++){_A[i] = '<li><span>'+_A[i].replace(/r/g,'').replace(/ t/g,' ').replace(/ /g,' ')+'</span></li>';}
return '<ol>'+_A.join('')+'</ol>';
}
var $ = function(e){return document.getElementById(e)};
視窗.onload = 函數(){
var pres = document.getElementsByTagName('pre');
for(k=0;k<pres.length;k++)if(pres[k].className.match(/bprehb/))
pres[k].innerHTML = str2styled(pres[k].innerHTML,'js')
}
</腳本>
</頭>
<正文>
<pre id="測試" class="preh js">
var 點 = 函數(){
這個.x = 1;
這個.y = 2;
this.valueOf = function(){return '點:('+x+','+y+')'};
}
如果(c<2)f()
var P = 新點();
警報(P.valueOf());
var rex_factory = function(){return {x:/re/g,y:/rere/g,z:[/re/,/rere/,/rerere/]}};
</pre>
<pre id="test2" class="preh js">
another = '這是另一個例子'
</前>
</正文>
</html>