Skip to content

Instantly share code, notes, and snippets.

@jrmoran
Created August 28, 2012 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrmoran/3495419 to your computer and use it in GitHub Desktop.
Save jrmoran/3495419 to your computer and use it in GitHub Desktop.
var appendStyle = function(){
var htmlstr = '<link rel="stylesheet" '+
'href="https://gist.github.com/stylesheets/gist/embed.css" '+
'type="text/css" />';
$('head').append( htmlstr );
}
/*
look for tags [gist]#######[/gist] and for each one found, insert a
div with an id attribute that references the gist's id
*/
var processTags = function(){
$('.post').each(function(i, el){
var htmlstr = $(el).html();
var htmlstr2 = htmlstr.replace(/\[gist\](\d{7})\[\/gist\]/g, function(m, gId){
return '<div id="svc-gist-' + gId + '" ></div>';
});
$(el).html( htmlstr2 );
});
}
// search for all processed tags and load gists
var printGists = function(){
$('[id^=svc-gist-]').each(function(i, el){
var $target = $(el),
gistId = $target.attr( 'id' ).substring( 9 );
$.ajax('https://gist.github.com/'+ gistId +'.json', {
dataType:'jsonp',
success: function(data){
$target.append(data.div);
}
});
});
}
appendStyle();
processTags();
printGists();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment