The issue won’t be solved by requiring blanks around horizontal rules. With that change, commonmark.js would still not produce a setext header; you’d just get a literal string ---
.
Here’s a nice case that I think illustrates some of the parsing difficulties:
> > 1. hi
> --
As this case shows, it’s not enough just to peek at the next line to see if it contains a setext header underline. For the underline might be embedded in nested block quotes and/or list items.
Note that Markdown.pl and the like aren’t very consistent about their behavior. Here’s another “nested” case where you don’t get a setext header:
- hi
- there
---
even though it works without the nesting.