Printing Markdown files on GitHub

[2013-12-30] bookmarklet, dev, hack, javascript, clientjs
(Ad, please don’t block)
GitHub displays Markdown files so nicely, it’s a shame there is no print view where all the toolbars etc. are hidden. Note that printing doesn’t necessarily mean that paper is involved. For example, on Mac OS X, you can print to PDF files.

This blog post explains three ways of printing Markdown files that are hosted on GitHub:

  • Markdown tools: such as kramdown can be used to turn Markdown files into HTML files that can be printed.
  • Safari’s Reader mode [1]: With many pages, Safari displays a “Reader” button in the address bar. Clicking it usually removes all clutter around content. You can print a page in Reader mode. Disadvantage of this solution (especially compared to the next one): You lose most of the syntax highlighting of source code.
  • Bookmarklet [2]: Create a bookmark with the following URL, click it and everything around the content is removed.
    javascript:var content = document. querySelector('article'); var body = document.querySelector('body'); body.innerHTML = ''; body.appendChild(content);
The above approaches work, e.g., with project readme files. I’ve tested them with the following file: “ServiceWorkers Explained” by Alex Russell.

References:

  1. Tip: clutter-free web content via Safari Reader
  2. Implementing bookmarklets in JavaScript