// // Begin anonymous function. This is used to contain local scope variables without polutting global scope. // if (typeof(SyntaxHighlighter) == 'undefined') var SyntaxHighlighter = function() { // CommonJS if (typeof(require) != 'undefined' && typeof(XRegExp) == 'undefined') { XRegExp = require('XRegExp').XRegExp; } // 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' : false, /** Lines to highlight. */ 'highlight' : null, /** Title to be displayed above the code block. */ 'title' : 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, /** Enables quick code copy and paste from double click. */ 'quick-code' : 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, 'html-script' : false }, config : { space : ' ', /** Enables use of tags. */ scriptScriptTags : { left: /(<|<)\s*script.*?(>|>)/gi, right: /(<|<)\/\s*script\s*(>|>)/gi } }, toolbar: { /** * Generates HTML markup for the toolbar. * @param {Highlighter} highlighter Highlighter instance. * @return {String} Returns HTML markup. */ getHtml: function(highlighter) { var html = '
', items = sh.toolbar.items, list = items.list ; function defaultGetHtml(highlighter, name) { return sh.toolbar.getButtonHtml(highlighter, name, sh.config.strings[name]); }; for (var i = 0; i < list.length; i++) html += (items[list[i]].getHtml || defaultGetHtml)(highlighter, list[i]); html += '
'; return html; }, /** * Generates HTML markup for a regular button in the toolbar. * @param {Highlighter} highlighter Highlighter instance. * @param {String} commandName Command name that would be executed. * @param {String} label Label text to display. * @return {String} Returns HTML markup. */ getButtonHtml: function(highlighter, commandName, label) { return '' + label + '' ; }, /** * Event handler for a toolbar anchor. */ handler: function(e) { var target = e.target, className = target.className || '' ; function getValue(name) { var r = new RegExp(name + '_(\\w+)'), match = r.exec(className) ; return match ? match[1] : null; }; var highlighter = getHighlighterById(findParentElement(target, '.syntaxhighlighter').id), commandName = getValue('command') ; // execute the toolbar command if (highlighter && commandName) sh.toolbar.items[commandName].execute(highlighter); // disable default A click behaviour e.preventDefault(); }, /** Collection of toolbar items. */ items : { // Ordered lis of items in the toolbar. Can't expect `for (var n in items)` to be consistent. list: ['expandSource', 'help'], expandSource: { getHtml: function(highlighter) { if (highlighter.getParam('collapse') != true) return ''; var title = highlighter.getParam('title'); return sh.toolbar.getButtonHtml(highlighter, 'expandSource', title ? title : sh.config.strings.expandSource); }, execute: function(highlighter) { var div = getHighlighterDivById(highlighter.id); removeClass(div, 'collapsed'); } }, /** Command to display the about dialog window. */ help: { execute: function(highlighter) { var wnd = popup('', '_blank', 500, 250, 'scrollbars=0'), doc = wnd.document ; doc.write(sh.config.strings.aboutDialog); doc.close(); wnd.focus(); } } } }, /** * Finds all elements on the page which should be processes by SyntaxHighlighter. * * @param {Object} globalParams Optional parameters which override element's * parameters. Only used if element is specified. * * @param {Object} element Optional element to highlight. If none is * provided, all elements in the current document * are returned which qualify. * * @return {Array} Returns list of { target: DOMElement, params: Object } objects. */ findElements: function(globalParams, element) { var elements = element ? [element] : toArray(document.getElementsByTagName(sh.config.tagName)), conf = sh.config, result = [] ; // support for