Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 espaco 1
/*!
2
 * XRegExp 2.0.0 <xregexp.com> MIT License
3
 */
4
var XRegExp;XRegExp=XRegExp||function(n){"use strict";function v(n,i,r){var u;for(u in t.prototype)t.prototype.hasOwnProperty(u)&&(n[u]=t.prototype[u]);return n.xregexp={captureNames:i,isNative:!!r},n}function g(n){return(n.global?"g":"")+(n.ignoreCase?"i":"")+(n.multiline?"m":"")+(n.extended?"x":"")+(n.sticky?"y":"")}function o(n,r,u){if(!t.isRegExp(n))throw new TypeError("type RegExp expected");var f=i.replace.call(g(n)+(r||""),h,"");return u&&(f=i.replace.call(f,new RegExp("["+u+"]+","g"),"")),n=n.xregexp&&!n.xregexp.isNative?v(t(n.source,f),n.xregexp.captureNames?n.xregexp.captureNames.slice(0):null):v(new RegExp(n.source,f),null,!0)}function a(n,t){var i=n.length;if(Array.prototype.lastIndexOf)return n.lastIndexOf(t);while(i--)if(n[i]===t)return i;return-1}function s(n,t){return Object.prototype.toString.call(n).toLowerCase()==="[object "+t+"]"}function d(n){return n=n||{},n==="all"||n.all?n={natives:!0,extensibility:!0}:s(n,"string")&&(n=t.forEach(n,/[^\s,]+/,function(n){this[n]=!0},{})),n}function ut(n,t,i,u){var o=p.length,s=null,e,f;y=!0;try{while(o--)if(f=p[o],(f.scope==="all"||f.scope===i)&&(!f.trigger||f.trigger.call(u))&&(f.pattern.lastIndex=t,e=r.exec.call(f.pattern,n),e&&e.index===t)){s={output:f.handler.call(u,e,i),match:e};break}}catch(h){throw h;}finally{y=!1}return s}function b(n){t.addToken=c[n?"on":"off"],f.extensibility=n}function tt(n){RegExp.prototype.exec=(n?r:i).exec,RegExp.prototype.test=(n?r:i).test,String.prototype.match=(n?r:i).match,String.prototype.replace=(n?r:i).replace,String.prototype.split=(n?r:i).split,f.natives=n}var t,c,u,f={natives:!1,extensibility:!1},i={exec:RegExp.prototype.exec,test:RegExp.prototype.test,match:String.prototype.match,replace:String.prototype.replace,split:String.prototype.split},r={},k={},p=[],e="default",rt="class",it={"default":/^(?:\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9]\d*|x[\dA-Fa-f]{2}|u[\dA-Fa-f]{4}|c[A-Za-z]|[\s\S])|\(\?[:=!]|[?*+]\?|{\d+(?:,\d*)?}\??)/,"class":/^(?:\\(?:[0-3][0-7]{0,2}|[4-7][0-7]?|x[\dA-Fa-f]{2}|u[\dA-Fa-f]{4}|c[A-Za-z]|[\s\S]))/},et=/\$(?:{([\w$]+)}|(\d\d?|[\s\S]))/g,h=/([\s\S])(?=[\s\S]*\1)/g,nt=/^(?:[?*+]|{\d+(?:,\d*)?})\??/,ft=i.exec.call(/()??/,"")[1]===n,l=RegExp.prototype.sticky!==n,y=!1,w="gim"+(l?"y":"");return t=function(r,u){if(t.isRegExp(r)){if(u!==n)throw new TypeError("can't supply flags when constructing one RegExp from another");return o(r)}if(y)throw new Error("can't call the XRegExp constructor within token definition functions");var l=[],a=e,b={hasNamedCapture:!1,captureNames:[],hasFlag:function(n){return u.indexOf(n)>-1}},f=0,c,s,p;if(r=r===n?"":String(r),u=u===n?"":String(u),i.match.call(u,h))throw new SyntaxError("invalid duplicate regular expression flag");for(r=i.replace.call(r,/^\(\?([\w$]+)\)/,function(n,t){if(i.test.call(/[gy]/,t))throw new SyntaxError("can't use flag g or y in mode modifier");return u=i.replace.call(u+t,h,""),""}),t.forEach(u,/[\s\S]/,function(n){if(w.indexOf(n[0])<0)throw new SyntaxError("invalid regular expression flag "+n[0]);});f<r.length;)c=ut(r,f,a,b),c?(l.push(c.output),f+=c.match[0].length||1):(s=i.exec.call(it[a],r.slice(f)),s?(l.push(s[0]),f+=s[0].length):(p=r.charAt(f),p==="["?a=rt:p==="]"&&(a=e),l.push(p),++f));return v(new RegExp(l.join(""),i.replace.call(u,/[^gimy]+/g,"")),b.hasNamedCapture?b.captureNames:null)},c={on:function(n,t,r){r=r||{},n&&p.push({pattern:o(n,"g"+(l?"y":"")),handler:t,scope:r.scope||e,trigger:r.trigger||null}),r.customFlags&&(w=i.replace.call(w+r.customFlags,h,""))},off:function(){throw new Error("extensibility must be installed before using addToken");}},t.addToken=c.off,t.cache=function(n,i){var r=n+"/"+(i||"");return k[r]||(k[r]=t(n,i))},t.escape=function(n){return i.replace.call(n,/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")},t.exec=function(n,t,i,u){var e=o(t,"g"+(u&&l?"y":""),u===!1?"y":""),f;return e.lastIndex=i=i||0,f=r.exec.call(e,n),u&&f&&f.index!==i&&(f=null),t.global&&(t.lastIndex=f?e.lastIndex:0),f},t.forEach=function(n,i,r,u){for(var e=0,o=-1,f;f=t.exec(n,i,e);)r.call(u,f,++o,n,i),e=f.index+(f[0].length||1);return u},t.globalize=function(n){return o(n,"g")},t.install=function(n){n=d(n),!f.natives&&n.natives&&tt(!0),!f.extensibility&&n.extensibility&&b(!0)},t.isInstalled=function(n){return!!f[n]},t.isRegExp=function(n){return s(n,"regexp")},t.matchChain=function(n,i){return function r(n,u){for(var o=i[u].regex?i[u]:{regex:i[u]},f=[],s=function(n){f.push(o.backref?n[o.backref]||"":n[0])},e=0;e<n.length;++e)t.forEach(n[e],o.regex,s);return u===i.length-1||!f.length?f:r(f,u+1)}([n],0)},t.replace=function(i,u,f,e){var c=t.isRegExp(u),s=u,h;return c?(e===n&&u.global&&(e="all"),s=o(u,e==="all"?"g":"",e==="all"?"":"g")):e==="all"&&(s=new RegExp(t.escape(String(u)),"g")),h=r.replace.call(String(i),s,f),c&&u.global&&(u.lastIndex=0),h},t.split=function(n,t,i){return r.split.call(n,t,i)},t.test=function(n,i,r,u){return!!t.exec(n,i,r,u)},t.uninstall=function(n){n=d(n),f.natives&&n.natives&&tt(!1),f.extensibility&&n.extensibility&&b(!1)},t.union=function(n,i){var l=/(\()(?!\?)|\\([1-9]\d*)|\\[\s\S]|\[(?:[^\\\]]|\\[\s\S])*]/g,o=0,f,h,c=function(n,t,i){var r=h[o-f];if(t){if(++o,r)return"(?<"+r+">"}else if(i)return"\\"+(+i+f);return n},e=[],r,u;if(!(s(n,"array")&&n.length))throw new TypeError("patterns must be a nonempty array");for(u=0;u<n.length;++u)r=n[u],t.isRegExp(r)?(f=o,h=r.xregexp&&r.xregexp.captureNames||[],e.push(t(r.source).source.replace(l,c))):e.push(t.escape(r));return t(e.join("|"),i)},t.version="2.0.0",r.exec=function(t){var r,f,e,o,u;if(this.global||(o=this.lastIndex),r=i.exec.apply(this,arguments),r){if(!ft&&r.length>1&&a(r,"")>-1&&(e=new RegExp(this.source,i.replace.call(g(this),"g","")),i.replace.call(String(t).slice(r.index),e,function(){for(var t=1;t<arguments.length-2;++t)arguments[t]===n&&(r[t]=n)})),this.xregexp&&this.xregexp.captureNames)for(u=1;u<r.length;++u)f=this.xregexp.captureNames[u-1],f&&(r[f]=r[u]);this.global&&!r[0].length&&this.lastIndex>r.index&&(this.lastIndex=r.index)}return this.global||(this.lastIndex=o),r},r.test=function(n){return!!r.exec.call(this,n)},r.match=function(n){if(t.isRegExp(n)){if(n.global){var u=i.match.apply(this,arguments);return n.lastIndex=0,u}}else n=new RegExp(n);return r.exec.call(n,this)},r.replace=function(n,r){var e=t.isRegExp(n),u,f,h,o;return e?(n.xregexp&&(u=n.xregexp.captureNames),n.global||(o=n.lastIndex)):n+="",s(r,"function")?f=i.replace.call(String(this),n,function(){var t=arguments,i;if(u)for(t[0]=new String(t[0]),i=0;i<u.length;++i)u[i]&&(t[0][u[i]]=t[i+1]);return e&&n.global&&(n.lastIndex=t[t.length-2]+t[0].length),r.apply(null,t)}):(h=String(this),f=i.replace.call(h,n,function(){var n=arguments;return i.replace.call(String(r),et,function(t,i,r){var f;if(i){if(f=+i,f<=n.length-3)return n[f]||"";if(f=u?a(u,i):-1,f<0)throw new SyntaxError("backreference to undefined group "+t);return n[f+1]||""}if(r==="$")return"$";if(r==="&"||+r==0)return n[0];if(r==="`")return n[n.length-1].slice(0,n[n.length-2]);if(r==="'")return n[n.length-1].slice(n[n.length-2]+n[0].length);if(r=+r,!isNaN(r)){if(r>n.length-3)throw new SyntaxError("backreference to undefined group "+t);return n[r]||""}throw new SyntaxError("invalid token "+t);})})),e&&(n.lastIndex=n.global?0:o),f},r.split=function(r,u){if(!t.isRegExp(r))return i.split.apply(this,arguments);var e=String(this),h=r.lastIndex,f=[],o=0,s;return u=(u===n?-1:u)>>>0,t.forEach(e,r,function(n){n.index+n[0].length>o&&(f.push(e.slice(o,n.index)),n.length>1&&n.index<e.length&&Array.prototype.push.apply(f,n.slice(1)),s=n[0].length,o=n.index+s)}),o===e.length?(!i.test.call(r,"")||s)&&f.push(""):f.push(e.slice(o)),r.lastIndex=h,f.length>u?f.slice(0,u):f},u=c.on,u(/\\([ABCE-RTUVXYZaeg-mopqyz]|c(?![A-Za-z])|u(?![\dA-Fa-f]{4})|x(?![\dA-Fa-f]{2}))/,function(n,t){if(n[1]==="B"&&t===e)return n[0];throw new SyntaxError("invalid escape "+n[0]);},{scope:"all"}),u(/\[(\^?)]/,function(n){return n[1]?"[\\s\\S]":"\\b\\B"}),u(/(?:\(\?#[^)]*\))+/,function(n){return i.test.call(nt,n.input.slice(n.index+n[0].length))?"":"(?:)"}),u(/\\k<([\w$]+)>/,function(n){var t=isNaN(n[1])?a(this.captureNames,n[1])+1:+n[1],i=n.index+n[0].length;if(!t||t>this.captureNames.length)throw new SyntaxError("backreference to undefined group "+n[0]);return"\\"+t+(i===n.input.length||isNaN(n.input.charAt(i))?"":"(?:)")}),u(/(?:\s+|#.*)+/,function(n){return i.test.call(nt,n.input.slice(n.index+n[0].length))?"":"(?:)"},{trigger:function(){return this.hasFlag("x")},customFlags:"x"}),u(/\./,function(){return"[\\s\\S]"},{trigger:function(){return this.hasFlag("s")},customFlags:"s"}),u(/\(\?P?<([\w$]+)>/,function(n){if(!isNaN(n[1]))throw new SyntaxError("can't use integer as capture name "+n[0]);return this.captureNames.push(n[1]),this.hasNamedCapture=!0,"("}),u(/\\(\d+)/,function(n,t){if(!(t===e&&/^[1-9]/.test(n[1])&&+n[1]<=this.captureNames.length)&&n[1]!=="0")throw new SyntaxError("can't use octal escape or backreference to undefined group "+n[0]);return n[0]},{scope:"all"}),u(/\((?!\?)/,function(){return this.hasFlag("n")?"(?:":(this.captureNames.push(null),"(")},{customFlags:"n"}),typeof exports!="undefined"&&(exports.XRegExp=t),t}()
5
 
6
 
7
/*!
8
 * SyntaxHighlighter by Alex Gorbatchev
9
 * https://github.com/alexgorbatchev/SyntaxHighlighter - MIT license
10
 */
11
 
12
//
13
// Begin anonymous function. This is used to contain local scope variables without polutting global scope.
14
//
15
if (typeof(SyntaxHighlighter) == 'undefined') var SyntaxHighlighter = function() {
16
 
17
// CommonJS
18
if (typeof(require) != 'undefined' && typeof(XRegExp) == 'undefined')
19
{
20
    XRegExp = require('xregexp').XRegExp;
21
}
22
 
23
// Shortcut object which will be assigned to the SyntaxHighlighter variable.
24
// This is a shorthand for local reference in order to avoid long namespace
25
// references to SyntaxHighlighter.whatever...
26
var sh = {
27
    defaults : {
28
        /** Additional CSS class names to be added to highlighter elements. */
29
        'class-name' : '',
30
 
31
        /** First line number. */
32
        'first-line' : 1,
33
 
34
        /**
35
         * Pads line numbers. Possible values are:
36
         *
37
         *   false - don't pad line numbers.
38
         *   true  - automaticaly pad numbers with minimum required number of leading zeroes.
39
         *   [int] - length up to which pad line numbers.
40
         */
41
        'pad-line-numbers' : false,
42
 
43
        /** Lines to highlight. */
44
        'highlight' : null,
45
 
46
        /** Title to be displayed above the code block. */
47
        'title' : null,
48
 
49
        /** Enables or disables smart tabs. */
50
        'smart-tabs' : true,
51
 
52
        /** Gets or sets tab size. */
53
        'tab-size' : 4,
54
 
55
        /** Enables or disables gutter. */
56
        'gutter' : true,
57
 
58
        /** Enables or disables toolbar. */
59
        'toolbar' : true,
60
 
61
        /** Enables quick code copy and paste from double click. */
62
        'quick-code' : true,
63
 
64
        /** Forces code view to be collapsed. */
65
        'collapse' : false,
66
 
67
        /** Enables or disables automatic links. */
68
        'auto-links' : true,
69
 
70
        /** Gets or sets light mode. Equavalent to turning off gutter and toolbar. */
71
        'light' : false,
72
 
73
        'unindent' : true,
74
 
75
        'html-script' : false
76
    },
77
 
78
    config : {
79
        space : '&nbsp;',
80
 
81
        /** Enables use of <SCRIPT type="syntaxhighlighter" /> tags. */
82
        useScriptTags : true,
83
 
84
        /** Blogger mode flag. */
85
        bloggerMode : false,
86
 
87
        stripBrs : false,
88
 
89
        /** Name of the tag that SyntaxHighlighter will automatically look for. */
90
        tagName : 'pre',
91
 
92
        strings : {
93
            expandSource : 'expand source',
94
            help : '?',
95
            alert: 'SyntaxHighlighter\n\n',
96
            noBrush : 'Can\'t find brush for: ',
97
            brushNotHtmlScript : 'Brush wasn\'t configured for html-script option: ',
98
 
99
            // this is populated by the build script
100
            aboutDialog : '<%- about %>'
101
        }
102
    },
103
 
104
    /** Internal 'global' variables. */
105
    vars : {
106
        discoveredBrushes : null,
107
        highlighters : {}
108
    },
109
 
110
    /** This object is populated by user included external brush files. */
111
    brushes : {},
112
 
113
    /** Common regular expressions. */
114
    regexLib : {
115
        multiLineCComments          : XRegExp('/\\*.*?\\*/', 'gs'),
116
        singleLineCComments         : /\/\/.*$/gm,
117
        singleLinePerlComments      : /#.*$/gm,
118
        doubleQuotedString          : /"([^\\"\n]|\\.)*"/g,
119
        singleQuotedString          : /'([^\\'\n]|\\.)*'/g,
120
        multiLineDoubleQuotedString : XRegExp('"([^\\\\"]|\\\\.)*"', 'gs'),
121
        multiLineSingleQuotedString : XRegExp("'([^\\\\']|\\\\.)*'", 'gs'),
122
        xmlComments                 : XRegExp('(&lt;|<)!--.*?--(&gt;|>)', 'gs'),
123
        url                         : /\w+:\/\/[\w-.\/?%&=:@;#]*/g,
124
        phpScriptTags               : { left: /(&lt;|<)\?(?:=|php)?/g, right: /\?(&gt;|>)/g, 'eof' : true },
125
        aspScriptTags               : { left: /(&lt;|<)%=?/g, right: /%(&gt;|>)/g },
126
        scriptScriptTags            : { left: /(&lt;|<)\s*script.*?(&gt;|>)/gi, right: /(&lt;|<)\/\s*script\s*(&gt;|>)/gi }
127
    },
128
 
129
    toolbar: {
130
        /**
131
         * Generates HTML markup for the toolbar.
132
         * @param {Highlighter} highlighter Highlighter instance.
133
         * @return {String} Returns HTML markup.
134
         */
135
        getHtml: function(highlighter)
136
        {
137
            var html = '<div class="toolbar">',
138
                items = sh.toolbar.items,
139
                list = items.list
140
                ;
141
 
142
            function defaultGetHtml(highlighter, name)
143
            {
144
                return sh.toolbar.getButtonHtml(highlighter, name, sh.config.strings[name]);
145
            }
146
 
147
            for (var i = 0, l = list.length; i < l; i++)
148
            {
149
                html += (items[list[i]].getHtml || defaultGetHtml)(highlighter, list[i]);
150
            }
151
 
152
            html += '</div>';
153
 
154
            return html;
155
        },
156
 
157
        /**
158
         * Generates HTML markup for a regular button in the toolbar.
159
         * @param {Highlighter} highlighter Highlighter instance.
160
         * @param {String} commandName      Command name that would be executed.
161
         * @param {String} label            Label text to display.
162
         * @return {String}                 Returns HTML markup.
163
         */
164
        getButtonHtml: function(highlighter, commandName, label)
165
        {
166
            return '<span><a href="#" class="toolbar_item'
167
                + ' command_' + commandName
168
                + ' ' + commandName
169
                + '">' + label + '</a></span>'
170
                ;
171
        },
172
 
173
        /**
174
         * Event handler for a toolbar anchor.
175
         */
176
        handler: function(e)
177
        {
178
            var target = e.target,
179
                className = target.className || ''
180
                ;
181
 
182
            function getValue(name)
183
            {
184
                var r = new RegExp(name + '_(\\w+)'),
185
                    match = r.exec(className)
186
                    ;
187
 
188
                return match ? match[1] : null;
189
            }
190
 
191
            var highlighter = getHighlighterById(findParentElement(target, '.syntaxhighlighter').id),
192
                commandName = getValue('command')
193
                ;
194
 
195
            // execute the toolbar command
196
            if (highlighter && commandName)
197
                sh.toolbar.items[commandName].execute(highlighter);
198
 
199
            // disable default A click behaviour
200
            e.preventDefault();
201
        },
202
 
203
        /** Collection of toolbar items. */
204
        items : {
205
            // Ordered lis of items in the toolbar. Can't expect `for (var n in items)` to be consistent.
206
            list: ['expandSource', 'help'],
207
 
208
            expandSource: {
209
                getHtml: function(highlighter)
210
                {
211
                    if (highlighter.getParam('collapse') != true)
212
                        return '';
213
 
214
                    var title = highlighter.getParam('title');
215
                    return sh.toolbar.getButtonHtml(highlighter, 'expandSource', title ? title : sh.config.strings.expandSource);
216
                },
217
 
218
                execute: function(highlighter)
219
                {
220
                    var div = getHighlighterDivById(highlighter.id);
221
                    removeClass(div, 'collapsed');
222
                }
223
            },
224
 
225
            /** Command to display the about dialog window. */
226
            help: {
227
                execute: function(highlighter)
228
                {
229
                    var wnd = popup('', '_blank', 500, 250, 'scrollbars=0'),
230
                        doc = wnd.document
231
                        ;
232
 
233
                    doc.write(sh.config.strings.aboutDialog);
234
                    doc.close();
235
                    wnd.focus();
236
                }
237
            }
238
        }
239
    },
240
 
241
    /**
242
     * Finds all elements on the page which should be processes by SyntaxHighlighter.
243
     *
244
     * @param {Object} globalParams     Optional parameters which override element's
245
     *                                  parameters. Only used if element is specified.
246
     *
247
     * @param {Object} element  Optional element to highlight. If none is
248
     *                          provided, all elements in the current document
249
     *                          are returned which qualify.
250
     *
251
     * @return {Array}  Returns list of <code>{ target: DOMElement, params: Object }</code> objects.
252
     */
253
    findElements: function(globalParams, element)
254
    {
255
        var elements = element ? [element] : toArray(document.getElementsByTagName(sh.config.tagName)),
256
            conf = sh.config,
257
            result = []
258
            ;
259
 
260
        // support for <SCRIPT TYPE="syntaxhighlighter" /> feature
261
        if (conf.useScriptTags)
262
            elements = elements.concat(getSyntaxHighlighterScriptTags());
263
 
264
        if (elements.length === 0)
265
            return result;
266
 
267
        for (var i = 0, l = elements.length; i < l; i++)
268
        {
269
            var item = {
270
                target: elements[i],
271
                // local params take precedence over globals
272
                params: merge(globalParams, parseParams(elements[i].className))
273
            };
274
 
275
            if (item.params['brush'] == null)
276
                continue;
277
 
278
            result.push(item);
279
        }
280
 
281
        return result;
282
    },
283
 
284
    /**
285
     * Shorthand to highlight all elements on the page that are marked as
286
     * SyntaxHighlighter source code.
287
     *
288
     * @param {Object} globalParams     Optional parameters which override element's
289
     *                                  parameters. Only used if element is specified.
290
     *
291
     * @param {Object} element  Optional element to highlight. If none is
292
     *                          provided, all elements in the current document
293
     *                          are highlighted.
294
     */
295
    highlight: function(globalParams, element)
296
    {
297
        var elements = this.findElements(globalParams, element),
298
            propertyName = 'innerHTML',
299
            highlighter = null,
300
            conf = sh.config
301
            ;
302
 
303
        if (elements.length === 0)
304
            return;
305
 
306
        for (var i = 0, l = elements.length; i < l; i++)
307
        {
308
            var element = elements[i],
309
                target = element.target,
310
                params = element.params,
311
                brushName = params.brush,
312
                code
313
                ;
314
 
315
            if (brushName == null)
316
                continue;
317
 
318
            // Instantiate a brush
319
            if (params['html-script'] == 'true' || sh.defaults['html-script'] == true)
320
            {
321
                highlighter = new sh.HtmlScript(brushName);
322
                brushName = 'htmlscript';
323
            }
324
            else
325
            {
326
                var brush = findBrush(brushName);
327
 
328
                if (brush)
329
                    highlighter = new brush();
330
                else
331
                    continue;
332
            }
333
 
334
            code = target[propertyName];
335
 
336
            // remove CDATA from <SCRIPT/> tags if it's present
337
            if (conf.useScriptTags)
338
                code = stripCData(code);
339
 
340
            // Inject title if the attribute is present
341
            if ((target.title || '') != '')
342
                params.title = target.title;
343
 
344
            params['brush'] = brushName;
345
            highlighter.init(params);
346
            element = highlighter.getDiv(code);
347
 
348
            // carry over ID
349
            if ((target.id || '') != '')
350
                element.id = target.id;
351
 
352
            target.parentNode.replaceChild(element, target);
353
        }
354
    },
355
 
356
    /**
357
     * Main entry point for the SyntaxHighlighter.
358
     * @param {Object} params Optional params to apply to all highlighted elements.
359
     */
360
    all: function(params)
361
    {
362
        attachEvent(
363
            window,
364
            'load',
365
            function() { sh.highlight(params); }
366
        );
367
    }
368
}; // end of sh
369
 
370
/**
371
 * Checks if target DOM elements has specified CSS class.
372
 * @param {DOMElement} target Target DOM element to check.
373
 * @param {String} className Name of the CSS class to check for.
374
 * @return {Boolean} Returns true if class name is present, false otherwise.
375
 */
376
function hasClass(target, className)
377
{
378
    return target.className.indexOf(className) != -1;
379
};
380
 
381
/**
382
 * Adds CSS class name to the target DOM element.
383
 * @param {DOMElement} target Target DOM element.
384
 * @param {String} className New CSS class to add.
385
 */
386
function addClass(target, className)
387
{
388
    if (!hasClass(target, className))
389
        target.className += ' ' + className;
390
};
391
 
392
/**
393
 * Removes CSS class name from the target DOM element.
394
 * @param {DOMElement} target Target DOM element.
395
 * @param {String} className CSS class to remove.
396
 */
397
function removeClass(target, className)
398
{
399
    target.className = target.className.replace(className, '');
400
};
401
 
402
/**
403
 * Converts the source to array object. Mostly used for function arguments and
404
 * lists returned by getElementsByTagName() which aren't Array objects.
405
 * @param {List} source Source list.
406
 * @return {Array} Returns array.
407
 */
408
function toArray(source)
409
{
410
    var result = [];
411
 
412
    for (var i = 0, l = source.length; i < l; i++)
413
        result.push(source[i]);
414
 
415
    return result;
416
};
417
 
418
/**
419
 * Splits block of text into lines.
420
 * @param {String} block Block of text.
421
 * @return {Array} Returns array of lines.
422
 */
423
function splitLines(block)
424
{
425
    return block.split(/\r?\n/);
426
}
427
 
428
/**
429
 * Generates HTML ID for the highlighter.
430
 * @param {String} highlighterId Highlighter ID.
431
 * @return {String} Returns HTML ID.
432
 */
433
function getHighlighterId(id)
434
{
435
    var prefix = 'highlighter_';
436
    return id.indexOf(prefix) == 0 ? id : prefix + id;
437
};
438
 
439
/**
440
 * Finds Highlighter instance by ID.
441
 * @param {String} highlighterId Highlighter ID.
442
 * @return {Highlighter} Returns instance of the highlighter.
443
 */
444
function getHighlighterById(id)
445
{
446
    return sh.vars.highlighters[getHighlighterId(id)];
447
};
448
 
449
/**
450
 * Finds highlighter's DIV container.
451
 * @param {String} highlighterId Highlighter ID.
452
 * @return {Element} Returns highlighter's DIV element.
453
 */
454
function getHighlighterDivById(id)
455
{
456
    return document.getElementById(getHighlighterId(id));
457
};
458
 
459
/**
460
 * Stores highlighter so that getHighlighterById() can do its thing. Each
461
 * highlighter must call this method to preserve itself.
462
 * @param {Highilghter} highlighter Highlighter instance.
463
 */
464
function storeHighlighter(highlighter)
465
{
466
    sh.vars.highlighters[getHighlighterId(highlighter.id)] = highlighter;
467
};
468
 
469
/**
470
 * Looks for a child or parent node which has specified classname.
471
 * Equivalent to jQuery's $(container).find(".className")
472
 * @param {Element} target Target element.
473
 * @param {String} search Class name or node name to look for.
474
 * @param {Boolean} reverse If set to true, will go up the node tree instead of down.
475
 * @return {Element} Returns found child or parent element on null.
476
 */
477
function findElement(target, search, reverse /* optional */)
478
{
479
    if (target == null)
480
        return null;
481
 
482
    var nodes           = reverse != true ? target.childNodes : [ target.parentNode ],
483
        propertyToFind  = { '#' : 'id', '.' : 'className' }[search.substr(0, 1)] || 'nodeName',
484
        expectedValue,
485
        found
486
        ;
487
 
488
    expectedValue = propertyToFind != 'nodeName'
489
        ? search.substr(1)
490
        : search.toUpperCase()
491
        ;
492
 
493
    // main return of the found node
494
    if ((target[propertyToFind] || '').indexOf(expectedValue) != -1)
495
        return target;
496
 
497
    for (var i = 0, l = nodes.length; nodes && i < l && found == null; i++)
498
        found = findElement(nodes[i], search, reverse);
499
 
500
    return found;
501
};
502
 
503
/**
504
 * Looks for a parent node which has specified classname.
505
 * This is an alias to <code>findElement(container, className, true)</code>.
506
 * @param {Element} target Target element.
507
 * @param {String} className Class name to look for.
508
 * @return {Element} Returns found parent element on null.
509
 */
510
function findParentElement(target, className)
511
{
512
    return findElement(target, className, true);
513
};
514
 
515
/**
516
 * Finds an index of element in the array.
517
 * @ignore
518
 * @param {Object} searchElement
519
 * @param {Number} fromIndex
520
 * @return {Number} Returns index of element if found; -1 otherwise.
521
 */
522
function indexOf(array, searchElement, fromIndex)
523
{
524
    fromIndex = Math.max(fromIndex || 0, 0);
525
 
526
    for (var i = fromIndex, l = array.length; i < l; i++)
527
        if(array[i] == searchElement)
528
            return i;
529
 
530
    return -1;
531
};
532
 
533
/**
534
 * Generates a unique element ID.
535
 */
536
function guid(prefix)
537
{
538
    return (prefix || '') + Math.round(Math.random() * 1000000).toString();
539
};
540
 
541
/**
542
 * Merges two objects. Values from obj2 override values in obj1.
543
 * Function is NOT recursive and works only for one dimensional objects.
544
 * @param {Object} obj1 First object.
545
 * @param {Object} obj2 Second object.
546
 * @return {Object} Returns combination of both objects.
547
 */
548
function merge(obj1, obj2)
549
{
550
    var result = {}, name;
551
 
552
    for (name in obj1)
553
        result[name] = obj1[name];
554
 
555
    for (name in obj2)
556
        result[name] = obj2[name];
557
 
558
    return result;
559
};
560
 
561
/**
562
 * Attempts to convert string to boolean.
563
 * @param {String} value Input string.
564
 * @return {Boolean} Returns true if input was "true", false if input was "false" and value otherwise.
565
 */
566
function toBoolean(value)
567
{
568
    var result = { "true" : true, "false" : false }[value];
569
    return result == null ? value : result;
570
};
571
 
572
/**
573
 * Opens up a centered popup window.
574
 * @param {String} url      URL to open in the window.
575
 * @param {String} name     Popup name.
576
 * @param {int} width       Popup width.
577
 * @param {int} height      Popup height.
578
 * @param {String} options  window.open() options.
579
 * @return {Window}         Returns window instance.
580
 */
581
function popup(url, name, width, height, options)
582
{
583
    var x = (screen.width - width) / 2,
584
        y = (screen.height - height) / 2
585
        ;
586
 
587
    options +=  ', left=' + x +
588
                ', top=' + y +
589
                ', width=' + width +
590
                ', height=' + height
591
        ;
592
    options = options.replace(/^,/, '');
593
 
594
    var win = window.open(url, name, options);
595
    win.focus();
596
    return win;
597
};
598
 
599
/**
600
 * Adds event handler to the target object.
601
 * @param {Object} obj      Target object.
602
 * @param {String} type     Name of the event.
603
 * @param {Function} func   Handling function.
604
 */
605
function attachEvent(obj, type, func, scope)
606
{
607
    function handler(e)
608
    {
609
        e = e || window.event;
610
 
611
        if (!e.target)
612
        {
613
            e.target = e.srcElement;
614
            e.preventDefault = function()
615
            {
616
                this.returnValue = false;
617
            };
618
        }
619
 
620
        func.call(scope || window, e);
621
    };
622
 
623
    if (obj.attachEvent)
624
    {
625
        obj.attachEvent('on' + type, handler);
626
    }
627
    else
628
    {
629
        obj.addEventListener(type, handler, false);
630
    }
631
};
632
 
633
/**
634
 * Displays an alert.
635
 * @param {String} str String to display.
636
 */
637
function alert(str)
638
{
639
    window.alert(sh.config.strings.alert + str);
640
};
641
 
642
/**
643
 * Finds a brush by its alias.
644
 *
645
 * @param {String} alias        Brush alias.
646
 * @param {Boolean} showAlert   Suppresses the alert if false.
647
 * @return {Brush}              Returns bursh constructor if found, null otherwise.
648
 */
649
function findBrush(alias, showAlert)
650
{
651
    var brushes = sh.vars.discoveredBrushes,
652
        result = null
653
        ;
654
 
655
    if (brushes == null)
656
    {
657
        brushes = {};
658
 
659
        // Find all brushes
660
        for (var brush in sh.brushes)
661
        {
662
            var info = sh.brushes[brush],
663
                aliases = info.aliases
664
                ;
665
 
666
            if (aliases == null)
667
                continue;
668
 
669
            // keep the brush name
670
            info.brushName = brush.toLowerCase();
671
 
672
            for (var i = 0, l = aliases.length; i < l; i++)
673
                brushes[aliases[i]] = brush;
674
        }
675
 
676
        sh.vars.discoveredBrushes = brushes;
677
    }
678
 
679
    result = sh.brushes[brushes[alias]];
680
 
681
    if (result == null && showAlert)
682
        alert(sh.config.strings.noBrush + alias);
683
 
684
    return result;
685
};
686
 
687
/**
688
 * Executes a callback on each line and replaces each line with result from the callback.
689
 * @param {Object} str          Input string.
690
 * @param {Object} callback     Callback function taking one string argument and returning a string.
691
 */
692
function eachLine(str, callback)
693
{
694
    var lines = splitLines(str);
695
 
696
    for (var i = 0, l = lines.length; i < l; i++)
697
        lines[i] = callback(lines[i], i);
698
 
699
    // include \r to enable copy-paste on windows (ie8) without getting everything on one line
700
    return lines.join('\r\n');
701
};
702
 
703
/**
704
 * This is a special trim which only removes first and last empty lines
705
 * and doesn't affect valid leading space on the first line.
706
 *
707
 * @param {String} str   Input string
708
 * @return {String}      Returns string without empty first and last lines.
709
 */
710
function trimFirstAndLastLines(str)
711
{
712
    return str.replace(/^[ ]*[\n]+|[\n]*[ ]*$/g, '');
713
};
714
 
715
/**
716
 * Parses key/value pairs into hash object.
717
 *
718
 * Understands the following formats:
719
 * - name: word;
720
 * - name: [word, word];
721
 * - name: "string";
722
 * - name: 'string';
723
 *
724
 * For example:
725
 *   name1: value; name2: [value, value]; name3: 'value'
726
 *
727
 * @param {String} str    Input string.
728
 * @return {Object}       Returns deserialized object.
729
 */
730
function parseParams(str)
731
{
732
    var match,
733
        result = {},
734
        arrayRegex = XRegExp("^\\[(?<values>(.*?))\\]$"),
735
        pos = 0,
736
        regex = XRegExp(
737
            "(?<name>[\\w-]+)" +
738
            "\\s*:\\s*" +
739
            "(?<value>" +
740
                "[\\w%#-]+|" +      // word
741
                "\\[.*?\\]|" +      // [] array
742
                '".*?"|' +          // "" string
743
                "'.*?'" +           // '' string
744
            ")\\s*;?",
745
            "g"
746
        )
747
        ;
748
 
749
    while ((match = XRegExp.exec(str, regex, pos)) != null)
750
    {
751
        var value = match.value
752
            .replace(/^['"]|['"]$/g, '') // strip quotes from end of strings
753
            ;
754
 
755
        // try to parse array value
756
        if (value != null && arrayRegex.test(value))
757
        {
758
            var m = XRegExp.exec(value, arrayRegex);
759
            value = m.values.length > 0 ? m.values.split(/\s*,\s*/) : [];
760
        }
761
 
762
        result[match.name] = value;
763
        pos = match.index + match[0].length;
764
    }
765
 
766
    // AJJ - markdown style language option
767
    var a = str.match(/language-(.*)/);
768
    if ( a ) {
769
        result['brush'] = a[1];
770
    }
771
    else if ( str && str.indexOf('multiline') !== -1 ) {
772
        // Markdown code block without a language identifier
773
        result['brush'] = 'text';
774
    }
775
 
776
    return result;
777
};
778
 
779
/**
780
 * Wraps each line of the string into <code/> tag with given style applied to it.
781
 *
782
 * @param {String} str   Input string.
783
 * @param {String} css   Style name to apply to the string.
784
 * @return {String}      Returns input string with each line surrounded by <span/> tag.
785
 */
786
function wrapLinesWithCode(str, css)
787
{
788
    if (str == null || str.length == 0 || str == '\n')
789
        return str;
790
 
791
    str = str.replace(/</g, '&lt;');
792
 
793
    // Replace two or more sequential spaces with &nbsp; leaving last space untouched.
794
    str = str.replace(/ {2,}/g, function(m)
795
    {
796
        var spaces = '';
797
 
798
        for (var i = 0, l = m.length; i < l - 1; i++)
799
            spaces += sh.config.space;
800
 
801
        return spaces + ' ';
802
    });
803
 
804
    // Split each line and apply <span class="...">...</span> to them so that
805
    // leading spaces aren't included.
806
    if (css != null)
807
        str = eachLine(str, function(line)
808
        {
809
            if (line.length == 0)
810
                return '';
811
 
812
            var spaces = '';
813
 
814
            line = line.replace(/^(&nbsp;| )+/, function(s)
815
            {
816
                spaces = s;
817
                return '';
818
            });
819
 
820
            if (line.length == 0)
821
                return spaces;
822
 
823
            return spaces + '<code class="' + css + '">' + line + '</code>';
824
        });
825
 
826
    return str;
827
};
828
 
829
/**
830
 * Pads number with zeros until it's length is the same as given length.
831
 *
832
 * @param {Number} number   Number to pad.
833
 * @param {Number} length   Max string length with.
834
 * @return {String}         Returns a string padded with proper amount of '0'.
835
 */
836
function padNumber(number, length)
837
{
838
    var result = number.toString();
839
 
840
    while (result.length < length)
841
        result = '0' + result;
842
 
843
    return result;
844
};
845
 
846
/**
847
 * Replaces tabs with spaces.
848
 *
849
 * @param {String} code     Source code.
850
 * @param {Number} tabSize  Size of the tab.
851
 * @return {String}         Returns code with all tabs replaces by spaces.
852
 */
853
function processTabs(code, tabSize)
854
{
855
    var tab = '';
856
 
857
    for (var i = 0; i < tabSize; i++)
858
        tab += ' ';
859
 
860
    return code.replace(/\t/g, tab);
861
};
862
 
863
/**
864
 * Replaces tabs with smart spaces.
865
 *
866
 * @param {String} code    Code to fix the tabs in.
867
 * @param {Number} tabSize Number of spaces in a column.
868
 * @return {String}        Returns code with all tabs replaces with roper amount of spaces.
869
 */
870
function processSmartTabs(code, tabSize)
871
{
872
    var lines = splitLines(code),
873
        tab = '\t',
874
        spaces = ''
875
        ;
876
 
877
    // Create a string with 1000 spaces to copy spaces from...
878
    // It's assumed that there would be no indentation longer than that.
879
    for (var i = 0; i < 50; i++)
880
        spaces += '                    '; // 20 spaces * 50
881
 
882
    // This function inserts specified amount of spaces in the string
883
    // where a tab is while removing that given tab.
884
    function insertSpaces(line, pos, count)
885
    {
886
        return line.substr(0, pos)
887
            + spaces.substr(0, count)
888
            + line.substr(pos + 1, line.length) // pos + 1 will get rid of the tab
889
            ;
890
    };
891
 
892
    // Go through all the lines and do the 'smart tabs' magic.
893
    code = eachLine(code, function(line)
894
    {
895
        if (line.indexOf(tab) == -1)
896
            return line;
897
 
898
        var pos = 0;
899
 
900
        while ((pos = line.indexOf(tab)) != -1)
901
        {
902
            // This is pretty much all there is to the 'smart tabs' logic.
903
            // Based on the position within the line and size of a tab,
904
            // calculate the amount of spaces we need to insert.
905
            var spaces = tabSize - pos % tabSize;
906
            line = insertSpaces(line, pos, spaces);
907
        }
908
 
909
        return line;
910
    });
911
 
912
    return code;
913
};
914
 
915
/**
916
 * Performs various string fixes based on configuration.
917
 */
918
function fixInputString(str)
919
{
920
    var br = /<br\s*\/?>|&lt;br\s*\/?&gt;/gi;
921
 
922
    if (sh.config.bloggerMode == true)
923
        str = str.replace(br, '\n');
924
 
925
    if (sh.config.stripBrs == true)
926
        str = str.replace(br, '');
927
 
928
    return str;
929
};
930
 
931
/**
932
 * Removes all white space at the begining and end of a string.
933
 *
934
 * @param {String} str   String to trim.
935
 * @return {String}      Returns string without leading and following white space characters.
936
 */
937
function trim(str)
938
{
939
    return str.replace(/^\s+|\s+$/g, '');
940
};
941
 
942
/**
943
 * Unindents a block of text by the lowest common indent amount.
944
 * @param {String} str   Text to unindent.
945
 * @return {String}      Returns unindented text block.
946
 */
947
function unindent(str)
948
{
949
    var lines = splitLines(fixInputString(str)),
950
        indents = new Array(),
951
        regex = /^\s*/,
952
        min = 1000
953
        ;
954
 
955
    // go through every line and check for common number of indents
956
    for (var i = 0, l = lines.length; i < l && min > 0; i++)
957
    {
958
        var line = lines[i];
959
 
960
        if (trim(line).length == 0)
961
            continue;
962
 
963
        var matches = regex.exec(line);
964
 
965
        // In the event that just one line doesn't have leading white space
966
        // we can't unindent anything, so bail completely.
967
        if (matches == null)
968
            return str;
969
 
970
        min = Math.min(matches[0].length, min);
971
    }
972
 
973
    // trim minimum common number of white space from the begining of every line
974
    if (min > 0)
975
        for (var i = 0, l = lines.length; i < l; i++)
976
            lines[i] = lines[i].substr(min);
977
 
978
    return lines.join('\n');
979
};
980
 
981
/**
982
 * Callback method for Array.sort() which sorts matches by
983
 * index position and then by length.
984
 *
985
 * @param {Match} m1    Left object.
986
 * @param {Match} m2    Right object.
987
 * @return {Number}     Returns -1, 0 or -1 as a comparison result.
988
 */
989
function matchesSortCallback(m1, m2)
990
{
991
    // sort matches by index first
992
    if(m1.index < m2.index)
993
        return -1;
994
    else if(m1.index > m2.index)
995
        return 1;
996
    else
997
    {
998
        // if index is the same, sort by length
999
        if(m1.length < m2.length)
1000
            return -1;
1001
        else if(m1.length > m2.length)
1002
            return 1;
1003
    }
1004
 
1005
    return 0;
1006
};
1007
 
1008
/**
1009
 * Executes given regular expression on provided code and returns all
1010
 * matches that are found.
1011
 *
1012
 * @param {String} code    Code to execute regular expression on.
1013
 * @param {Object} regex   Regular expression item info from <code>regexList</code> collection.
1014
 * @return {Array}         Returns a list of Match objects.
1015
 */
1016
function getMatches(code, regexInfo)
1017
{
1018
    function defaultAdd(match, regexInfo)
1019
    {
1020
        return match[0];
1021
    };
1022
 
1023
    var index = 0,
1024
        match = null,
1025
        matches = [],
1026
        func = regexInfo.func ? regexInfo.func : defaultAdd
1027
        pos = 0
1028
        ;
1029
 
1030
    while((match = XRegExp.exec(code, regexInfo.regex, pos)) != null)
1031
    {
1032
        var resultMatch = func(match, regexInfo);
1033
 
1034
        if (typeof(resultMatch) == 'string')
1035
            resultMatch = [new sh.Match(resultMatch, match.index, regexInfo.css)];
1036
 
1037
        matches = matches.concat(resultMatch);
1038
        pos = match.index + match[0].length;
1039
    }
1040
 
1041
    return matches;
1042
};
1043
 
1044
/**
1045
 * Turns all URLs in the code into <a/> tags.
1046
 * @param {String} code Input code.
1047
 * @return {String} Returns code with </a> tags.
1048
 */
1049
function processUrls(code)
1050
{
1051
    var gt = /(.*)((&gt;|&lt;).*)/;
1052
 
1053
    return code.replace(sh.regexLib.url, function(m)
1054
    {
1055
        var suffix = '',
1056
            match = null
1057
            ;
1058
 
1059
        // We include &lt; and &gt; in the URL for the common cases like <http://google.com>
1060
        // The problem is that they get transformed into &lt;http://google.com&gt;
1061
        // Where as &gt; easily looks like part of the URL string.
1062
 
1063
        if (match = gt.exec(m))
1064
        {
1065
            m = match[1];
1066
            suffix = match[2];
1067
        }
1068
 
1069
        return '<a href="' + m + '">' + m + '</a>' + suffix;
1070
    });
1071
};
1072
 
1073
/**
1074
 * Finds all <SCRIPT TYPE="syntaxhighlighter" /> elementss.
1075
 * @return {Array} Returns array of all found SyntaxHighlighter tags.
1076
 */
1077
function getSyntaxHighlighterScriptTags()
1078
{
1079
    var tags = document.getElementsByTagName('script'),
1080
        result = []
1081
        ;
1082
 
1083
    for (var i = 0, l = tags.length; i < l; i++)
1084
        if (tags[i].type == 'syntaxhighlighter')
1085
            result.push(tags[i]);
1086
 
1087
    return result;
1088
};
1089
 
1090
/**
1091
 * Strips <![CDATA[]]> from <SCRIPT /> content because it should be used
1092
 * there in most cases for XHTML compliance.
1093
 * @param {String} original Input code.
1094
 * @return {String} Returns code without leading <![CDATA[]]> tags.
1095
 */
1096
function stripCData(original)
1097
{
1098
    var left = '<![CDATA[',
1099
        right = ']]>',
1100
        // for some reason IE inserts some leading blanks here
1101
        copy = trim(original),
1102
        changed = false,
1103
        leftLength = left.length,
1104
        rightLength = right.length
1105
        ;
1106
 
1107
    if (copy.indexOf(left) == 0)
1108
    {
1109
        copy = copy.substring(leftLength);
1110
        changed = true;
1111
    }
1112
 
1113
    var copyLength = copy.length;
1114
 
1115
    if (copy.indexOf(right) == copyLength - rightLength)
1116
    {
1117
        copy = copy.substring(0, copyLength - rightLength);
1118
        changed = true;
1119
    }
1120
 
1121
    return changed ? copy : original;
1122
};
1123
 
1124
 
1125
/**
1126
 * Quick code mouse double click handler.
1127
 */
1128
function quickCodeHandler(e)
1129
{
1130
    var target = e.target,
1131
        highlighterDiv = findParentElement(target, '.syntaxhighlighter'),
1132
        container = findParentElement(target, '.container'),
1133
        textarea = document.createElement('textarea'),
1134
        highlighter
1135
        ;
1136
 
1137
    if (!container || !highlighterDiv || findElement(container, 'textarea'))
1138
        return;
1139
 
1140
    highlighter = getHighlighterById(highlighterDiv.id);
1141
 
1142
    // add source class name
1143
    addClass(highlighterDiv, 'source');
1144
 
1145
    // Have to go over each line and grab it's text, can't just do it on the
1146
    // container because Firefox loses all \n where as Webkit doesn't.
1147
    var lines = container.childNodes,
1148
        code = []
1149
        ;
1150
 
1151
    for (var i = 0, l = lines.length; i < l; i++)
1152
        code.push(lines[i].innerText || lines[i].textContent);
1153
 
1154
    // using \r instead of \r or \r\n makes this work equally well on IE, FF and Webkit
1155
    code = code.join('\r');
1156
 
1157
    // For Webkit browsers, replace nbsp with a breaking space
1158
    code = code.replace(/\u00a0/g, " ");
1159
 
1160
    // inject <textarea/> tag
1161
    textarea.appendChild(document.createTextNode(code));
1162
    container.appendChild(textarea);
1163
 
1164
    // preselect all text
1165
    textarea.focus();
1166
    textarea.select();
1167
 
1168
    // set up handler for lost focus
1169
    attachEvent(textarea, 'blur', function(e)
1170
    {
1171
        textarea.parentNode.removeChild(textarea);
1172
        removeClass(highlighterDiv, 'source');
1173
    });
1174
};
1175
 
1176
/**
1177
 * Match object.
1178
 */
1179
sh.Match = function(value, index, css)
1180
{
1181
    this.value = value;
1182
    this.index = index;
1183
    this.length = value.length;
1184
    this.css = css;
1185
    this.brushName = null;
1186
};
1187
 
1188
sh.Match.prototype.toString = function()
1189
{
1190
    return this.value;
1191
};
1192
 
1193
/**
1194
 * Simulates HTML code with a scripting language embedded.
1195
 *
1196
 * @param {String} scriptBrushName Brush name of the scripting language.
1197
 */
1198
sh.HtmlScript = function(scriptBrushName)
1199
{
1200
    var brushClass = findBrush(scriptBrushName),
1201
        scriptBrush,
1202
        xmlBrush = new sh.brushes.Xml(),
1203
        bracketsRegex = null,
1204
        ref = this,
1205
        methodsToExpose = 'getDiv getHtml init'.split(' ')
1206
        ;
1207
 
1208
    if (brushClass == null)
1209
        return;
1210
 
1211
    scriptBrush = new brushClass();
1212
 
1213
    for(var i = 0, l = methodsToExpose.length; i < l; i++)
1214
        // make a closure so we don't lose the name after i changes
1215
        (function() {
1216
            var name = methodsToExpose[i];
1217
 
1218
            ref[name] = function()
1219
            {
1220
                return xmlBrush[name].apply(xmlBrush, arguments);
1221
            };
1222
        })();
1223
 
1224
    if (scriptBrush.htmlScript == null)
1225
    {
1226
        alert(sh.config.strings.brushNotHtmlScript + scriptBrushName);
1227
        return;
1228
    }
1229
 
1230
    xmlBrush.regexList.push(
1231
        { regex: scriptBrush.htmlScript.code, func: process }
1232
    );
1233
 
1234
    function offsetMatches(matches, offset)
1235
    {
1236
        for (var j = 0, l = matches.length; j < l; j++)
1237
            matches[j].index += offset;
1238
    }
1239
 
1240
    function process(match, info)
1241
    {
1242
        var code = match.code,
1243
            matches = [],
1244
            regexList = scriptBrush.regexList,
1245
            offset = match.index + match.left.length,
1246
            htmlScript = scriptBrush.htmlScript,
1247
            result
1248
            ;
1249
 
1250
        // add all matches from the code
1251
        for (var i = 0, l = regexList.length; i < l; i++)
1252
        {
1253
            result = getMatches(code, regexList[i]);
1254
            offsetMatches(result, offset);
1255
            matches = matches.concat(result);
1256
        }
1257
 
1258
        // add left script bracket
1259
        if (htmlScript.left != null && match.left != null)
1260
        {
1261
            result = getMatches(match.left, htmlScript.left);
1262
            offsetMatches(result, match.index);
1263
            matches = matches.concat(result);
1264
        }
1265
 
1266
        // add right script bracket
1267
        if (htmlScript.right != null && match.right != null)
1268
        {
1269
            result = getMatches(match.right, htmlScript.right);
1270
            offsetMatches(result, match.index + match[0].lastIndexOf(match.right));
1271
            matches = matches.concat(result);
1272
        }
1273
 
1274
        for (var j = 0, l = matches.length; j < l; j++)
1275
            matches[j].brushName = brushClass.brushName;
1276
 
1277
        return matches;
1278
    }
1279
};
1280
 
1281
/**
1282
 * Main Highlither class.
1283
 * @constructor
1284
 */
1285
sh.Highlighter = function()
1286
{
1287
    // not putting any code in here because of the prototype inheritance
1288
};
1289
 
1290
sh.Highlighter.prototype = {
1291
    /**
1292
     * Returns value of the parameter passed to the highlighter.
1293
     * @param {String} name             Name of the parameter.
1294
     * @param {Object} defaultValue     Default value.
1295
     * @return {Object}                 Returns found value or default value otherwise.
1296
     */
1297
    getParam: function(name, defaultValue)
1298
    {
1299
        var result = this.params[name];
1300
        return toBoolean(result == null ? defaultValue : result);
1301
    },
1302
 
1303
    /**
1304
     * Shortcut to document.createElement().
1305
     * @param {String} name     Name of the element to create (DIV, A, etc).
1306
     * @return {HTMLElement}    Returns new HTML element.
1307
     */
1308
    create: function(name)
1309
    {
1310
        return document.createElement(name);
1311
    },
1312
 
1313
    /**
1314
     * Applies all regular expression to the code and stores all found
1315
     * matches in the `this.matches` array.
1316
     * @param {Array} regexList     List of regular expressions.
1317
     * @param {String} code         Source code.
1318
     * @return {Array}              Returns list of matches.
1319
     */
1320
    findMatches: function(regexList, code)
1321
    {
1322
        var result = [];
1323
 
1324
        if (regexList != null)
1325
            for (var i = 0, l = regexList.length; i < l; i++)
1326
                // BUG: length returns len+1 for array if methods added to prototype chain (oising@gmail.com)
1327
                if (typeof (regexList[i]) == "object")
1328
                    result = result.concat(getMatches(code, regexList[i]));
1329
 
1330
        // sort and remove nested the matches
1331
        return this.removeNestedMatches(result.sort(matchesSortCallback));
1332
    },
1333
 
1334
    /**
1335
     * Checks to see if any of the matches are inside of other matches.
1336
     * This process would get rid of highligted strings inside comments,
1337
     * keywords inside strings and so on.
1338
     */
1339
    removeNestedMatches: function(matches)
1340
    {
1341
        // Optimized by Jose Prado (http://joseprado.com)
1342
        for (var i = 0, l = matches.length; i < l; i++)
1343
        {
1344
            if (matches[i] === null)
1345
                continue;
1346
 
1347
            var itemI = matches[i],
1348
                itemIEndPos = itemI.index + itemI.length
1349
                ;
1350
 
1351
            for (var j = i + 1, l = matches.length; j < l && matches[i] !== null; j++)
1352
            {
1353
                var itemJ = matches[j];
1354
 
1355
                if (itemJ === null)
1356
                    continue;
1357
                else if (itemJ.index > itemIEndPos)
1358
                    break;
1359
                else if (itemJ.index == itemI.index && itemJ.length > itemI.length)
1360
                    matches[i] = null;
1361
                else if (itemJ.index >= itemI.index && itemJ.index < itemIEndPos)
1362
                    matches[j] = null;
1363
            }
1364
        }
1365
 
1366
        return matches;
1367
    },
1368
 
1369
    /**
1370
     * Creates an array containing integer line numbers starting from the 'first-line' param.
1371
     * @return {Array} Returns array of integers.
1372
     */
1373
    figureOutLineNumbers: function(code)
1374
    {
1375
        var lines = [],
1376
            firstLine = parseInt(this.getParam('first-line'))
1377
            ;
1378
 
1379
        eachLine(code, function(line, index)
1380
        {
1381
            lines.push(index + firstLine);
1382
        });
1383
 
1384
        return lines;
1385
    },
1386
 
1387
    /**
1388
     * Determines if specified line number is in the highlighted list.
1389
     */
1390
    isLineHighlighted: function(lineNumber)
1391
    {
1392
        var list = this.getParam('highlight', []);
1393
 
1394
        if (typeof(list) != 'object' && list.push == null)
1395
            list = [ list ];
1396
 
1397
        return indexOf(list, lineNumber.toString()) != -1;
1398
    },
1399
 
1400
    /**
1401
     * Generates HTML markup for a single line of code while determining alternating line style.
1402
     * @param {Integer} lineNumber  Line number.
1403
     * @param {String} code Line    HTML markup.
1404
     * @return {String}             Returns HTML markup.
1405
     */
1406
    getLineHtml: function(lineIndex, lineNumber, code)
1407
    {
1408
        var classes = [
1409
            'line',
1410
            'number' + lineNumber,
1411
            'index' + lineIndex,
1412
            'alt' + (lineNumber % 2 == 0 ? 1 : 2).toString()
1413
        ];
1414
 
1415
        if (this.isLineHighlighted(lineNumber))
1416
            classes.push('highlighted');
1417
 
1418
        if (lineNumber == 0)
1419
            classes.push('break');
1420
 
1421
        return '<div class="' + classes.join(' ') + '">' + code + '</div>';
1422
    },
1423
 
1424
    /**
1425
     * Generates HTML markup for line number column.
1426
     * @param {String} code         Complete code HTML markup.
1427
     * @param {Array} lineNumbers   Calculated line numbers.
1428
     * @return {String}             Returns HTML markup.
1429
     */
1430
    getLineNumbersHtml: function(code, lineNumbers)
1431
    {
1432
        var html = '',
1433
            count = splitLines(code).length,
1434
            firstLine = parseInt(this.getParam('first-line')),
1435
            pad = this.getParam('pad-line-numbers')
1436
            ;
1437
 
1438
        if (pad == true)
1439
            pad = (firstLine + count - 1).toString().length;
1440
        else if (isNaN(pad) == true)
1441
            pad = 0;
1442
 
1443
        for (var i = 0; i < count; i++)
1444
        {
1445
            var lineNumber = lineNumbers ? lineNumbers[i] : firstLine + i,
1446
                code = lineNumber == 0 ? sh.config.space : padNumber(lineNumber, pad)
1447
                ;
1448
 
1449
            html += this.getLineHtml(i, lineNumber, code);
1450
        }
1451
 
1452
        return html;
1453
    },
1454
 
1455
    /**
1456
     * Splits block of text into individual DIV lines.
1457
     * @param {String} code         Code to highlight.
1458
     * @param {Array} lineNumbers   Calculated line numbers.
1459
     * @return {String}             Returns highlighted code in HTML form.
1460
     */
1461
    getCodeLinesHtml: function(html, lineNumbers)
1462
    {
1463
        html = trim(html);
1464
 
1465
        var lines = splitLines(html),
1466
            padLength = this.getParam('pad-line-numbers'),
1467
            firstLine = parseInt(this.getParam('first-line')),
1468
            html = '',
1469
            brushName = this.getParam('brush')
1470
            ;
1471
 
1472
        for (var i = 0, l = lines.length; i < l; i++)
1473
        {
1474
            var line = lines[i],
1475
                indent = /^(&nbsp;|\s)+/.exec(line),
1476
                spaces = null,
1477
                lineNumber = lineNumbers ? lineNumbers[i] : firstLine + i;
1478
                ;
1479
 
1480
            if (indent != null)
1481
            {
1482
                spaces = indent[0].toString();
1483
                line = line.substr(spaces.length);
1484
                spaces = spaces.replace(' ', sh.config.space);
1485
            }
1486
 
1487
            line = trim(line);
1488
 
1489
            if (line.length == 0)
1490
                line = sh.config.space;
1491
 
1492
            html += this.getLineHtml(
1493
                i,
1494
                lineNumber,
1495
                (spaces != null ? '<code class="' + brushName + ' spaces">' + spaces + '</code>' : '') + line
1496
            );
1497
        }
1498
 
1499
        return html;
1500
    },
1501
 
1502
    /**
1503
     * Returns HTML for the table title or empty string if title is null.
1504
     */
1505
    getTitleHtml: function(title)
1506
    {
1507
        return title ? '<caption>' + title + '</caption>' : '';
1508
    },
1509
 
1510
    /**
1511
     * Finds all matches in the source code.
1512
     * @param {String} code     Source code to process matches in.
1513
     * @param {Array} matches   Discovered regex matches.
1514
     * @return {String} Returns formatted HTML with processed mathes.
1515
     */
1516
    getMatchesHtml: function(code, matches)
1517
    {
1518
        var pos = 0,
1519
            result = '',
1520
            brushName = this.getParam('brush', '')
1521
            ;
1522
 
1523
        function getBrushNameCss(match)
1524
        {
1525
            var result = match ? (match.brushName || brushName) : brushName;
1526
            return result ? result + ' ' : '';
1527
        };
1528
 
1529
        // Finally, go through the final list of matches and pull the all
1530
        // together adding everything in between that isn't a match.
1531
        for (var i = 0, l = matches.length; i < l; i++)
1532
        {
1533
            var match = matches[i],
1534
                matchBrushName
1535
                ;
1536
 
1537
            if (match === null || match.length === 0)
1538
                continue;
1539
 
1540
            matchBrushName = getBrushNameCss(match);
1541
 
1542
            result += wrapLinesWithCode(code.substr(pos, match.index - pos), matchBrushName + 'plain')
1543
                    + wrapLinesWithCode(match.value, matchBrushName + match.css)
1544
                    ;
1545
 
1546
            pos = match.index + match.length + (match.offset || 0);
1547
        }
1548
 
1549
        // don't forget to add whatever's remaining in the string
1550
        result += wrapLinesWithCode(code.substr(pos), getBrushNameCss() + 'plain');
1551
 
1552
        return result;
1553
    },
1554
 
1555
    /**
1556
     * Generates HTML markup for the whole syntax highlighter.
1557
     * @param {String} code Source code.
1558
     * @return {String} Returns HTML markup.
1559
     */
1560
    getHtml: function(code)
1561
    {
1562
        var html = '',
1563
            classes = [ 'syntaxhighlighter' ],
1564
            tabSize,
1565
            matches,
1566
            lineNumbers
1567
            ;
1568
 
1569
        // process light mode
1570
        if (this.getParam('light') == true)
1571
            this.params.toolbar = this.params.gutter = false;
1572
 
1573
        className = 'syntaxhighlighter';
1574
 
1575
        if (this.getParam('collapse') == true)
1576
            classes.push('collapsed');
1577
 
1578
        if ((gutter = this.getParam('gutter')) == false)
1579
            classes.push('nogutter');
1580
 
1581
        // add custom user style name
1582
        classes.push(this.getParam('class-name'));
1583
 
1584
        // add brush alias to the class name for custom CSS
1585
        classes.push(this.getParam('brush'));
1586
 
1587
        code = trimFirstAndLastLines(code)
1588
            .replace(/\r/g, ' ') // IE lets these buggers through
1589
            ;
1590
 
1591
        tabSize = this.getParam('tab-size');
1592
 
1593
        // replace tabs with spaces
1594
        code = this.getParam('smart-tabs') == true
1595
            ? processSmartTabs(code, tabSize)
1596
            : processTabs(code, tabSize)
1597
            ;
1598
 
1599
        // unindent code by the common indentation
1600
        if (this.getParam('unindent'))
1601
            code = unindent(code);
1602
 
1603
        if (gutter)
1604
            lineNumbers = this.figureOutLineNumbers(code);
1605
 
1606
        // find matches in the code using brushes regex list
1607
        matches = this.findMatches(this.regexList, code);
1608
        // processes found matches into the html
1609
        html = this.getMatchesHtml(code, matches);
1610
        // finally, split all lines so that they wrap well
1611
        html = this.getCodeLinesHtml(html, lineNumbers);
1612
 
1613
        // finally, process the links
1614
        if (this.getParam('auto-links'))
1615
            html = processUrls(html);
1616
 
1617
        if (typeof(navigator) != 'undefined' && navigator.userAgent && navigator.userAgent.match(/MSIE/))
1618
            classes.push('ie');
1619
 
1620
        html =
1621
            '<div id="' + getHighlighterId(this.id) + '" class="' + classes.join(' ') + '">'
1622
                + (this.getParam('toolbar') ? sh.toolbar.getHtml(this) : '')
1623
                + '<table border="0" cellpadding="0" cellspacing="0">'
1624
                    + this.getTitleHtml(this.getParam('title'))
1625
                    + '<tbody>'
1626
                        + '<tr>'
1627
                            + (gutter ? '<td class="gutter">' + this.getLineNumbersHtml(code) + '</td>' : '')
1628
                            + '<td class="code">'
1629
                                + '<div class="container">'
1630
                                    + html
1631
                                + '</div>'
1632
                            + '</td>'
1633
                        + '</tr>'
1634
                    + '</tbody>'
1635
                + '</table>'
1636
            + '</div>'
1637
            ;
1638
 
1639
        return html;
1640
    },
1641
 
1642
    /**
1643
     * Highlights the code and returns complete HTML.
1644
     * @param {String} code     Code to highlight.
1645
     * @return {Element}        Returns container DIV element with all markup.
1646
     */
1647
    getDiv: function(code)
1648
    {
1649
        if (code === null)
1650
            code = '';
1651
 
1652
        this.code = code;
1653
 
1654
        var div = this.create('div');
1655
 
1656
        // create main HTML
1657
        div.innerHTML = this.getHtml(code);
1658
 
1659
        // set up click handlers
1660
        if (this.getParam('toolbar'))
1661
            attachEvent(findElement(div, '.toolbar'), 'click', sh.toolbar.handler);
1662
 
1663
        if (this.getParam('quick-code'))
1664
            attachEvent(findElement(div, '.code'), 'dblclick', quickCodeHandler);
1665
 
1666
        return div;
1667
    },
1668
 
1669
    /**
1670
     * Initializes the highlighter/brush.
1671
     *
1672
     * Constructor isn't used for initialization so that nothing executes during necessary
1673
     * `new SyntaxHighlighter.Highlighter()` call when setting up brush inheritence.
1674
     *
1675
     * @param {Hash} params Highlighter parameters.
1676
     */
1677
    init: function(params)
1678
    {
1679
        this.id = guid();
1680
 
1681
        // register this instance in the highlighters list
1682
        storeHighlighter(this);
1683
 
1684
        // local params take precedence over defaults
1685
        this.params = merge(sh.defaults, params || {})
1686
 
1687
        // process light mode
1688
        if (this.getParam('light') == true)
1689
            this.params.toolbar = this.params.gutter = false;
1690
    },
1691
 
1692
    /**
1693
     * Converts space separated list of keywords into a regular expression string.
1694
     * @param {String} str    Space separated keywords.
1695
     * @return {String}       Returns regular expression string.
1696
     */
1697
    getKeywords: function(str)
1698
    {
1699
        str = str
1700
            .replace(/^\s+|\s+$/g, '')
1701
            .replace(/\s+/g, '|')
1702
            ;
1703
 
1704
        return '\\b(?:' + str + ')\\b';
1705
    },
1706
 
1707
    /**
1708
     * Makes a brush compatible with the `html-script` functionality.
1709
     * @param {Object} regexGroup Object containing `left` and `right` regular expressions.
1710
     */
1711
    forHtmlScript: function(regexGroup)
1712
    {
1713
        var regex = { 'end' : regexGroup.right.source };
1714
 
1715
        if(regexGroup.eof)
1716
            regex.end = "(?:(?:" + regex.end + ")|$)";
1717
 
1718
        this.htmlScript = {
1719
            left : { regex: regexGroup.left, css: 'script' },
1720
            right : { regex: regexGroup.right, css: 'script' },
1721
            code : XRegExp(
1722
                "(?<left>" + regexGroup.left.source + ")" +
1723
                "(?<code>.*?)" +
1724
                "(?<right>" + regex.end + ")",
1725
                "sgi"
1726
                )
1727
        };
1728
    }
1729
}; // end of Highlighter
1730
 
1731
return sh;
1732
}(); // end of anonymous function
1733
 
1734
// CommonJS
1735
typeof(exports) != 'undefined' ? exports.SyntaxHighlighter = SyntaxHighlighter : null;
1736
 
1737
 
1738
 
1739
// JS brush
1740
;(function()
1741
{
1742
    // CommonJS
1743
    SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null);
1744
 
1745
    function Brush()
1746
    {
1747
        var keywords =  'break case catch class continue ' +
1748
                'default delete do else enum export extends false  ' +
1749
                'for function if implements import in instanceof ' +
1750
                'interface let new null package private protected ' +
1751
                'static return super switch ' +
1752
                'this throw true try typeof var while with yield';
1753
 
1754
        var r = SyntaxHighlighter.regexLib;
1755
 
1756
        this.regexList = [
1757
            { regex: r.multiLineDoubleQuotedString,                 css: 'string' },            // double quoted strings
1758
            { regex: r.multiLineSingleQuotedString,                 css: 'string' },            // single quoted strings
1759
            { regex: r.singleLineCComments,                         css: 'comments' },          // one line comments
1760
            { regex: r.multiLineCComments,                          css: 'comments' },          // multiline comments
1761
            { regex: /\s*#.*/gm,                                    css: 'preprocessor' },      // preprocessor tags like #region and #endregion
1762
            { regex: new RegExp(this.getKeywords(keywords), 'gm'),  css: 'keyword' }            // keywords
1763
            ];
1764
 
1765
        this.forHtmlScript(r.scriptScriptTags);
1766
    };
1767
 
1768
    Brush.prototype = new SyntaxHighlighter.Highlighter();
1769
    Brush.aliases   = ['js', 'jscript', 'javascript', 'json'];
1770
 
1771
    SyntaxHighlighter.brushes.JScript = Brush;
1772
 
1773
    // CommonJS
1774
    typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
1775
})();
1776
 
1777
 
1778
 
1779
// XML / HTML brush
1780
;(function()
1781
{
1782
    // CommonJS
1783
    SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null);
1784
 
1785
    function Brush()
1786
    {
1787
        function process(match, regexInfo)
1788
        {
1789
            var constructor = SyntaxHighlighter.Match,
1790
                code = match[0],
1791
                tag = XRegExp.exec(code, XRegExp('(&lt;|<)[\\s\\/\\?!]*(?<name>[:\\w-\\.]+)', 'xg')),
1792
                result = []
1793
                ;
1794
 
1795
            if (match.attributes != null)
1796
            {
1797
                var attributes,
1798
                    pos = 0,
1799
                    regex = XRegExp('(?<name> [\\w:.-]+)' +
1800
                                    '\\s*=\\s*' +
1801
                                    '(?<value> ".*?"|\'.*?\'|\\w+)',
1802
                                    'xg');
1803
 
1804
                while ((attributes = XRegExp.exec(code, regex, pos)) != null)
1805
                {
1806
                    result.push(new constructor(attributes.name, match.index + attributes.index, 'color1'));
1807
                    result.push(new constructor(attributes.value, match.index + attributes.index + attributes[0].indexOf(attributes.value), 'string'));
1808
                    pos = attributes.index + attributes[0].length;
1809
                }
1810
            }
1811
 
1812
            if (tag != null)
1813
                result.push(
1814
                    new constructor(tag.name, match.index + tag[0].indexOf(tag.name), 'keyword')
1815
                );
1816
 
1817
            return result;
1818
        }
1819
 
1820
        this.regexList = [
1821
            { regex: XRegExp('(\\&lt;|<)\\!\\[[\\w\\s]*?\\[(.|\\s)*?\\]\\](\\&gt;|>)', 'gm'),           css: 'color2' },    // <![ ... [ ... ]]>
1822
            { regex: SyntaxHighlighter.regexLib.xmlComments,                                                css: 'comments' },  // <!-- ... -->
1823
            { regex: XRegExp('(&lt;|<)[\\s\\/\\?!]*(\\w+)(?<attributes>.*?)[\\s\\/\\?]*(&gt;|>)', 'sg'), func: process }
1824
        ];
1825
    };
1826
 
1827
    Brush.prototype = new SyntaxHighlighter.Highlighter();
1828
    Brush.aliases   = ['xml', 'xhtml', 'xslt', 'html', 'plist'];
1829
 
1830
    SyntaxHighlighter.brushes.Xml = Brush;
1831
 
1832
    // CommonJS
1833
    typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
1834
})();
1835
 
1836
 
1837
 
1838
// CSS brush
1839
;(function()
1840
{
1841
    // CommonJS
1842
    SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null);
1843
 
1844
    function Brush()
1845
    {
1846
        function getKeywordsCSS(str)
1847
        {
1848
            return '\\b([a-z_]|)' + str.replace(/ /g, '(?=:)\\b|\\b([a-z_\\*]|\\*|)') + '(?=:)\\b';
1849
        };
1850
 
1851
        function getValuesCSS(str)
1852
        {
1853
            return '\\b' + str.replace(/ /g, '(?!-)(?!:)\\b|\\b()') + '\:\\b';
1854
        };
1855
 
1856
        var keywords =  'ascent azimuth background-attachment background-color background-image background-position ' +
1857
                        'background-repeat background baseline bbox border-collapse border-color border-spacing border-style border-top ' +
1858
                        'border-right border-bottom border-left border-top-color border-right-color border-bottom-color border-left-color ' +
1859
                        'border-top-style border-right-style border-bottom-style border-left-style border-top-width border-right-width ' +
1860
                        'border-bottom-width border-left-width border-width border bottom cap-height caption-side centerline clear clip color ' +
1861
                        'content counter-increment counter-reset cue-after cue-before cue cursor definition-src descent direction display ' +
1862
                        'elevation empty-cells float font-size-adjust font-family font-size font-stretch font-style font-variant font-weight font ' +
1863
                        'height left letter-spacing line-height list-style-image list-style-position list-style-type list-style margin-top ' +
1864
                        'margin-right margin-bottom margin-left margin marker-offset marks mathline max-height max-width min-height min-width orphans ' +
1865
                        'outline-color outline-style outline-width outline overflow padding-top padding-right padding-bottom padding-left padding page ' +
1866
                        'page-break-after page-break-before page-break-inside pause pause-after pause-before pitch pitch-range play-during position ' +
1867
                        'quotes right richness size slope src speak-header speak-numeral speak-punctuation speak speech-rate stemh stemv stress ' +
1868
                        'table-layout text-align top text-decoration text-indent text-shadow text-transform unicode-bidi unicode-range units-per-em ' +
1869
                        'vertical-align visibility voice-family volume white-space widows width widths word-spacing x-height z-index';
1870
 
1871
        var values =    'above absolute all always aqua armenian attr aural auto avoid baseline behind below bidi-override black blink block blue bold bolder '+
1872
                        'both bottom braille capitalize caption center center-left center-right circle close-quote code collapse compact condensed '+
1873
                        'continuous counter counters crop cross crosshair cursive dashed decimal decimal-leading-zero default digits disc dotted double '+
1874
                        'embed embossed e-resize expanded extra-condensed extra-expanded fantasy far-left far-right fast faster fixed format fuchsia '+
1875
                        'gray green groove handheld hebrew help hidden hide high higher icon inline-table inline inset inside invert italic '+
1876
                        'justify landscape large larger left-side left leftwards level lighter lime line-through list-item local loud lower-alpha '+
1877
                        'lowercase lower-greek lower-latin lower-roman lower low ltr marker maroon medium message-box middle mix move narrower '+
1878
                        'navy ne-resize no-close-quote none no-open-quote no-repeat normal nowrap n-resize nw-resize oblique olive once open-quote outset '+
1879
                        'outside overline pointer portrait pre print projection purple red relative repeat repeat-x repeat-y rgb ridge right right-side '+
1880
                        'rightwards rtl run-in screen scroll semi-condensed semi-expanded separate se-resize show silent silver slower slow '+
1881
                        'small small-caps small-caption smaller soft solid speech spell-out square s-resize static status-bar sub super sw-resize '+
1882
                        'table-caption table-cell table-column table-column-group table-footer-group table-header-group table-row table-row-group teal '+
1883
                        'text-bottom text-top thick thin top transparent tty tv ultra-condensed ultra-expanded underline upper-alpha uppercase upper-latin '+
1884
                        'upper-roman url visible wait white wider w-resize x-fast x-high x-large x-loud x-low x-slow x-small x-soft xx-large xx-small yellow';
1885
 
1886
        var fonts =     '[mM]onospace [tT]ahoma [vV]erdana [aA]rial [hH]elvetica [sS]ans-serif [sS]erif [cC]ourier mono sans serif';
1887
 
1888
        this.regexList = [
1889
            { regex: SyntaxHighlighter.regexLib.multiLineCComments,     css: 'comments' },  // multiline comments
1890
            { regex: SyntaxHighlighter.regexLib.doubleQuotedString,     css: 'string' },    // double quoted strings
1891
            { regex: SyntaxHighlighter.regexLib.singleQuotedString,     css: 'string' },    // single quoted strings
1892
            { regex: /\#[a-fA-F0-9]{3,6}/g,                             css: 'value' },     // html colors
1893
            { regex: /(-?\d+)(\.\d+)?(px|em|pt|\:|\%|)/g,               css: 'value' },     // sizes
1894
            { regex: /!important/g,                                     css: 'color3' },    // !important
1895
            { regex: new RegExp(getKeywordsCSS(keywords), 'gm'),        css: 'keyword' },   // keywords
1896
            { regex: new RegExp(getValuesCSS(values), 'g'),             css: 'value' },     // values
1897
            { regex: new RegExp(this.getKeywords(fonts), 'g'),          css: 'color1' }     // fonts
1898
            ];
1899
 
1900
        this.forHtmlScript({
1901
            left: /(&lt;|<)\s*style.*?(&gt;|>)/gi,
1902
            right: /(&lt;|<)\/\s*style\s*(&gt;|>)/gi
1903
            });
1904
    };
1905
 
1906
    Brush.prototype = new SyntaxHighlighter.Highlighter();
1907
    Brush.aliases   = ['css'];
1908
 
1909
    SyntaxHighlighter.brushes.CSS = Brush;
1910
 
1911
    // CommonJS
1912
    typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
1913
})();
1914
 
1915
 
1916
 
1917
// PHP brush
1918
;(function()
1919
{
1920
    // CommonJS
1921
    SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null);
1922
 
1923
    function Brush()
1924
    {
1925
        var funcs   =   'abs acos acosh addcslashes addslashes ' +
1926
                        'array_change_key_case array_chunk array_combine array_count_values array_diff '+
1927
                        'array_diff_assoc array_diff_key array_diff_uassoc array_diff_ukey array_fill '+
1928
                        'array_filter array_flip array_intersect array_intersect_assoc array_intersect_key '+
1929
                        'array_intersect_uassoc array_intersect_ukey array_key_exists array_keys array_map '+
1930
                        'array_merge array_merge_recursive array_multisort array_pad array_pop array_product '+
1931
                        'array_push array_rand array_reduce array_reverse array_search array_shift '+
1932
                        'array_slice array_splice array_sum array_udiff array_udiff_assoc '+
1933
                        'array_udiff_uassoc array_uintersect array_uintersect_assoc '+
1934
                        'array_uintersect_uassoc array_unique array_unshift array_values array_walk '+
1935
                        'array_walk_recursive atan atan2 atanh base64_decode base64_encode base_convert '+
1936
                        'basename bcadd bccomp bcdiv bcmod bcmul bindec bindtextdomain bzclose bzcompress '+
1937
                        'bzdecompress bzerrno bzerror bzerrstr bzflush bzopen bzread bzwrite ceil chdir '+
1938
                        'checkdate checkdnsrr chgrp chmod chop chown chr chroot chunk_split class_exists '+
1939
                        'closedir closelog copy cos cosh count count_chars date decbin dechex decoct '+
1940
                        'deg2rad delete ebcdic2ascii echo empty end ereg ereg_replace eregi eregi_replace error_log '+
1941
                        'error_reporting escapeshellarg escapeshellcmd eval exec exit exp explode extension_loaded '+
1942
                        'feof fflush fgetc fgetcsv fgets fgetss file_exists file_get_contents file_put_contents '+
1943
                        'fileatime filectime filegroup fileinode filemtime fileowner fileperms filesize filetype '+
1944
                        'floatval flock floor flush fmod fnmatch fopen fpassthru fprintf fputcsv fputs fread fscanf '+
1945
                        'fseek fsockopen fstat ftell ftok getallheaders getcwd getdate getenv gethostbyaddr gethostbyname '+
1946
                        'gethostbynamel getimagesize getlastmod getmxrr getmygid getmyinode getmypid getmyuid getopt '+
1947
                        'getprotobyname getprotobynumber getrandmax getrusage getservbyname getservbyport gettext '+
1948
                        'gettimeofday gettype glob gmdate gmmktime ini_alter ini_get ini_get_all ini_restore ini_set '+
1949
                        'interface_exists intval ip2long is_a is_array is_bool is_callable is_dir is_double '+
1950
                        'is_executable is_file is_finite is_float is_infinite is_int is_integer is_link is_long '+
1951
                        'is_nan is_null is_numeric is_object is_readable is_real is_resource is_scalar is_soap_fault '+
1952
                        'is_string is_subclass_of is_uploaded_file is_writable is_writeable mkdir mktime nl2br '+
1953
                        'parse_ini_file parse_str parse_url passthru pathinfo print readlink realpath rewind rewinddir rmdir '+
1954
                        'round str_ireplace str_pad str_repeat str_replace str_rot13 str_shuffle str_split '+
1955
                        'str_word_count strcasecmp strchr strcmp strcoll strcspn strftime strip_tags stripcslashes '+
1956
                        'stripos stripslashes stristr strlen strnatcasecmp strnatcmp strncasecmp strncmp strpbrk '+
1957
                        'strpos strptime strrchr strrev strripos strrpos strspn strstr strtok strtolower strtotime '+
1958
                        'strtoupper strtr strval substr substr_compare';
1959
 
1960
        var keywords =  'abstract and array as break case catch cfunction class clone const continue declare default die do ' +
1961
                        'else elseif enddeclare endfor endforeach endif endswitch endwhile extends final finally for foreach ' +
1962
                        'function global goto if implements include include_once interface instanceof insteadof namespace new ' +
1963
                        'old_function or private protected public return require require_once static switch ' +
1964
                        'trait throw try use var while xor yield ';
1965
 
1966
        var constants   = '__FILE__ __LINE__ __METHOD__ __FUNCTION__ __CLASS__';
1967
 
1968
        this.regexList = [
1969
            { regex: SyntaxHighlighter.regexLib.singleLineCComments,    css: 'comments' },          // one line comments
1970
            { regex: SyntaxHighlighter.regexLib.multiLineCComments,     css: 'comments' },          // multiline comments
1971
            { regex: SyntaxHighlighter.regexLib.doubleQuotedString,     css: 'string' },            // double quoted strings
1972
            { regex: SyntaxHighlighter.regexLib.singleQuotedString,     css: 'string' },            // single quoted strings
1973
            { regex: /\$\w+/g,                                          css: 'variable' },          // variables
1974
            { regex: new RegExp(this.getKeywords(funcs), 'gmi'),        css: 'functions' },         // common functions
1975
            { regex: new RegExp(this.getKeywords(constants), 'gmi'),    css: 'constants' },         // constants
1976
            { regex: new RegExp(this.getKeywords(keywords), 'gm'),      css: 'keyword' }            // keyword
1977
            ];
1978
 
1979
        this.forHtmlScript(SyntaxHighlighter.regexLib.phpScriptTags);
1980
    };
1981
 
1982
    Brush.prototype = new SyntaxHighlighter.Highlighter();
1983
    Brush.aliases   = ['php'];
1984
 
1985
    SyntaxHighlighter.brushes.Php = Brush;
1986
 
1987
    // CommonJS
1988
    typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
1989
})();
1990
 
1991
 
1992
;(function()
1993
{
1994
    // CommonJS
1995
    SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null);
1996
 
1997
    function Brush()
1998
    {
1999
        var funcs   =   'abs avg case cast coalesce convert count current_timestamp ' +
2000
                        'current_user day isnull left lower month nullif replace right ' +
2001
                        'session_user space substring sum system_user upper user year';
2002
 
2003
        var keywords =  'absolute action add after alter as asc at authorization begin bigint ' +
2004
                        'binary bit by cascade char character check checkpoint close collate ' +
2005
                        'column commit committed connect connection constraint contains continue ' +
2006
                        'create cube current current_date current_time cursor database date ' +
2007
                        'deallocate dec decimal declare default delete desc distinct double drop ' +
2008
                        'dynamic else end end-exec escape except exec execute false fetch first ' +
2009
                        'float for force foreign forward free from full function global goto grant ' +
2010
                        'group grouping having hour ignore index inner insensitive insert instead ' +
2011
                        'int integer intersect into is isolation key last level load local max min ' +
2012
                        'minute modify move name national nchar next no numeric of off on only ' +
2013
                        'open option order out output partial password precision prepare primary ' +
2014
                        'prior privileges procedure public read real references relative repeatable ' +
2015
                        'restrict return returns revoke rollback rollup rows rule schema scroll ' +
2016
                        'second section select sequence serializable set size smallint static ' +
2017
                        'statistics table temp temporary then time timestamp to top transaction ' +
2018
                        'translation trigger true truncate uncommitted union unique update values ' +
2019
                        'varchar varying view when where with work';
2020
 
2021
        var operators = 'all and any between cross in join like not null or outer some';
2022
 
2023
        this.regexList = [
2024
            { regex: /--(.*)$/gm,                                               css: 'comments' },   // one line comments
2025
            { regex: /\/\*([^\*][\s\S]*?)?\*\//gm,                              css: 'comments' },   // multi line comments
2026
            { regex: SyntaxHighlighter.regexLib.multiLineDoubleQuotedString,    css: 'string' },     // double quoted strings
2027
            { regex: SyntaxHighlighter.regexLib.multiLineSingleQuotedString,    css: 'string' },     // single quoted strings
2028
            { regex: new RegExp(this.getKeywords(funcs), 'gmi'),                css: 'color2' },     // functions
2029
            { regex: new RegExp(this.getKeywords(operators), 'gmi'),            css: 'color1' },     // operators and such
2030
            { regex: new RegExp(this.getKeywords(keywords), 'gmi'),             css: 'keyword' }     // keyword
2031
            ];
2032
    };
2033
 
2034
    Brush.prototype = new SyntaxHighlighter.Highlighter();
2035
    Brush.aliases   = ['sql'];
2036
 
2037
    SyntaxHighlighter.brushes.Sql = Brush;
2038
 
2039
    // CommonJS
2040
    typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
2041
})();
2042
 
2043
 
2044
 
2045
;(function()
2046
{
2047
    // CommonJS
2048
    SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null);
2049
 
2050
    function Brush()
2051
    {
2052
    };
2053
 
2054
    Brush.prototype = new SyntaxHighlighter.Highlighter();
2055
    Brush.aliases   = ['text', 'plain'];
2056
 
2057
    SyntaxHighlighter.brushes.Plain = Brush;
2058
 
2059
    // CommonJS
2060
    typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
2061
})();
2062
 
2063
 
2064
SyntaxHighlighter.all();