-
-
Save liamcain/81679412643690a7cdd13dff4dc909ce to your computer and use it in GitHub Desktop.
/** | |
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; | |
} | |
} |
This is great thank you!
It doesn't avoid page breaks after h3, h4. I've been looking for a solution everywhere with no luck. Do you have an idea?
h3,
h4 {
page-break-after: avoid;
}
I have the same problem as @PaulMndn, it doesn't avoid page breaks after headings.
This was really useful. Thanks! I added one to mine for H1, but having it skip the first one:
h1:not(:first-of-type) {
page-break-before: always;
}
For some reason now with Obsidian 1.7.0, the "double hr" aka hr + hr
css is no longer working. h2
still does. Hmm.
works
## Foo
Doesn't work
Foo
---
---
Bar
Any idea @liamcain ?
Oh, the html output was changed in Obsidian 1.6 to improve support for RTL languages so this snippet probably won't work anymore. I'll see if we can avoid wrapping the HR elements in their own
@liamcain Ok thanks. Aside from that, literally none of my .print
/ @media print
CSS seems functional anymore (Forum post)
I guess there were major changes there, hopefully there's a path forward.
The page-preview plugin still works for me. I don't think I can help debug without seeing the snippets.
The major change is that the print output now matches the DOM structure of reading mode. So as of 1.6, it should be easier to create snippets for print.
Okay. I will spend some more time looking at it. Right now I just needed the text inside codeblocks to print BLACK, so I did this 🤷♂️
.print code {
color: #000000 !important;
}
Very useful snippet!
One suggestion:
I changed the first block to
to prevent h2 from creating a page break if no text other than its parent heading comes before it. Useful if you have chapters without introduction text.