jQuery.fn.highlight=function(o){return $(this).each(function(){var code=$(this);var text=code.html();var lang=code.attr('class');if($.browser.msie){text=code.html().replace(/\r\n/g,'\r\n<br />').replace(/\t/g,'&nbsp;&nbsp;&nbsp;&nbsp;');code.html(text)}text=code.html();if(lang){paint(lang);code.html('<span class="'+lang+'">'+code.html()+'</span>')}else{text=text.replace(/(&lt;\?[\s\S]*?\?&gt;)/g,'<span class="php">$1</span>');code.html(text);if(code.children('.php').length){lang='html'}else{if(text.indexOf('<script')>-1||text.indexOf('<style')>-1){lang='html'}else{lang=detectLang(text)}var detect=true;text='<span class="'+lang+'">'+text+'</span>'}if(lang=='html'){text=detect?text:'<span class="php"></span>'+text;text=text+'<span class="php"></span>';text=text.replace(/<\/span>([\s\S]*?)(<span class=\"php\">)/g,'<\/span><span class="html">$1</span>$2').replace(/&lt;script(.*?)&gt;([\s\S]*?)&lt;\/script&gt;/g,'&lt;script$1&gt;</span><span class="js">$2</span><span class="html">&lt;\/script&gt;').replace(/&lt;style(.*?)&gt;([\s\S]*?)&lt;\/style&gt;/g,'&lt;style$1&gt;</span><span class="css">$2</span><span class="html">&lt;\/style&gt;')}code.html(text)}paint('php');paint('js');paint('css');paint('html');function paint(mod){var painted=code.children('.'+mod);if(!painted.length)return;switch(mod){case'php':painted.each(function(){var php_text=$(this).html().replace(/(\'|\")(.*?)\1/g,'<span class="str">$1$2$1</span>').replace(/\b(__CLASS__|__clone|__construct|__destruct|__FILE__|__FUNCTION__|__LINE__|__METHOD__|abstract|and|array|as|break|case|catch|cfunction|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|eval|exception|exit|extends|false|final|for|foreach|function|global|if|implements|include|include_once|instanceof|interface|isset|list|new|old_function|or|parent|php_user_filter|print|private|protected|public|require|require_once|return|self|static|switch|this|throw|true|try|unset|use|var|while|xor)\b/g,'<span class="key">$1</span>').replace(/(\$\w+)\b/gi,'<span class="var">$1</span>').replace(/(\w+\s*)\(/gi,'<span class="func">$1</span>(').replace(/(\/\/|#)(.*)\n/g,'<span class="comm">$1$2\n</span>').replace(/\/\*([\s\S]*?)\*\//g,'<span class="comm">/*$1*/</span>');$(this).html(php_text)});break;case'html':painted.each(function(){var html_text=$(this).html().replace(/([a-z]+)=(.*?)(\s|&gt;)/g,'<span class="attr">$1</span>=<span class="val">$2</span>$3').replace(/&lt;!--([\s\S]*?)--&gt;/g,'<span class="comm">&lt;!--$1--&gt;</span>').replace(/&lt;(.*?)&gt;/g,'<span class="tag">&lt;$1&gt;</span>');$(this).html(html_text)});break;case'js':painted.each(function(){var js_text=$(this).html().replace(/(\'|\")(.*?)\1/g,'<span class="str">$1$2$1</span>').replace(/\b(break|case|catch|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|function|if|import|in|new|null|return|super|switch|this|throw|true|try|typeof|var|void|while|with)\b/g,'<span class="key">$1</span>').replace(/(\$\w+)\b/gi,'<span class="var">$1</span>').replace(/(\w+\s*)\(/gi,'<span class="func">$1</span>(').replace(/\/\/(.*)\n/g,'<span class="comm">//$1\n</span>').replace(/\/\*([\s\S]*?)\*\//g,'<span class="comm">/*$1*/</span>');$(this).html(js_text)});break;case'css':painted.each(function(){var css_text=$(this).html().replace(/(\'|\")(.*?)\1/g,'<span class="str">$1$2$1</span>').replace(/([\w\-]+\s*):([^\n;\}\{]+)(\n|;|\})/gi,'<span class="var">$1</span>:<span class="val">$2</span>$3').replace(/([\w\-#\s:,\.]+\s*){/g,'<span class="id">$1</span>{').replace(/\/\*([\s\S]*?)\*\//g,'<span class="comm">/*$1*/</span>');$(this).html(css_text)})}}});function strCount(str,pattern){var pos=str.indexOf(pattern);for(var count=0;pos!=-1;count++)pos=str.indexOf(pattern,pos+pattern.length);return count}function detectLang(text){var textL=text.length;var braces=strCount(text,'{');var brackets=strCount(text,'(');var comm=strCount(text,'/*');var ids=strCount(text,'#');var colon=strCount(text,':');var bar=strCount(text,'/');var openTag=strCount(text,'&lt;');var lineComm=strCount(text,'//');var isJs=braces+brackets+comm+lineComm;var isCss=braces+colon+comm+ids;var isHtml=(openTag+bar)-(braces+brackets);if(isHtml>isCss&&isHtml>isJs)return'html';if(isJs>isCss&&isJs>isHtml)return'js';if(isCss>isJs&&isCss>isHtml)return'css'}}
