Skip to content

Instantly share code, notes, and snippets.

@davidcann
Created June 10, 2022 17:43
Show Gist options
  • 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);});

@spikespaz
Copy link

spikespaz commented Jul 17, 2024

Edited to set the font size to 10pt and made the change above (to remove copy button)

javascript:document.body.appendChild(document.querySelector(".markdown-body"));document.querySelector("[data-turbo-body]").remove();document.querySelectorAll("clipboard-copy").forEach((cc) => {cc.parentNode.removeChild(cc);});var style = document.createElement('style');style.innerHTML = '.markdown-body { font-size: 10pt; }';document.head.appendChild(style);window.print();

@aubertc
Copy link

aubertc commented Aug 13, 2024

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();

This is very nice, but only the first message in the thread is displayed with this snippet. Is that the intended behavior, @thomasverleye ?

@aubertc
Copy link

aubertc commented Aug 13, 2024

To get the whole thread, I've used

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

(that is, I used #discussion_bucket insteal of .markdown-body.)

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