rem: var parsed; 
add: var parsed, clsRx = new RegExp("(\\s|^)" + styleSet.name + "(\\s|$)"); 
context: CodeHighlighter.init = function() {	if (!document.getElementsByTagName) return; 	if ("a".replace(/a/, function() {return "b"}) != "b") return; // throw out Safari versions that don't support replace function	// throw out older browsers		var codeEls = document.getElementsByTagName("CODE");	// collect array of all pre elements	codeEls.filter = function(f) {		var a =  new Array;		for (var i = 0; i < this.length; i++) if (f(this[i])) a[a.length] = this[i];		return a;	} 		var rules = new Array;	rules.toString = function() {		// joins regexes into one big parallel regex		var exps = new Array;		for (var i = 0; i < this.length; i++) exps.push(this[i].exp);		return exps.join("|");	}		function addRule(className, rule) {		// add a replace rule		var exp = (typeof rule.exp != "string")?String(rule.exp).substr(1, String(rule.exp).length-2):rule.exp;		// converts regex rules to strings and chops of the slashes		rules.push({			className : className,			exp : "(" + exp + ")",			length : (exp.match(/(^|[^\\])\([^?]/g) || "").length + 1, // number of subexps in rule			replacement : rule.replacement || null 		});	}		function parse(text, ignoreCase) {		// main text parsing and replacement		return text.replace(new RegExp(rules, (ignoreCase)?"gi":"g"), function() {			var i = 0, j = 1, rule;			while (rule = rules[i++]) {				if (arguments[j]) {					// if no custom replacement defined do the simple replacement					if (!rule.replacement) return "<span class=\"" + rule.className + "\">" + arguments[0] + "</span>";					else {						// replace $0 with the className then do normal replaces						var str = rule.replacement.replace("$0", rule.className);						for (var k = 1; k <= rule.length - 1; k++) str = str.replace("$" + k, arguments[j + k]);						return str;					}				} else j+= rule.length;			}		});	}		function highlightCode(styleSet) {		// clear rules array		var parsed;		rules.length = 0;				// get stylable elements by filtering out all code elements without the correct className			var stylableEls = codeEls.filter(function(item) {return (item.className.indexOf(styleSet.name)>=0)});				// add style rules to parser		for (var className in styleSet.rules) addRule(className, styleSet.rules[className]);							// replace for all elements		for (var i = 0; i < stylableEls.length; i++) {			// EVIL hack to fix IE whitespace badness if it's inside a <pre>			if (/MSIE/.test(navigator.appVersion) && stylableEls[i].parentNode.nodeName == 'PRE') {				stylableEls[i] = stylableEls[i].parentNode;								parsed = stylableEls[i].innerHTML.replace(/(<code[^>]*>)([^<]*)<\/code>/i, function() {					return arguments[1] + parse(arguments[2], styleSet.ignoreCase) + "</code>"				});				parsed = parsed.replace(/\n( *)/g, function() { 					var spaces = "";					for (var i = 0; i < arguments[1].length; i++) spaces+= "&nbsp;";					return "\n" + spaces;  				});				parsed = parsed.replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;");				parsed = parsed.replace(/\n(<\/\w+>)?/g, "<br />$1").replace(/<br \/>[\n\r\s]*<br \/>/g, "<p><br></p>");							} else parsed = parse(stylableEls[i].innerHTML, styleSet.ignoreCase);						stylableEls[i].innerHTML = parsed;		}	}		// run highlighter on all stylesets	for (var i=0; i < this.styleSets.length; i++) {		highlightCode(this.styleSets[i]);  	}}
meta: 9327	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/9327/770caef9a7a77eae247dbf48ac6324bf1ebc82d3/code_highlighter.js/buggy/code_highlighter.js