If I want to print a markdown file from GitHub as it appears on screen, for example: https://github.com/RestKit/RestKit/blob/master/Docs/Object%20Mapping.md
Then how can
I made a Chrome extension that does just this: GitHub Markdown Printer. It's a one-click solution for printing markdown files exactly how they appear on GitHub.
Check out the repo for more info.
I recommend taking a picture with http://awesomescreenshot.com/, then cropping the image and printing (I just did this and it worked for me :).
Works for Chromium browsers and "current" GitHub html page structure
javascript:var content = document.querySelector('.repository-content');
var toc = document.querySelector('#wiki-rightbar');
toc.innerHTML = '';
var wb = document.querySelector('.has-rightbar .wiki-body');
wb.style.marginRight = '0px';
var body = document.querySelector('body');
body.innerHTML = '';
body.appendChild(content);
window.print();
Selects the Wiki text, removes and formats the table of content, replaces the body content and calls the printer.
Here's a super simple solution: Simply select all the text in the readme that you want to print, then print and choose "Only selected text".
This worked perfectly in Chrome (including images) and required no javascript or external sites or downloading or building software.
This is what I tested on: https://github.com/kroitor/gjk.c/blob/master/README.md
Another option is pandoc. After installing (it supports Windows, Linux and Mac OS), the command would be along the lines of
pandoc file.md -f markdown --smart -s -o file.pdf
Then print the resulting PDF file.
There is also this online converter, which produced the nicest output for me: http://www.markdowntopdf.com/
Pandoc has an online demo as well.
Update 2020: on macOS Catalina this command worked for me:
brew cask install basictex
pandoc README.md -f markdown+smart -s -o out.pdf --pdf-engine=/Library/TeX/texbin/pdflatex --pdf-engine=xelatex
If you have an Instapaper account, navigate to the README.md file, save the link to Instapaper, then open the "text" option in Instapaper on that link. Most of the "clutter" is removed and the page prints well.