(function($){
$.aisensiyCodeHighLight = function(code, holder) {
var keyWords = [
"boolean", "int", "long", "short", "byte", "float", "double",
"var", "function", "return", "public", "static", "void", "protected",
"private", "extends", "for", "in", "while", "if", "else", "then", "new",
"false", "true", "null", "break", "continue", "goto", "switch", "case",
"integer", "implements", "synchronized", "package", "catch", "try", "finnal",
"using", "bool", "get", "set", "enum", "struct"
];
var settings = {
regs: {
"keyWord": {
"pattern": new RegExp("\\b(" + keyWords.join("\\b|\\b") + ")\\b", "ig"),
"class": "keyWord"
},
"lineComment": {
"pattern": /[^:](\/\/.*)/g
},
"globalComentHead": {
"pattern": /(\/\*.*)/g
},
"globalCommentFoot": {
"pattern": /\*\//g
},
"commentClass": "comment",
"string": {
"pattern": /("[^"]*")/g,
"class": "string"
}
},
commentWrap : function(codes) {
var commentFlag = false;
var commentClass = settings.regs.commentClass;
for( var i=0; i<codes.length; i++) {
if(commentFlag)
{
if(codes[i].indexOf("*/") == -1)
codes[i] = codes[i].replace("<li><span>",
"<li><span class=\"" + commentClass + "\">");
else
{
var strBegin = "<li><span>".length;
var strEnd = codes[i].indexOf("*/") + 2 - strBegin;
var end = codes[i].substr(strBegin, strEnd);
codes[i] = codes[i].replace(end, "<span class=\""
+ commentClass + "\">" + end + "</span>" );
commentFlag = false;
}
continue;
}
if(settings.regs.globalComentHead.pattern.test(codes[i]))
{
codes[i] = codes[i].replace(settings.regs.globalComentHead.pattern, "<span class=\"" +
commentClass + "\">$1</span>");
commentFlag = true;
}
}
return codes;
},
xmlEscape: function(s) {
return s.replace(/&/g,"&").replace(/\</g,"<").replace(/\>/g, ">").replace(/ /g," ").replace(/\\"/g, """);
}
};
settings.container = holder;
settings.code = code;
var codes = settings.xmlEscape($.trim(code)).split("\n");
for(var i=0; i<codes.length; i++) {
codes[i] = "<li><span>" + codes[i] + "</span></li>";
codes[i] = codes[i].replace(settings.regs.string.pattern,
"<span class=\"" + settings.regs.string["class"] + "\">$1</span>");
codes[i] = codes[i].replace(settings.regs.keyWord.pattern,
"<span class=\"" + settings.regs.keyWord["class"] + "\">$1</span>");
codes[i] = codes[i].replace(settings.regs.lineComment.pattern,
"<span class=\"" + settings.regs.commentClass + "\">$1</span>");
}
codes = settings.commentWrap(codes);
settings.container.html("<ol>" + codes.join("") + "</ol>");
$("span[class=" + settings.regs.string["class"]+"]", settings.container).each(function(n){
$(this).html($(this).html().replace(/\<\/?[^>]+\>/g, ""));
});
$("span[class=" + settings.regs.commentClass+"]", settings.container).each(function(){
$(this).html($(this).html().replace(/\<\/?[^>]+\>/g, ""));
});
}
})(jQuery);