User:Pyrospirit/syntaxhighlighter.js

// Code placed here to increase efficiency of User:Pyrospirit/monobook.js

/* Syntax highlighter */

if(document.title.indexOf(".js") == -1) // Ignore pages that end in .js

$(function () {

/* CSS syntax highlighting */

multicommentRE = new RegExp('(/\\*[\\s\\S]*?\\*/)', 'g');

ruleRE = new RegExp('([^\\{]+)\\{([^\\}]+)\\}', 'g');

idselectorRE = new RegExp('(#[a-zA-Z0-9\-\_]+)\\b', 'g');

classselectorRE = new RegExp('(\\.[a-zA-Z0-9\-\_]+)\\b', 'g');

pairRE = new RegExp('([a-zA-Z-]+):([^;]+);', 'g');

css = document.getElementsByTagName('pre');

for (i = 0; i < css.length; i++) {

c = css[i];

content = c.innerHTML;

content=content.replace(multicommentRE, '$1');

content = content.replace(ruleRE, function(text, selector, body) {

selector = selector.replace(idselectorRE, '$1');

selector = selector.replace(classselectorRE, '$1');

body = body.replace(pairRE, '$1:$2;');

return selector + '{' + body + '}';

});

c.innerHTML = content;

}

});

else { /* JS syntax highlighting */

//

/**

  • Code Syntax Highlighter.
  • Version 1.3.0
  • Copyright (C) 2004 Alex Gorbatchev.
  • http://www.dreamprojections.com/syntaxhighlighter/
  • This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
  • Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
  • any later version.
  • This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  • warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  • details.
  • You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
  • the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  • /

var dp={sh:{Brushes:{},Version:'1.3.0'}};dp.SyntaxHighlighter=dp.sh;dp.sh.Match=function(value,index,css){this.value=value;this.index=index,this.length=value.length,this.css=css};dp.sh.Highlighter=function(){this.addGutter=true,this.collapse=false,this.tabsToSpaces=true};dp.sh.Highlighter.SortCallback=function(m1,m2){if(m1.indexm2.index)return 1;else{if(m1.lengthm2.length)return 1};return 0};dp.sh.Highlighter.prototype.GetMatches=function(regex,css){var index=0;var match=null;while((match=regex.exec(this.code))!=null){this.matches[this.matches.length]=new dp.sh.Match(match[0],match.index,css)}};dp.sh.Highlighter.prototype.AddBit=

function(str,css){

var span=document.createElement('span');

str=str.replace(/&/g,'\&');

str=str.replace(/\&/g,'&');

str=str.replace(/\"/g,'"');

str=str.replace(/ |\t/g,' ').replace(/\n/gm,'
');

if(css!=null){var regex=new RegExp('
','gi');if(regex.test(str)){var lines=str.split('
');str=;for(var i=0;ic.index)&&(match.index<=c.index+c.length))return true}return false};dp.sh.Highlighter.prototype.ProcessRegexList=function(){for(var i=0;i;var tabSize=4;var tab='\t';function InsertSpaces(line,pos,count){var left=line.substr(0,pos);var right=line.substr(pos+1,line.length);var spaces=;for(var i=0;i/gi,'\n');var lines=html.split('\n');var row=null;var cell=null;var tBody=null;var html=;var pipe=' | ';tBody=document.createElement('TBODY');this.table.appendChild(tBody);if(this.addGutter==true){row=tBody.insertRow(-1);cell=row.insertCell(-1)}for(var i=0,lineIndex=this.firstLine;i};dp.sh.Highlighter.prototype.Highlight=function(code){function Trim(str){return str.replace(/^\s*(.*?)[\s\n]*$/g,'$1')};function Chop(str){return str.replace(/\n*$/,).replace(/^\n*/,'')};function Unindent(str){var lines=str.split('\n');var indents=new Array();var regex=new RegExp('^\\s*','g');var min=1000;for(var i=0;i0;i++){if(Trim(lines[i]).length==0)continue;var matches=regex.exec(lines[i]);if(matches!=null&&matches.length>0)min=Math.min(matches[0].length,min)};if(min>0)for(var i=0;i

dp.sh.Brushes.JScript = function(){

var keywords = 'abstract boolean break byte case catch char class const continue debugger ' +

'default delete do double else enum export extends false final finally float ' +

'for function goto if implements import in instanceof int interface long native ' +

'new null package private protected public return short static super switch ' +

'synchronized this throw throws transient true try typeof var void volatile while with';

this.regexList = [

{regex: new RegExp('//.*$', 'gm'), css: 'comment' }, // one line comments

{regex: new RegExp('/\\*[\\s\\S]*?\\*/', 'g'),css: 'comment' }, // multiline comments

{regex: new RegExp('"(?:[^"\n]|[\"])*?".*?','g'),css: 'string' }, // double quoted strings

{regex: new RegExp("'(?:[^'\n]|[\'])*?'.*?",'g'),css: 'string' }, // single quoted strings

{regex: new RegExp('^\\s*#.*', 'gm'), css: 'preprocessor'},// preprocessor tags like #region and #endregion

{regex: new RegExp(this.GetKeyw(keywords),'gm'),css: 'keyword'} // keywords

];

this.CssClass = 'dp-c';

}

dp.sh.Brushes.JScript.prototype = new dp.sh.Highlighter();

$(dp.SyntaxHighlighter.HighlightAll);

//

}