Search code examples
githubmarkdownpretty-print

Print markdown file from GitHub


I wanted to share a simple way to pretty print markdown (*.md) files from GitHub.

I found a lot of interesting approaches, mainly in this question. But none of them were updated and working, or what I was looking for (a simple and comfortable way to pretty print). Based on a couple of answers, I managed to make a solution myself that works.

Any other solutions are welcome as well.


Solution

  • I based my answer in Boris Terzic's awesome answer, so I also made a bookmarklet:

    javascript:document.querySelector('.markdown-body').setAttribute('style', 'position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 100; background-color: white; border:0');document.querySelector('body').appendChild(document.querySelector('.markdown-body'));window.print()
    

    As Boris Terzic also explained, you should add the contents of the bookmarklet (copy-paste the code above) as a bookmark. Basically, Add new bookmark, give it an appropriate name, and copy-paste the code above as the URL. Then, to use it, you have to:

    1. Open the Git webpage of the *.md file you want to print.
    2. Click on the bookmark you created; it will reformat the page, so it can print it afterwards.

    Try with an example!