Skip to content

Instantly share code, notes, and snippets.

@jorilallo
Created January 7, 2012 11:36
Show Gist options
  • Save jorilallo/1574525 to your computer and use it in GitHub Desktop.
Save jorilallo/1574525 to your computer and use it in GitHub Desktop.
GitHub'fy Grove.io with dot.js
/*
** GitHub'fy Grove.io with dot.js
**
** source: http://github.github.com/github-flavored-markdown/scripts/showdown.js
** dotjs: http://defunkt.io/dotjs/
*/
var repo = 'Organization/repo';
setInterval(function(){
$('.content').each(function() {
var text = $(this).html();
// ** GFM ** Auto-link sha1
text = text.replace(/[a-f0-9]{40}/ig, function(wholeMatch,matchIndex){
var left = text.slice(0, matchIndex), right = text.slice(matchIndex)
if (left.match(/@$/) || (left.match(/<[^>]+$/) && right.match(/^[^>]*>/))) {return wholeMatch;}
return "<a href='http://github.com/" +repo + "/commit/" + wholeMatch + "' target='_blank'>" + wholeMatch.substring(0,7) + "</a>";
});
// ** GFM ** Auto-link #issue
text = text.replace(/#([0-9]+)/ig, function(wholeMatch,issue,matchIndex){
var left = text.slice(0, matchIndex), right = text.slice(matchIndex)
if (left == "" || left.match(/[a-z0-9_\-+=.]$/) || (left.match(/<[^>]+$/) && right.match(/^[^>]*>/))) {return wholeMatch;}
return "<a href='http://github.com/" + repo + "/issues/#issue/" + issue + "' target='_blank'>" + wholeMatch + "</a>";
});
$(this).html(text);
})
}, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment