Skip to content

Instantly share code, notes, and snippets.

@davidcann
Created June 10, 2022 17:43
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save davidcann/2d65fb189cdee31a6dcaa248f46afec3 to your computer and use it in GitHub Desktop.
Save davidcann/2d65fb189cdee31a6dcaa248f46afec3 to your computer and use it in GitHub Desktop.

Print GitHub Markdown Bookmarklet

javascript:document.body.appendChild(document.querySelector("#readme"));document.querySelector("header").remove();document.querySelector(".application-main").remove();document.querySelector("footer").remove();window.print();

Make it into a bookmarklet. It removes everything around the markdown article and opens the print dialog.

@betabites
Copy link

This has been extremely helpful 😄 . I'm surprised GitHub doesn't support this by default.

It may be better to use document.querySelector(".markdown-body") instead of document.querySelector("#readme"). This seems to make it work on Wiki pages as well.

@thomasverleye
Copy link

For what it's worth, with following code it works for me:

javascript:document.body.appendChild(document.querySelector(".markdown-body"));document.querySelector("[data-turbo-body]").remove();window.print();

@RandallPittmanOrSt
Copy link

Thanks! I added the following just before window.print() to remove all the ugly clipboard-copy buttons:

document.querySelectorAll("clipboard-copy").forEach((cc) => {cc.parentNode.removeChild(cc);});

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