Created
October 25, 2014 12:24
-
-
Save nemoo/ee47cd9ad2a5b4fdddfa to your computer and use it in GitHub Desktop.
Tampermonkey script for chrome to display README.md files rendered as html from markdown in gitweb
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
// ==UserScript== | |
// @name Gitwebmarkdown | |
// @version 0.1 | |
// @description renders readme files in markdown | |
// @include http://yourserverhere.com/git/* | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js | |
// @require http://cdnjs.cloudflare.com/ajax/libs/showdown/0.3.1/showdown.min.js | |
// ==/UserScript== | |
var converter = new Showdown.converter(); | |
//lets find out if there is a README.md that we want to render | |
$('a.list').each(function( index ) { | |
var hrefcontent = $( this ).attr("href"); | |
var tmparray = hrefcontent.split("f="); | |
if (tmparray[1].indexOf("README.md") > -1) { | |
var thelink = $(this).parent().next().find('a').last().attr("href"); | |
$.get(thelink,function (markdown){ | |
// markdown needs two adjacent newlines to recognize it as newline! | |
var newLinedMarkdown = markdown.replace(/(?:\r\n|\r|\n)/g, "\n\n"); | |
var html = converter.makeHtml(newLinedMarkdown); | |
$('.page_footer').html(html); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this, just install tampermonkey in chrome and paste this to a new tampermonkey script.
To run it you just have to adjust the line
// @include http://yourserverhere.com/git/*
to match your needs