/* colorizer fixer */
function unfixEntities(text) {
text = text.replace(/x14/g, '>');
text = text.replace(/x13/g, '<');
return text;
}
function fixEntities(text) {
text = text.replace(//g, 'x14');
return text;
}
function fixWhiteSpace(text) {
return text;
}
function fixStringLiterals(text) {
return text.replace(/("[^"]*")/gim, '$1');
}
function css(text) {
text = fixEntities(text);
text = fixStringLiterals(text);
// color the properites
text = text.replace(/([;{][
]*)([^:}]+)([:}])/gim, '$1$2$3');
// color the selectors
text = text.replace(/(^|[
}][
]*)([^{]*){/gim, '$1$2{');
// color the values
text = text.replace(/:([^;]*);/gm, ':$1;');
// color the comments
text = text.replace(//*([^*]*?)(*/)/gm, '');
text = fixWhiteSpace(text);
return unfixEntities(text);
}
onload = function () {
var pres = document.getElementsByTagName('pre');
// add the correct stylesheet
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/html';
link.href = '/codes/?code=42';
// add the stylesheet
document.getElementsByTagName('head')[0].appendChild(link);
// apply CSS formatting
for (var i = 0, preLen = pres.length; i < preLen; i++)
pres[i].innerHTML = css(pres[i].innerHTML);
}