I was really hoping this kind of use case would be possible in the base CommonMark spec. If it’s not, I’m willing to consider implementation-specific extensions; we’re using the CommonMark Python package.
Perhaps <p> should be special-cased indeed, because it is the default block element generated from markdown code, which also cannot be nested within its kind, and therefore easily leads to invalid HTML output.
then monkey with the stylesheet to make div.example > p styled the same as p.example. But this is unsatisfactory in two ways:
The source text looks strange. The purpose of those extra blank lines is opaque, and they tempt anyone editing the source to delete them. This is especially true in the context of larger files which don’t often have such blank lines.
The output has an extra wrapper div, not matching how we would write this by hand, which is minorly frustrating for those of us who care about writing tight, semantic HTML.