//
// Begin anonymous function. This is used to contain local scope variables without polutting global scope.
//
if (!window.SyntaxHighlighter) var SyntaxHighlighter = function() {
// Shortcut object which will be assigned to the SyntaxHighlighter variable.
// This is a shorthand for local reference in order to avoid long namespace
// references to SyntaxHighlighter.whatever...
var sh = {
defaults : {
/** Additional CSS class names to be added to highlighter elements. */
'class-name' : '',
/** First line number. */
'first-line' : 1,
/**
* Pads line numbers. Possible values are:
*
* false - don't pad line numbers.
* true - automaticaly pad numbers with minimum required number of leading zeroes.
* [int] - length up to which pad line numbers.
*/
'pad-line-numbers' : true,
/** Lines to highlight. */
'highlight' : null,
/** Enables or disables smart tabs. */
'smart-tabs' : true,
/** Gets or sets tab size. */
'tab-size' : 4,
/** Enables or disables gutter. */
'gutter' : true,
/** Enables or disables toolbar. */
'toolbar' : true,
/** Forces code view to be collapsed. */
'collapse' : false,
/** Enables or disables automatic links. */
'auto-links' : true,
/** Gets or sets light mode. Equavalent to turning off gutter and toolbar. */
'light' : false,
/** Enables or disables automatic line wrapping. */
'wrap-lines' : true,
'html-script' : false
},
config : {
/** Enables use of tags. */
useScriptTags : true,
/** Path to the copy to clipboard SWF file. */
clipboardSwf : null,
/** Width of an item in the toolbar. */
toolbarItemWidth : 16,
/** Height of an item in the toolbar. */
toolbarItemHeight : 16,
/** Blogger mode flag. */
bloggerMode : false,
stripBrs : false,
/** Name of the tag that SyntaxHighlighter will automatically look for. */
tagName : 'pre',
strings : {
expandSource : 'show source',
viewSource : 'view source',
copyToClipboard : 'copy to clipboard',
copyToClipboardConfirmation : 'The code is in your clipboard now',
print : 'print',
help : '?',
alert: 'SyntaxHighlighter\n\n',
noBrush : 'Can\'t find brush for: ',
brushNotHtmlScript : 'Brush wasn\'t configured for html-script option: ',
// this is populated by the build script
aboutDialog : '@ABOUT@'
},
/** If true, output will show HTML produces instead. */
debug : false
},
/** Internal 'global' variables. */
vars : {
discoveredBrushes : null,
spaceWidth : null,
printFrame : null,
highlighters : {}
},
/** This object is populated by user included external brush files. */
brushes : {},
/** Common regular expressions. */
regexLib : {
multiLineCComments : /\/\*[\s\S]*?\*\//gm,
singleLineCComments : /\/\/.*$/gm,
singleLinePerlComments : /#.*$/gm,
doubleQuotedString : /"([^\\"\n]|\\.)*"/g,
singleQuotedString : /'([^\\'\n]|\\.)*'/g,
multiLineDoubleQuotedString : /"([^\\"]|\\.)*"/g,
multiLineSingleQuotedString : /'([^\\']|\\.)*'/g,
xmlComments : /(<|<)!--[\s\S]*?--(>|>)/gm,
url : /<\w+:\/\/[\w-.\/?%&=@:;]*>|\w+:\/\/[\w-.\/?%&=@:;]*/g,
/** = ?> tags. */
phpScriptTags : { left: /(<|<)\?=?/g, right: /\?(>|>)/g },
/** <%= %> tags. */
aspScriptTags : { left: /(<|<)%=?/g, right: /%(>|>)/g },
/** tags. */
scriptScriptTags : { left: /(<|<)\s*script.*?(>|>)/gi, right: /(<|<)\/\s*script\s*(>|>)/gi }
},
toolbar : {
/**
* Creates new toolbar for a highlighter.
* @param {Highlighter} highlighter Target highlighter.
*/
create : function(highlighter)
{
var div = document.createElement('DIV'),
items = sh.toolbar.items
;
div.className = 'toolbar';
for (var name in items)
{
var constructor = items[name],
command = new constructor(highlighter),
element = command.create()
;
highlighter.toolbarCommands[name] = command;
if (element == null)
continue;
if (typeof(element) == 'string')
element = sh.toolbar.createButton(element, highlighter.id, name);
element.className += 'item ' + name;
div.appendChild(element);
}
return div;
},
/**
* Create a standard anchor button for the toolbar.
* @param {String} label Label text to display.
* @param {String} highlighterId Highlighter ID that this button would belong to.
* @param {String} commandName Command name that would be executed.
* @return {Element} Returns an 'A' element.
*/
createButton : function(label, highlighterId, commandName)
{
var a = document.createElement('a'),
style = a.style,
config = sh.config,
width = config.toolbarItemWidth,
height = config.toolbarItemHeight
;
a.href = '#' + commandName;
a.title = label;
a.highlighterId = highlighterId;
a.commandName = commandName;
a.innerHTML = label;
if (isNaN(width) == false)
style.width = width + 'px';
if (isNaN(height) == false)
style.height = height + 'px';
a.onclick = function(e)
{
try
{
sh.toolbar.executeCommand(
this,
e || window.event,
this.highlighterId,
this.commandName
);
}
catch(e)
{
sh.utils.alert(e.message);
}
return false;
};
return a;
},
/**
* Executes a toolbar command.
* @param {Element} sender Sender element.
* @param {MouseEvent} event Original mouse event object.
* @param {String} highlighterId Highlighter DIV element ID.
* @param {String} commandName Name of the command to execute.
* @return {Object} Passes out return value from command execution.
*/
executeCommand : function(sender, event, highlighterId, commandName, args)
{
var highlighter = sh.vars.highlighters[highlighterId],
command
;
if (highlighter == null || (command = highlighter.toolbarCommands[commandName]) == null)
return null;
return command.execute(sender, event, args);
},
/** Collection of toolbar items. */
items : {
expandSource : function(highlighter)
{
this.create = function()
{
if (highlighter.getParam('collapse') != true)
return;
return sh.config.strings.expandSource;
};
this.execute = function(sender, event, args)
{
var div = highlighter.div;
sender.parentNode.removeChild(sender);
div.className = div.className.replace('collapsed', '');
};
},
/**
* Command to open a new window and display the original unformatted source code inside.
*/
viewSource : function(highlighter)
{
this.create = function()
{
return sh.config.strings.viewSource;
};
this.execute = function(sender, event, args)
{
var code = sh.utils.fixInputString(highlighter.originalCode).replace(/' + code + '');
wnd.document.close();
};
},
/**
* Command to copy the original source code in to the clipboard.
* Uses Flash method if clipboardSwf
is configured.
*/
copyToClipboard : function(highlighter)
{
var flashDiv, flashSwf,
highlighterId = highlighter.id
;
this.create = function()
{
var config = sh.config;
// disable functionality if running locally
if (config.clipboardSwf == null)
return null;
function params(list)
{
var result = '';
for (var name in list)
result += "";
return result;
};
function attributes(list)
{
var result = '';
for (var name in list)
result += " " + name + "='" + list[name] + "'";
return result;
};
var args1 = {
width : config.toolbarItemWidth,
height : config.toolbarItemHeight,
id : highlighterId + '_clipboard',
type : 'application/x-shockwave-flash',
title : sh.config.strings.copyToClipboard
},
// these arguments are used in IE's collection
args2 = {
allowScriptAccess : 'always',
wmode : 'transparent',
flashVars : 'highlighterId=' + highlighterId,
menu : 'false'
},
swf = config.clipboardSwf,
html
;
if (/msie/i.test(navigator.userAgent))
{
html = ''
;
}
else
{
html = ''
;
}
flashDiv = document.createElement('div');
flashDiv.innerHTML = html;
return flashDiv;
};
this.execute = function(sender, event, args)
{
var command = args.command;
switch (command)
{
case 'get':
var code = sh.utils.unindent(
sh.utils.fixInputString(highlighter.originalCode)
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/&/g, '&')
);
if(window.clipboardData)
// will fall through to the confirmation because there isn't a break
window.clipboardData.setData('text', code);
else
return sh.utils.unindent(code);
case 'ok':
sh.utils.alert(sh.config.strings.copyToClipboardConfirmation);
break;
case 'error':
sh.utils.alert(args.message);
break;
}
};
},
/** Command to print the colored source code. */
printSource : function(highlighter)
{
this.create = function()
{
return sh.config.strings.print;
};
this.execute = function(sender, event, args)
{
var iframe = document.createElement('IFRAME'),
doc = null
;
// make sure there is never more than one hidden iframe created by SH
if (sh.vars.printFrame != null)
document.body.removeChild(sh.vars.printFrame);
sh.vars.printFrame = iframe;
// this hides the iframe
iframe.style.cssText = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
document.body.appendChild(iframe);
doc = iframe.contentWindow.document;
copyStyles(doc, window.document);
doc.write('
tag with given style applied to it.
*
* @param {String} str Input string.
* @param {String} css Style name to apply to the string.
* @return {String} Returns input string with each line surrounded by tag.
*/
decorate: function(str, css)
{
if (str == null || str.length == 0 || str == '\n')
return str;
str = str.replace(/... to them so that
// leading spaces aren't included.
if (css != null)
str = sh.utils.eachLine(str, function(line)
{
if (line.length == 0)
return '';
var spaces = '';
line = line.replace(/^( | )+/, function(s)
{
spaces = s;
return '';
});
if (line.length == 0)
return spaces;
return spaces + '' + line + '
';
});
return str;
},
/**
* Pads number with zeros until it's length is the same as given length.
*
* @param {Number} number Number to pad.
* @param {Number} length Max string length with.
* @return {String} Returns a string padded with proper amount of '0'.
*/
padNumber : function(number, length)
{
var result = number.toString();
while (result.length < length)
result = '0' + result;
return result;
},
/**
* Measures width of a single space character.
* @return {Number} Returns width of a single space character.
*/
measureSpace : function()
{
var container = document.createElement('div'),
span,
result = 0,
body = document.body,
id = sh.utils.guid('measureSpace'),
// variable names will be compressed, so it's better than a plain string
divOpen = 'regexList
collection.
* @return {Array} Returns a list of Match objects.
*/
getMatches: function(code, regexInfo)
{
function defaultAdd(match, regexInfo)
{
return [new sh.Match(match[0], match.index, regexInfo.css)];
};
var index = 0,
match = null,
result = [],
func = regexInfo.func ? regexInfo.func : defaultAdd
;
while((match = regexInfo.regex.exec(code)) != null)
result = result.concat(func(match, regexInfo));
return result;
},
processUrls: function(code)
{
var lt = '<',
gt = '>'
;
return code.replace(sh.regexLib.url, function(m)
{
var suffix = '', prefix = '';
// We include < and > in the URL for the common cases like ' + lineNumber + ' | ' : '')
+ ''
+ (spaces != null ? '' + spaces.replace(' ', ' ') + ' ' : '')
+ line
+ ' | '
+ '
.*?)" +
"(?" + regexGroup.right.source + ")",
"sgi"
)
};
}
}; // end of Highlighter
return sh;
}(); // end of anonymous function
/**
* XRegExp 0.6.1
* (c) 2007-2008 Steven Levithan
*
* MIT License
*
* provides an augmented, cross-browser implementation of regular expressions
* including support for additional modifiers and syntax. several convenience
* methods and a recursive-construct parser are also included.
*/
// prevent running twice, which would break references to native globals
if (!window.XRegExp) {
// anonymous function to avoid global variables
(function () {
// copy various native globals for reference. can't use the name ``native``
// because it's a reserved JavaScript keyword.
var real = {
exec: RegExp.prototype.exec,
match: String.prototype.match,
replace: String.prototype.replace,
split: String.prototype.split
},
/* regex syntax parsing with support for all the necessary cross-
browser and context issues (escapings, character classes, etc.) */
lib = {
part: /(?:[^\\([#\s.]+|\\(?!k<[\w$]+>|[pP]{[^}]+})[\S\s]?|\((?=\?(?!#|<[\w$]+>)))+|(\()(?:\?(?:(#)[^)]*\)|<([$\w]+)>))?|\\(?:k<([\w$]+)>|[pP]{([^}]+)})|(\[\^?)|([\S\s])/g,
replaceVar: /(?:[^$]+|\$(?![1-9$&`']|{[$\w]+}))+|\$(?:([1-9]\d*|[$&`'])|{([$\w]+)})/g,
extended: /^(?:\s+|#.*)+/,
quantifier: /^(?:[?*+]|{\d+(?:,\d*)?})/,
classLeft: /&&\[\^?/g,
classRight: /]/g
},
indexOf = function (array, item, from) {
for (var i = from || 0; i < array.length; i++)
if (array[i] === item) return i;
return -1;
},
brokenExecUndef = /()??/.exec("")[1] !== undefined,
plugins = {};
/**
* Accepts a pattern and flags, returns a new, extended RegExp object.
* differs from a native regex in that additional flags and syntax are
* supported and browser inconsistencies are ameliorated.
* @ignore
*/
XRegExp = function (pattern, flags) {
if (pattern instanceof RegExp) {
if (flags !== undefined)
throw TypeError("can't supply flags when constructing one RegExp from another");
return pattern.addFlags(); // new copy
}
var flags = flags || "",
singleline = flags.indexOf("s") > -1,
extended = flags.indexOf("x") > -1,
hasNamedCapture = false,
captureNames = [],
output = [],
part = lib.part,
match, cc, len, index, regex;
part.lastIndex = 0; // in case the last XRegExp compilation threw an error (unbalanced character class)
while (match = real.exec.call(part, pattern)) {
// comment pattern. this check must come before the capturing group check,
// because both match[1] and match[2] will be non-empty.
if (match[2]) {
// keep tokens separated unless the following token is a quantifier
if (!lib.quantifier.test(pattern.slice(part.lastIndex)))
output.push("(?:)");
// capturing group
} else if (match[1]) {
captureNames.push(match[3] || null);
if (match[3])
hasNamedCapture = true;
output.push("(");
// named backreference
} else if (match[4]) {
index = indexOf(captureNames, match[4]);
// keep backreferences separate from subsequent literal numbers
// preserve backreferences to named groups that are undefined at this point as literal strings
output.push(index > -1 ?
"\\" + (index + 1) + (isNaN(pattern.charAt(part.lastIndex)) ? "" : "(?:)") :
match[0]
);
// unicode element (requires plugin)
} else if (match[5]) {
output.push(plugins.unicode ?
plugins.unicode.get(match[5], match[0].charAt(1) === "P") :
match[0]
);
// character class opening delimiter ("[" or "[^")
// (non-native unicode elements are not supported within character classes)
} else if (match[6]) {
if (pattern.charAt(part.lastIndex) === "]") {
// for cross-browser compatibility with ECMA-262 v3 behavior,
// convert [] to (?!) and [^] to [\S\s].
output.push(match[6] === "[" ? "(?!)" : "[\\S\\s]");
part.lastIndex++;
} else {
// parse the character class with support for inner escapes and
// ES4's infinitely nesting intersection syntax ([&&[^&&[]]]).
cc = XRegExp.matchRecursive("&&" + pattern.slice(match.index), lib.classLeft, lib.classRight, "", {escapeChar: "\\"})[0];
output.push(match[6] + cc + "]");
part.lastIndex += cc.length + 1;
}
// dot ("."), pound sign ("#"), or whitespace character
} else if (match[7]) {
if (singleline && match[7] === ".") {
output.push("[\\S\\s]");
} else if (extended && lib.extended.test(match[7])) {
len = real.exec.call(lib.extended, pattern.slice(part.lastIndex - 1))[0].length;
// keep tokens separated unless the following token is a quantifier
if (!lib.quantifier.test(pattern.slice(part.lastIndex - 1 + len)))
output.push("(?:)");
part.lastIndex += len - 1;
} else {
output.push(match[7]);
}
} else {
output.push(match[0]);
}
}
regex = RegExp(output.join(""), real.replace.call(flags, /[sx]+/g, ""));
regex._x = {
source: pattern,
captureNames: hasNamedCapture ? captureNames : null
};
return regex;
};
/**
* Barebones plugin support for now (intentionally undocumented)
* @ignore
* @param {Object} name
* @param {Object} o
*/
XRegExp.addPlugin = function (name, o) {
plugins[name] = o;
};
/**
* Adds named capture support, with values returned as ``result.name``.
*
* Also fixes two cross-browser issues, following the ECMA-262 v3 spec:
* - captured values for non-participating capturing groups should be returned
* as ``undefined``, rather than the empty string.
* - the regex's ``lastIndex`` should not be incremented after zero-length
* matches.
* @ignore
*/
RegExp.prototype.exec = function (str) {
var match = real.exec.call(this, str),
name, i, r2;
if (match) {
// fix browsers whose exec methods don't consistently return
// undefined for non-participating capturing groups
if (brokenExecUndef && match.length > 1) {
// r2 doesn't need /g or /y, but they shouldn't hurt
r2 = new RegExp("^" + this.source + "$(?!\\s)", this.getNativeFlags());
real.replace.call(match[0], r2, function () {
for (i = 1; i < arguments.length - 2; i++) {
if (arguments[i] === undefined) match[i] = undefined;
}
});
}
// attach named capture properties
if (this._x && this._x.captureNames) {
for (i = 1; i < match.length; i++) {
name = this._x.captureNames[i - 1];
if (name) match[name] = match[i];
}
}
// fix browsers that increment lastIndex after zero-length matches
if (this.global && this.lastIndex > (match.index + match[0].length))
this.lastIndex--;
}
return match;
};
})(); // end anonymous function
} // end if(!window.XRegExp)
/**
* intentionally undocumented
* @ignore
*/
RegExp.prototype.getNativeFlags = function () {
return (this.global ? "g" : "") +
(this.ignoreCase ? "i" : "") +
(this.multiline ? "m" : "") +
(this.extended ? "x" : "") +
(this.sticky ? "y" : "");
};
/**
* Accepts flags; returns a new XRegExp object generated by recompiling
* the regex with the additional flags (may include non-native flags).
* The original regex object is not altered.
* @ignore
*/
RegExp.prototype.addFlags = function (flags) {
var regex = new XRegExp(this.source, (flags || "") + this.getNativeFlags());
if (this._x) {
regex._x = {
source: this._x.source,
captureNames: this._x.captureNames ? this._x.captureNames.slice(0) : null
};
}
return regex;
};
/**
* Accepts a context object and string; returns the result of calling
* ``exec`` with the provided string. the context is ignored but is
* accepted for congruity with ``Function.prototype.call``.
* @ignore
*/
RegExp.prototype.call = function (context, str) {
return this.exec(str);
};
/**
* Accepts a context object and arguments array; returns the result of
* calling ``exec`` with the first value in the arguments array. the context
* is ignored but is accepted for congruity with ``Function.prototype.apply``.
* @ignore
*/
RegExp.prototype.apply = function (context, args) {
return this.exec(args[0]);
};
/**
* Accepts a pattern and flags; returns an XRegExp object. if the pattern
* and flag combination has previously been cached, the cached copy is
* returned, otherwise the new object is cached.
* @ignore
*/
XRegExp.cache = function (pattern, flags) {
var key = "/" + pattern + "/" + (flags || "");
return XRegExp.cache[key] || (XRegExp.cache[key] = new XRegExp(pattern, flags));
};
/**
* Accepts a string; returns the string with regex metacharacters escaped.
* the returned string can safely be used within a regex to match a literal
* string. escaped characters are [, ], {, }, (, ), -, *, +, ?, ., \, ^, $,
* |, #, [comma], and whitespace.
* @ignore
*/
XRegExp.escape = function (str) {
return str.replace(/[-[\]{}()*+?.\\^$|,#\s]/g, "\\$&");
};
/**
* Accepts a string to search, left and right delimiters as regex pattern
* strings, optional regex flags (may include non-native s, x, and y flags),
* and an options object which allows setting an escape character and changing
* the return format from an array of matches to a two-dimensional array of
* string parts with extended position data. returns an array of matches
* (optionally with extended data), allowing nested instances of left and right
* delimiters. use the g flag to return all matches, otherwise only the first
* is returned. if delimiters are unbalanced within the subject data, an error
* is thrown.
*
* This function admittedly pushes the boundaries of what can be accomplished
* sensibly without a "real" parser. however, by doing so it provides flexible
* and powerful recursive parsing capabilities with minimal code weight.
*
* Warning: the ``escapeChar`` option is considered experimental and might be
* changed or removed in future versions of XRegExp.
*
* unsupported features:
* - backreferences within delimiter patterns when using ``escapeChar``.
* - although providing delimiters as regex objects adds the minor feature of
* independent delimiter flags, it introduces other limitations and is only
* intended to be done by the ``XRegExp`` constructor (which can't call
* itself while building a regex).
*
* @ignore
*/
XRegExp.matchRecursive = function (str, left, right, flags, options) {
var options = options || {},
escapeChar = options.escapeChar,
vN = options.valueNames,
flags = flags || "",
global = flags.indexOf("g") > -1,
ignoreCase = flags.indexOf("i") > -1,
multiline = flags.indexOf("m") > -1,
sticky = flags.indexOf("y") > -1,
/* sticky mode has its own handling in this function, which means you
can use flag "y" even in browsers which don't support it natively */
flags = flags.replace(/y/g, ""),
left = left instanceof RegExp ? (left.global ? left : left.addFlags("g")) : new XRegExp(left, "g" + flags),
right = right instanceof RegExp ? (right.global ? right : right.addFlags("g")) : new XRegExp(right, "g" + flags),
output = [],
openTokens = 0,
delimStart = 0,
delimEnd = 0,
lastOuterEnd = 0,
outerStart, innerStart, leftMatch, rightMatch, escaped, esc;
if (escapeChar) {
if (escapeChar.length > 1) throw SyntaxError("can't supply more than one escape character");
if (multiline) throw TypeError("can't supply escape character when using the multiline flag");
escaped = XRegExp.escape(escapeChar);
/* Escape pattern modifiers:
/g - not needed here
/i - included
/m - **unsupported**, throws error
/s - handled by XRegExp when delimiters are provided as strings
/x - handled by XRegExp when delimiters are provided as strings
/y - not needed here; supported by other handling in this function
*/
esc = new RegExp(
"^(?:" + escaped + "[\\S\\s]|(?:(?!" + left.source + "|" + right.source + ")[^" + escaped + "])+)+",
ignoreCase ? "i" : ""
);
}
while (true) {
/* advance the starting search position to the end of the last delimiter match.
a couple special cases are also covered:
- if using an escape character, advance to the next delimiter's starting position,
skipping any escaped characters
- first time through, reset lastIndex in case delimiters were provided as regexes
*/
left.lastIndex = right.lastIndex = delimEnd +
(escapeChar ? (esc.exec(str.slice(delimEnd)) || [""])[0].length : 0);
leftMatch = left.exec(str);
rightMatch = right.exec(str);
// only keep the result which matched earlier in the string
if (leftMatch && rightMatch) {
if (leftMatch.index <= rightMatch.index)
rightMatch = null;
else leftMatch = null;
}
/* paths*:
leftMatch | rightMatch | openTokens | result
1 | 0 | 1 | ...
1 | 0 | 0 | ...
0 | 1 | 1 | ...
0 | 1 | 0 | throw
0 | 0 | 1 | throw
0 | 0 | 0 | break
* - does not include the sticky mode special case
- the loop ends after the first completed match if not in global mode
*/
if (leftMatch || rightMatch) {
delimStart = (leftMatch || rightMatch).index;
delimEnd = (leftMatch ? left : right).lastIndex;
} else if (!openTokens) {
break;
}
if (sticky && !openTokens && delimStart > lastOuterEnd)
break;
if (leftMatch) {
if (!openTokens++) {
outerStart = delimStart;
innerStart = delimEnd;
}
} else if (rightMatch && openTokens) {
if (!--openTokens) {
if (vN) {
if (vN[0] && outerStart > lastOuterEnd)
output.push([vN[0], str.slice(lastOuterEnd, outerStart), lastOuterEnd, outerStart]);
if (vN[1]) output.push([vN[1], str.slice(outerStart, innerStart), outerStart, innerStart]);
if (vN[2]) output.push([vN[2], str.slice(innerStart, delimStart), innerStart, delimStart]);
if (vN[3]) output.push([vN[3], str.slice(delimStart, delimEnd), delimStart, delimEnd]);
} else {
output.push(str.slice(innerStart, delimStart));
}
lastOuterEnd = delimEnd;
if (!global)
break;
}
} else {
// reset lastIndex in case delimiters were provided as regexes
left.lastIndex = right.lastIndex = 0;
throw Error("subject data contains unbalanced delimiters");
}
// if the delimiter matched an empty string, advance delimEnd to avoid an infinite loop
if (delimStart === delimEnd)
delimEnd++;
}
if (global && !sticky && vN && vN[0] && str.length > lastOuterEnd)
output.push([vN[0], str.slice(lastOuterEnd), lastOuterEnd, str.length]);
// reset lastIndex in case delimiters were provided as regexes
left.lastIndex = right.lastIndex = 0;
return output;
};
;
SyntaxHighlighter.brushes.CSharp = function()
{
var keywords = 'abstract as base bool break byte case catch char checked class const ' +
'continue decimal default delegate do double else enum event explicit ' +
'extern false finally fixed float for foreach get goto if implicit in int ' +
'interface internal is lock long namespace new null object operator out ' +
'override params private protected public readonly ref return sbyte sealed set ' +
'short sizeof stackalloc static string struct switch this throw true try ' +
'typeof uint ulong unchecked unsafe ushort using virtual void while';
function fixComments(match, regexInfo)
{
var css = (match[0].indexOf("///") == 0)
? 'color1'
: 'comments'
;
return [new SyntaxHighlighter.Match(match[0], match.index, css)];
}
this.regexList = [
{ regex: SyntaxHighlighter.regexLib.singleLineCComments, func : fixComments }, // one line comments
{ regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comments' }, // multiline comments
{ regex: /@"(?:[^"]|"")*"/g, css: 'string' }, // @-quoted strings
{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // strings
{ regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // strings
{ regex: /^\s*#.*/gm, css: 'preprocessor' }, // preprocessor tags like #region and #endregion
{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' }, // c# keyword
{ regex: /\bpartial(?=\s+(?:class|interface|struct)\b)/g, css: 'keyword' }, // contextual keyword: 'partial'
{ regex: /\byield(?=\s+(?:return|break)\b)/g, css: 'keyword' } // contextual keyword: 'yield'
];
this.forHtmlScript(SyntaxHighlighter.regexLib.aspScriptTags);
};
SyntaxHighlighter.brushes.CSharp.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.CSharp.aliases = ['c#', 'c-sharp', 'csharp'];
;
SyntaxHighlighter.brushes.Cpp = function()
{
// Copyright 2006 Shin, YoungJin
var datatypes = 'ATOM BOOL BOOLEAN BYTE CHAR COLORREF DWORD DWORDLONG DWORD_PTR ' +
'DWORD32 DWORD64 FLOAT HACCEL HALF_PTR HANDLE HBITMAP HBRUSH ' +
'HCOLORSPACE HCONV HCONVLIST HCURSOR HDC HDDEDATA HDESK HDROP HDWP ' +
'HENHMETAFILE HFILE HFONT HGDIOBJ HGLOBAL HHOOK HICON HINSTANCE HKEY ' +
'HKL HLOCAL HMENU HMETAFILE HMODULE HMONITOR HPALETTE HPEN HRESULT ' +
'HRGN HRSRC HSZ HWINSTA HWND INT INT_PTR INT32 INT64 LANGID LCID LCTYPE ' +
'LGRPID LONG LONGLONG LONG_PTR LONG32 LONG64 LPARAM LPBOOL LPBYTE LPCOLORREF ' +
'LPCSTR LPCTSTR LPCVOID LPCWSTR LPDWORD LPHANDLE LPINT LPLONG LPSTR LPTSTR ' +
'LPVOID LPWORD LPWSTR LRESULT PBOOL PBOOLEAN PBYTE PCHAR PCSTR PCTSTR PCWSTR ' +
'PDWORDLONG PDWORD_PTR PDWORD32 PDWORD64 PFLOAT PHALF_PTR PHANDLE PHKEY PINT ' +
'PINT_PTR PINT32 PINT64 PLCID PLONG PLONGLONG PLONG_PTR PLONG32 PLONG64 POINTER_32 ' +
'POINTER_64 PSHORT PSIZE_T PSSIZE_T PSTR PTBYTE PTCHAR PTSTR PUCHAR PUHALF_PTR ' +
'PUINT PUINT_PTR PUINT32 PUINT64 PULONG PULONGLONG PULONG_PTR PULONG32 PULONG64 ' +
'PUSHORT PVOID PWCHAR PWORD PWSTR SC_HANDLE SC_LOCK SERVICE_STATUS_HANDLE SHORT ' +
'SIZE_T SSIZE_T TBYTE TCHAR UCHAR UHALF_PTR UINT UINT_PTR UINT32 UINT64 ULONG ' +
'ULONGLONG ULONG_PTR ULONG32 ULONG64 USHORT USN VOID WCHAR WORD WPARAM WPARAM WPARAM ' +
'char bool short int __int32 __int64 __int8 __int16 long float double __wchar_t ' +
'clock_t _complex _dev_t _diskfree_t div_t ldiv_t _exception _EXCEPTION_POINTERS ' +
'FILE _finddata_t _finddatai64_t _wfinddata_t _wfinddatai64_t __finddata64_t ' +
'__wfinddata64_t _FPIEEE_RECORD fpos_t _HEAPINFO _HFILE lconv intptr_t ' +
'jmp_buf mbstate_t _off_t _onexit_t _PNH ptrdiff_t _purecall_handler ' +
'sig_atomic_t size_t _stat __stat64 _stati64 terminate_function ' +
'time_t __time64_t _timeb __timeb64 tm uintptr_t _utimbuf ' +
'va_list wchar_t wctrans_t wctype_t wint_t signed';
var keywords = 'break case catch class const __finally __exception __try ' +
'const_cast continue private public protected __declspec ' +
'default delete deprecated dllexport dllimport do dynamic_cast ' +
'else enum explicit extern if for friend goto inline ' +
'mutable naked namespace new noinline noreturn nothrow ' +
'register reinterpret_cast return selectany ' +
'sizeof static static_cast struct switch template this ' +
'thread throw true false try typedef typeid typename union ' +
'using uuid virtual void volatile whcar_t while';
var functions = 'assert isalnum isalpha iscntrl isdigit isgraph islower isprint' +
'ispunct isspace isupper isxdigit tolower toupper errno localeconv ' +
'setlocale acos asin atan atan2 ceil cos cosh exp fabs floor fmod ' +
'frexp ldexp log log10 modf pow sin sinh sqrt tan tanh jmp_buf ' +
'longjmp setjmp raise signal sig_atomic_t va_arg va_end va_start ' +
'clearerr fclose feof ferror fflush fgetc fgetpos fgets fopen ' +
'fprintf fputc fputs fread freopen fscanf fseek fsetpos ftell ' +
'fwrite getc getchar gets perror printf putc putchar puts remove ' +
'rename rewind scanf setbuf setvbuf sprintf sscanf tmpfile tmpnam ' +
'ungetc vfprintf vprintf vsprintf abort abs atexit atof atoi atol ' +
'bsearch calloc div exit free getenv labs ldiv malloc mblen mbstowcs ' +
'mbtowc qsort rand realloc srand strtod strtol strtoul system ' +
'wcstombs wctomb memchr memcmp memcpy memmove memset strcat strchr ' +
'strcmp strcoll strcpy strcspn strerror strlen strncat strncmp ' +
'strncpy strpbrk strrchr strspn strstr strtok strxfrm asctime ' +
'clock ctime difftime gmtime localtime mktime strftime time';
this.regexList = [
{ regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comments' }, // one line comments
{ regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comments' }, // multiline comments
{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // strings
{ regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // strings
{ regex: /^ *#.*/gm, css: 'preprocessor' },
{ regex: new RegExp(this.getKeywords(datatypes), 'gm'), css: 'color1 bold' },
{ regex: new RegExp(this.getKeywords(functions), 'gm'), css: 'functions bold' },
{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword bold' }
];
};
SyntaxHighlighter.brushes.Cpp.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.Cpp.aliases = ['cpp', 'c'];
;
SyntaxHighlighter.brushes.JScript = function()
{
var keywords = 'break case catch continue ' +
'default delete do else false ' +
'for function if in instanceof ' +
'new null return super switch ' +
'this throw true try typeof var while with'
;
this.regexList = [
{ regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comments' }, // one line comments
{ regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comments' }, // multiline comments
{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // double quoted strings
{ regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // single quoted strings
{ regex: /\s*#.*/gm, css: 'preprocessor' }, // preprocessor tags like #region and #endregion
{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' } // keywords
];
this.forHtmlScript(SyntaxHighlighter.regexLib.scriptScriptTags);
};
SyntaxHighlighter.brushes.JScript.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.JScript.aliases = ['js', 'jscript', 'javascript'];
;
SyntaxHighlighter.brushes.Java = function()
{
var keywords = 'abstract assert boolean break byte case catch char class const ' +
'continue default do double else enum extends ' +
'false final finally float for goto if implements import ' +
'instanceof int interface long native new null ' +
'package private protected public return ' +
'short static strictfp super switch synchronized this throw throws true ' +
'transient try void volatile while';
this.regexList = [
{ regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comments' }, // one line comments
{ regex: /\/\*([^\*][\s\S]*)?\*\//gm, css: 'comments' }, // multiline comments
{ regex: /\/\*(?!\*\/)\*[\s\S]*?\*\//gm, css: 'preprocessor' }, // documentation comments
{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // strings
{ regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // strings
{ regex: /\b([\d]+(\.[\d]+)?|0x[a-f0-9]+)\b/gi, css: 'value' }, // numbers
{ regex: /(?!\@interface\b)\@[\$\w]+\b/g, css: 'color1' }, // annotation @anno
{ regex: /\@interface\b/g, css: 'color2' }, // @interface keyword
{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' } // java keyword
];
this.forHtmlScript({
left : /(<|<)%[@!=]?/g,
right : /%(>|>)/g
});
};
SyntaxHighlighter.brushes.Java.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.Java.aliases = ['java'];
;
SyntaxHighlighter.brushes.Plain = function()
{
};
SyntaxHighlighter.brushes.Plain.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.Plain.aliases = ['text', 'plain'];
;
SyntaxHighlighter.brushes.Xml = function()
{
function process(match, regexInfo)
{
var constructor = SyntaxHighlighter.Match,
code = match[0],
tag = new XRegExp('(<|<)[\\s\\/\\?]*(?[:\\w-\\.]+)', 'xg').exec(code),
result = []
;
if (match.attributes != null)
{
var attributes,
regex = new XRegExp('(? [\\w:\\-\\.]+)' +
'\\s*=\\s*' +
'(? ".*?"|\'.*?\'|\\w+)',
'xg');
while ((attributes = regex.exec(code)) != null)
{
result.push(new constructor(attributes.name, match.index + attributes.index, 'color1'));
result.push(new constructor(attributes.value, match.index + attributes.index + attributes[0].indexOf(attributes.value), 'string'));
}
}
if (tag != null)
result.push(
new constructor(tag.name, match.index + tag[0].indexOf(tag.name), 'keyword')
);
return result;
}
this.regexList = [
{ regex: new XRegExp('(\\<|<)\\!\\[[\\w\\s]*?\\[(.|\\s)*?\\]\\](\\>|>)', 'gm'), css: 'color2' }, //
{ regex: SyntaxHighlighter.regexLib.xmlComments, css: 'comments' }, //
{ regex: new XRegExp('(<|<)[\\s\\/\\?]*(\\w+)(?.*?)[\\s\\/\\?]*(>|>)', 'sg'), func: process }
];
};
SyntaxHighlighter.brushes.Xml.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.Xml.aliases = ['xml', 'xhtml', 'xslt', 'html'];
;
/**
* @file
* Attaches the behaviors for the Scroll to Destination Anchors module.
*/
// Prevent script conflicts and attach the behavior.
(function($) {
Drupal.behaviors.scrolltoanchors = {
attach: function(context, settings) {
// Wait until after the window has loaded.
$(window).load(function(){
// Utility to check if a string is a valid selector.
function validateSelector(a) {
return /^#[a-z]{1}[a-z0-9_-]*$/i.test(a);
}
// Utility to scroll users to particular destination on the page.
function scrollToDestination(a, b) {
if (a > b) {
destination = b;
} else {
destination = a;
}
var movement = 'scroll mousedown DOMMouseScroll mousewheel keyup';
$('html, body').animate({scrollTop: destination}, 500, 'swing').bind(movement, function(){
$('html, body').stop();
});
}
// When a user clicks on a link that starts with a hashtag.
$('a[href^="#"]', context).click(function(event) {
// Store important values.
var hrefValue = $(this).attr('href');
var strippedHref = hrefValue.replace('#','');
var heightDifference = $(document).height() - $(window).height();
// Make sure that the link value is a valid selector.
if (validateSelector(hrefValue)) {
// Scroll users if there is an element with a corresponding id.
if ($(hrefValue).length > 0) {
var linkOffset = $(this.hash).offset().top;
scrollToDestination(linkOffset, heightDifference);
}
// Scroll users if there is a link with a corresponding name.
else if ($('a[name=' + strippedHref + ']').length > 0) {
var linkOffset = $('a[name=' + strippedHref + ']').offset().top;
scrollToDestination(linkOffset, heightDifference);
}
// Add the href value to the URL.
document.location.hash = strippedHref;
}
// Prevent the event's default behavior.
event.preventDefault();
});
});
}
};
}(jQuery));
;