1var dp = { 2 SyntaxHighlighter : {} 3}; 4 5dp.SyntaxHighlighter = { 6 parseParams: function( 7 input, 8 showGutter, 9 showControls, 10 collapseAll, 11 firstLine, 12 showColumns 13 ) 14 { 15 function getValue(list, name) 16 { 17 var regex = XRegExp('^' + name + '\\[(?<value>\\w+)\\]$', 'gi'), 18 match = null 19 ; 20 21 for (var i = 0; i < list.length; i++) 22 if ((match = XRegExp.exec(list[i], regex)) != null) 23 return match.value; 24 25 return null; 26 }; 27 28 function defaultValue(value, def) 29 { 30 return value != null ? value : def; 31 }; 32 33 function asString(value) 34 { 35 return value != null ? value.toString() : null; 36 }; 37 38 var parts = input.split(':'), 39 brushName = parts[0], 40 options = {}, 41 straight = { 'true' : true } 42 reverse = { 'true' : false }, 43 result = null, 44 defaults = SyntaxHighlighter.defaults 45 ; 46 47 for (var i in parts) 48 options[parts[i]] = 'true'; 49 50 showGutter = asString(defaultValue(showGutter, defaults.gutter)); 51 showControls = asString(defaultValue(showControls, defaults.toolbar)); 52 collapseAll = asString(defaultValue(collapseAll, defaults.collapse)); 53 showColumns = asString(defaultValue(showColumns, defaults.ruler)); 54 firstLine = asString(defaultValue(firstLine, defaults['first-line'])); 55 56 return { 57 brush : brushName, 58 gutter : defaultValue(reverse[options.nogutter], showGutter), 59 toolbar : defaultValue(reverse[options.nocontrols], showControls), 60 collapse : defaultValue(straight[options.collapse], collapseAll), 61 // ruler : defaultValue(straight[options.showcolumns], showColumns), 62 'first-line' : defaultValue(getValue(parts, 'firstline'), firstLine) 63 }; 64 }, 65 66 HighlightAll: function( 67 name, 68 showGutter /* optional */, 69 showControls /* optional */, 70 collapseAll /* optional */, 71 firstLine /* optional */, 72 showColumns /* optional */ 73 ) 74 { 75 function findValue() 76 { 77 var a = arguments; 78 79 for (var i = 0; i < a.length; i++) 80 { 81 if (a[i] === null) 82 continue; 83 84 if (typeof(a[i]) == 'string' && a[i] != '') 85 return a[i] + ''; 86 87 if (typeof(a[i]) == 'object' && a[i].value != '') 88 return a[i].value + ''; 89 } 90 91 return null; 92 }; 93 94 function findTagsByName(list, name, tagName) 95 { 96 var tags = document.getElementsByTagName(tagName); 97 98 for (var i = 0; i < tags.length; i++) 99 if (tags[i].getAttribute('name') == name) 100 list.push(tags[i]); 101 } 102 103 var elements = [], 104 highlighter = null, 105 registered = {}, 106 propertyName = 'innerHTML' 107 ; 108 109 // for some reason IE doesn't find <pre/> by name, however it does see them just fine by tag name... 110 findTagsByName(elements, name, 'pre'); 111 findTagsByName(elements, name, 'textarea'); 112 113 if (elements.length === 0) 114 return; 115 116 for (var i = 0; i < elements.length; i++) 117 { 118 var element = elements[i], 119 params = findValue( 120 element.attributes['class'], element.className, 121 element.attributes['language'], element.language 122 ), 123 language = '' 124 ; 125 126 if (params === null) 127 continue; 128 129 params = dp.SyntaxHighlighter.parseParams( 130 params, 131 showGutter, 132 showControls, 133 collapseAll, 134 firstLine, 135 showColumns 136 ); 137 138 SyntaxHighlighter.highlight(params, element); 139 } 140 } 141}; 142