With the current outage of syntaxhighlighter at alexgorbatchev.com I searched for alternative mirrors, and realized how many people now solely rely on alexgorbatchev.com as a CDN (content deliver network) to directly load the scripts for their syntax-highlighting needs from the 'current'-fork of SH. After all the site itself promotes that use, however didn't stand up to the expected quality of service one would expect.
One crucial problem which arises in a case of an outage of remote resource delivery is that with the newer method of packing scriptlets into actual script tags, nothing will be shown without the Syntaxhighlighting-script included. There is simply no fallback!
In this newer method of scriptlet presentation the scriptlet content is embedded in XML conforming CDATA container within script-tags. In principle most users must rely on this method if a basic convenience of editing character rich code and XHTML conformity is to be upheld.
Fallback if no Syntaxhighlighter is present:
Note: If you just need a quick working solution, use this shAutloader.js instead, which already includes the Fallback functionality.
<script src='http://sites.google.com/site/xhr2code/shAutoloaderSite.js' type='text/javascript'></script>
An apropriate css-class would be for instance...
I quickly came up with a FALLBACK code-snippet, which you would best include right after you invoke the Syntaxhighlighter-Render like this:
SyntaxHighlighter.HighlightAll();
or
SyntaxHighlighter.HighlightAll('code');
Here is a better readable version of the programm
Just include this instead of dp.SyntaxHighlighter.HighlightAll(). You can style the fallback pre-tags by setting the variable elClass to a string containing the classname. Otherwise you can directly add different Fallback classes to the script tags containing your scriptlets.
One crucial problem which arises in a case of an outage of remote resource delivery is that with the newer method of packing scriptlets into actual script tags, nothing will be shown without the Syntaxhighlighting-script included. There is simply no fallback!
In this newer method of scriptlet presentation the scriptlet content is embedded in XML conforming CDATA container within script-tags. In principle most users must rely on this method if a basic convenience of editing character rich code and XHTML conformity is to be upheld.
Fallback if no Syntaxhighlighter is present:
Note: If you just need a quick working solution, use this shAutloader.js instead, which already includes the Fallback functionality.
<script src='http://sites.google.com/site/xhr2code/shAutoloaderSite.js' type='text/javascript'></script>
An apropriate css-class would be for instance...
pre,
.preFallback {
width:auto;
height:auto;
overflow:scroll;
color:#030;
padding:5px;
border:1px solid #eee;
border-radius:5px;
}
I quickly came up with a FALLBACK code-snippet, which you would best include right after you invoke the Syntaxhighlighter-Render like this:
SyntaxHighlighter.HighlightAll();
or
SyntaxHighlighter.HighlightAll('code');
Here is a better readable version of the programm
for(var i in els) {
if( /brush/.test(els[i].className) ){
var pN = els[i].parentNode;
var content = els[i].innerHTML;
newDomEl = document.createElement('pre');
newDomEl.innerHTML = content;
if(els[i].className) newDomEl.className = els[i].className;
pN.replaceChild(newDomEl, els[i]); //new, old
}
}
Just include this instead of dp.SyntaxHighlighter.HighlightAll(). You can style the fallback pre-tags by setting the variable elClass to a string containing the classname. Otherwise you can directly add different Fallback classes to the script tags containing your scriptlets.
//dp is the typical SyntaxHighlighter object;
//use the class 'shFallback' for styling the fallback
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();
}