Keep header connected to its paragraph when printed— Markdown to HTML to PDF page break before headings, CSS for widows & orphans

The CSS-obvious perfect answer is:

h2, h3, h4, h5 {
  page-break-after: avoid;
}

p {
  widows: 2;
  orphans: 2;
}

https://ebooks.stackexchange.com/a/7020

except that it does not seem to work, is not honored, either in Firefox or whatever mdpdf (Markdown to PDF command line converter) is using.

The terrible solution of adding divs around headings and paragraphs:

https://stackoverflow.com/questions/12593816/markdown-scoping-with-section-and-div-blocks

… which is completely unworkable in Markdown anyway?

… though i suppose we could write our own processor to do that step.

But the CSS is really supposed to work:

https://developer.mozilla.org/en-US/docs/Web/CSS/break-before https://developer.mozilla.org/en-US/docs/Web/CSS/break-after

https://discourse.joplinapp.org/t/pagebreak-after-heading-on-pdf-export/6672/5

https://css-tricks.com/almanac/properties/b/break-after/

https://www.w3schools.com/cssref/pr_print_pageba.php

https://cssdeck.com/blog/how-to-use-csss-page-break-properties/

https://css-tricks.com/almanac/properties/p/page-break/

https://davidwalsh.name/css-page-breaks

css Page break after avoid ignored print

firefox web developer tools print preview

has been a bug: 5097 – CSS2: page-break-after does not work