Skip to content

Instantly share code, notes, and snippets.

@nemoo
Created October 25, 2014 12:24
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save nemoo/ee47cd9ad2a5b4fdddfa to your computer and use it in GitHub Desktop.
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
// ==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);
});
}
});
@nemoo
Copy link
Author

nemoo commented Oct 25, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment