Skip to content

Instantly share code, notes, and snippets.

@lsauer
Created September 6, 2011 10:06
Show Gist options
  • Save lsauer/1197178 to your computer and use it in GitHub Desktop.
Save lsauer/1197178 to your computer and use it in GitHub Desktop.
SyntaxHighlighter-script Render Fallback
//L.Sauer 2011; Public Domain
//renders code even without SyntaxHighlighter present
//see http://xhr2.blogspot.com/2011/09/alexgorbatchevcom-down-changing.html
//dp is the typical SyntaxHighlighter object;
//use the class 'shFallback' for styling the fallback <pre>-tag
if(typeof dp === 'undefined' ){
(function(){
var els = document.getElementsByTagName('script');
var elClass = null; //or e.g. class 'shFallback'
for(var i in els) {
if( /brush/.test(els[i].className) ){
var newDomEl = document.createElement('pre');
newDomEl.innerHTML = els[i].innerHTML.replace('<![CDATA[','').replace(']]>','');//filter CDATA Elements
if(els[i].className || elClass) newDomEl.className = elClass ? elClass : els[i].className;
els[i].parentNode.replaceChild(newDomEl, els[i]); //new, old
}
}
})();
}else {
dp.SyntaxHighlighter.HighlightAll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment