Created
April 11, 2017 10:31
-
-
Save beevelop/a0f2c76e79610dca01550c9a93f83876 to your computer and use it in GitHub Desktop.
Print GitHub markdown files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.querySelector('#readme').setAttribute('style', 'position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 100; background-color: white') | |
document.querySelector('body').appendChild(document.querySelector('#readme')) | |
window.print() |
@NJichev I create another one based on it without border and more printable:
https://gist.github.com/hangxingliu/37ff8a8754327886b8ec46ecfcbf2d86
This is for the absolute beginners, those wondering what to do with this piece of code?
- Open developer console in your browser.
- Paste these lines in the console and hit enter.
This is for the absolute beginners, those wondering what to do with this piece of code?
- Open developer console in your browser.
- Paste these lines in the console and hit enter.
This is amazing. Thanks
I use this:
const styleElement = document.createElement('style')
styleElement.innerHTML = /*css*/`
* {
font-family: Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;
}
ins {
display: block;
page-break-after: always;
}
`
const insElements = Array.from(document.querySelectorAll('ins'))
for (const insElement of insElements) {
const parent = insElement.parentNode
parent.parentNode.insertBefore(insElement, parent.nextSibling);
parent.parentNode.removeChild(parent)
}
document.head.appendChild(styleElement)
document.body.innerHTML = document.querySelector('#readme').innerHTML
This will fix font issues on MacOS and allow you to use <ins></ins>
to insert page breaks
I ran the suggestion by @alshdavid through a minifier and set it as a bookmark in my browser.
javascript:(function(){const styleElement=document.createElement("style");styleElement.innerHTML="\n * {\n font-family: Segoe UI, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji;\n }\n\n ins {\n display: block;\n page-break-after: always;\n }\n";const insElements=Array.from(document.querySelectorAll("ins"));for(const e of insElements){const n=e.parentNode;n.parentNode.insertBefore(e,n.nextSibling),n.parentNode.removeChild(n)}document.head.appendChild(styleElement),document.body.innerHTML=document.querySelector("#readme").innerHTML;})();
Copy and paste it into a bookmark entry and click it to activate it on whatever readme file you're looking at.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also remove border from
.readme
if you don't want in the print document.