You can read markdown like this
and in the QTextBrowser/QTextEdit, there is already an extra blank line, which is an extra QTextBlock. It's visible if there is any special highlighting of code blocks in the editor (which can be done by making a subclass of QSyntaxHighlighter, as in https://github.com/ec1oud/nettebook/commit/ececcd6d04f22e3764ee6b90e5520495a18e9f48 ). And when you rewrite the markdown, this comes through as an extra blank line before the ending fence, but in html it's worse: something like
that is, a whole extra <pre> tag with all the cruft that comes with it. The blank line should be treated as part of the single <pre> if it's there; but in fact it shouldn't be there at all.