Created
September 6, 2011 10:06
-
-
Save lsauer/1197178 to your computer and use it in GitHub Desktop.
SyntaxHighlighter-script Render Fallback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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