Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Print GitHub markdown files
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

This comment has been minimized.

Copy link

NJichev commented Mar 26, 2018

You can also remove border from .readme if you don't want in the print document.

@hangxingliu

This comment has been minimized.

Copy link

hangxingliu commented May 23, 2018

@NJichev I create another one based on it without border and more printable:
https://gist.github.com/hangxingliu/37ff8a8754327886b8ec46ecfcbf2d86

@ashutosh2411

This comment has been minimized.

Copy link

ashutosh2411 commented Oct 22, 2018

This is for the absolute beginners, those wondering what to do with this piece of code?

@adnan-oodles

This comment has been minimized.

Copy link

adnan-oodles commented Aug 7, 2019

This is for the absolute beginners, those wondering what to do with this piece of code?

This is amazing. Thanks

@alshdavid

This comment has been minimized.

Copy link

alshdavid commented Jan 16, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.