Skip to content

Instantly share code, notes, and snippets.

@rivy
Forked from nemoo/Gitwebmarkdown
Last active April 25, 2017 01:36
Show Gist options
  • Select an option

  • Save rivy/6c65bbbcae73541e42e3ab2b0bc2eeef to your computer and use it in GitHub Desktop.

Select an option

Save rivy/6c65bbbcae73541e42e3ab2b0bc2eeef 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);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment