Created
January 7, 2012 11:36
-
-
Save jorilallo/1574525 to your computer and use it in GitHub Desktop.
GitHub'fy Grove.io with dot.js
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
/* | |
** 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