One big hint: leave blank lines between block elements. (It’s the same in reStructuredText, except that it actually complains if you do it incorrectly rather than being silently inconsistent as all Markdown implementations that I know of are.) Not doing that is the main thing that’s wreaking havoc here.