Heim > Artikel > Web-Frontend > JavaScript版代码高亮_JavaScript
return htmlTxt.join("");
}
this.isStartWith = function(str,code,index){
if(typeof(str)!="undefined"&&str.length>0){
for(var i=0;i
if(str.charAt(i)!=code[index+i]||(index+i>=code.length)){
return false;
}
} else {
if(str.charAt(i).toLowerCase()!=code[index+i].toLowerCase()||(index+i>=code.length)){
return false;
}
}
}
return true;
} else {
return false;
}
}
this.isKeyword = function(val){
return this._keywords.contains(this._caseSensitive?val:val.toLowerCase());
}
this.isCommonObject = function(val){
return this._commonObjects.contains(this._caseSensitive?val:val.toLowerCase());
}
this.isTag = function(val){
return this._tags.contains(val.toLowerCase());
}
}
function doHighlight(o, syntax){
var htmltxt = "";
if(o == null){
alert("domNode is null!");
return;
}
var _codetxt = "";
if(typeof(o)=="object"){
switch(o.tagName){
case "TEXTAREA":
case "INPUT":
_codetxt = o.value;
break;
case "DIV":
case "SPAN":
_codetxt = o.innerText;
break;
default:
_codetxt = o.innerHTML;
break;
}
}else{
_codetxt = o;
}
var _syn = new CLASS_HIGHLIGHT(_codetxt,syntax);
htmltxt = _syn.highlight();
return htmltxt;
}
function goit(stx){
var code = document.getElementById("m").innerText;
var xx = new CLASS_HIGHLIGHT(code,stx);
document.getElementById("highlight").innerHTML = xx.highlight();
}