Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Syntax highlighting in Blogger
(function() {
var baseUrl = 'http://alexgorbatchev.com/pub/sh/current';
var theme = 'Default';
var bloggerMode = true;
function addScript (uri) {
var e = document.createElement('script'); e.type = 'text/javascript';
e.src = baseUrl + uri;
document.getElementsByTagName('script')[0].parentNode.appendChild(e);
}
function addStyle (uri) {
var e = document.createElement('link');
e.type = 'text/css';
e.rel = 'stylesheet';
e.href = baseUrl + uri;
document.getElementsByTagName('link')[0].parentNode.appendChild(e);
}
function waitFor(objStr, callback){
var interval, retryCount = 0, retryMax = 10, retryTime = 300;
var checkRun = function() {
var obj = eval(objStr);
if (typeof obj != "undefined") {
callback();
retryCount = -1;
}
if (retryCount == -1 || retryCount == retryMax) {
if (interval) window.clearInterval(interval);
if (retryCount == retryMax && window.console) {
console.log('Object "' + objStr + '" not found after ' + (retryMax * retryTime) + ' ms waiting');
} else {
return true;
}
}
}
if (!checkRun())
interval = window.setInterval(checkRun, retryTime);
}
addStyle('/styles/shCore.css');
addStyle('/styles/shTheme'+theme+'.css');
addScript('/scripts/shCore.js');
var init = function() {
var path = function() {
var args = arguments, result = [];
for(var i = 0; i < args.length; i++)
result.push(args[i].replace('@', baseUrl + '/scripts/'));
return result;
}
SyntaxHighlighter.config.bloggerMode = bloggerMode;
SyntaxHighlighter.autoloader.apply(null, path(
'applescript @shBrushAppleScript.js',
'actionscript3 as3 @shBrushAS3.js',
'bash shell @shBrushBash.js',
'coldfusion cf @shBrushColdFusion.js',
'cpp c @shBrushCpp.js',
'c# c-sharp csharp @shBrushCSharp.js',
'css @shBrushCss.js',
'delphi pascal @shBrushDelphi.js',
'diff patch pas @shBrushDiff.js',
'erl erlang @shBrushErlang.js',
'groovy @shBrushGroovy.js',
'java @shBrushJava.js',
'jfx javafx @shBrushJavaFX.js',
'js jscript javascript @shBrushJScript.js',
'perl pl @shBrushPerl.js',
'php @shBrushPhp.js',
'text plain @shBrushPlain.js',
'py python @shBrushPython.js',
'ruby rails ror rb @shBrushRuby.js',
'sass scss @shBrushSass.js',
'scala @shBrushScala.js',
'sql @shBrushSql.js',
'vb vbnet @shBrushVb.js',
'xml xhtml xslt html @shBrushXml.js'
));
SyntaxHighlighter.all();
}
waitFor('window.SyntaxHighlighter', function(){
addScript('/scripts/shAutoloader.js');
waitFor('window.SyntaxHighlighter.autoloader', init);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.