Fix incorrect page breaks after h1 and h2 divs

Fixes #463, fixes #337, fixes #293