Skip to content

Instantly share code, notes, and snippets.

@liamcain
Created November 8, 2020 01:04
Show Gist options
  • Select an option

  • Save liamcain/81679412643690a7cdd13dff4dc909ce to your computer and use it in GitHub Desktop.

Select an option

Save liamcain/81679412643690a7cdd13dff4dc909ce to your computer and use it in GitHub Desktop.
Obsidian Pagebreaks
/**
Create pagebreaks in exported Obsidian PDFs.
Example:
# Heading 1
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
## Heading 2 (pagebreak before this)
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
---
--- ( <-- linebreak )
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
*/
@media print {
/* pagebreak before all ## headings */
h2 {
page-break-before: always;
}
h3,
h4 {
page-break-after: avoid;
}
pre,
blockquote {
page-break-inside: avoid;
}
/* use double <hr> ('---') to indicate a page break */
hr + hr {
page-break-before: always;
visibility: hidden;
}
:not(hr) + hr {
visibility: hidden;
}
:not(hr) + hr + :not(hr):not(h2) {
border-top: 1px solid black;
padding-top: 2em;
}
}
@EntropicNinja
Copy link

EntropicNinja commented Feb 24, 2026

Thanks for this update, I indeed took inspiration and I updated to include:

  • Natural page breaks at A4 boundaries (no forced breaks at headings)
  • Headings never stranded at bottom of page (widow protection)
  • Paragraphs that would end near the bottom move to the next page instead
  • Code blocks, tables, images, and callouts never split across pages
  • hr elements converted to explicit page breaks
  • Manual page break: type > [!pagebreak] anywhere in your note
    • Invisible in reading view, forces a page break in PDF export
    • Can be used as many times as needed
    • All clean-break rules apply from that point forward

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