Steps to replicate the issue (include links if applicable):
- Print a page to PDF with Prince (https://www.princexml.com/))
- Note: We only tested with Mediawiki version 1.39.7
What happens?:
When a headline is at the end of a page it may be orphaned:
The text belonging to this headline appears on the next page.
What should have happened instead?:
The headline and the text following the headline should appear on the next page.
Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):
MediaWiki 1.39.7
Other information (browser name/version, screenshots, etc.):
We analyzed the issue and found out that there are two CSS setting from Mediawiki, which cause this behavior from Prince.
- In mediawiki/skins/Timeless/resources/libraries/common-print.less there is the setting:
h1,
h2,
h3,
h4,
h5,
h6 {
font-weight: bold;
page-break-after: avoid;
page-break-before: avoid
}To avoid page breaks before a headline makes no sense. This should be changed to:
page-break-after: avoid !important; page-break-before: auto !important;
- Normally (at least in our case) a paragraph follows after a headline. In mediawiki/skins/Vector/resources/common/print.less there is a setting:
p:before {
content: '';
display: block;
width: 120pt;
overflow: hidden
}This setting introduces empty content before each paragraph. A headline sticks to this empty paragraph, which makes the "page-break-after: avoid;" meaningless for the real content that follows the headline.
We propose to add this setting:
h1 + p::before,
h2 + p::before,
h3 + p::before,
h4 + p::before,
h5 + p::before,
h6 + p::before {
display: none !important;
}This will avoid empty content before a paragraphs which follow a headline.



