Make text after latex or code blocks not ruin preview

Use case or problem

When the closing “tag” of a latex or code block has additional text after it and on the same line the rest of document is rendered as part of the block.

Example:
2021-06-08-115549_536x132_escrotum
is rendered as
2021-06-08-120744_529x36_escrotum

This is a problem because the spaced repetition plugin has an option to insert metadata in the form of an HTML comment on the same line as the flashcard’s last line in order to avoid “breaking list formatting”. With this option turned on if I end a flashcard with a latex or code block then the document will not render properly.

Proposed solution

I think the above text should be rendered as
2021-06-08-120729_563x130_escrotum

That is, text after the closing “tag” of the block and on the same line as it should be rendered on the next line.

Current workaround (optional)

Related feature requests (optional)

I considered this behaviour a bug, but apparently it matches commonmark spec. I was asked to make it a feature request.