Produce unique HTML ids for identical Markdown headings
Currently if you have markdown like
# foo
## bar
some text
# oof
## bar
other text
The resultant HTML will be invalid because it will have multiple elements with id="bar"
.
But it's not unreasonable for a document to have the same subheading under different headings. In addition to producing invalid HTML, it also makes it impossible to link to any but the first heading by that name.
Instead, I propose a semantic approach in two parts:
If the heading is a non-unique subheading with a unique parent, combine the two.
# foo
## bar
# oof
## bar
should produce ids "foo", "bar", "oof", and "oof-bar".
If the heading is non-unique and does not have a unique parent, use an increment.
# foo
## bar
# foo
## bar
should produce ids "foo", "bar", "foo-1" and "bar-1".
The latter case should be relatively rare, but nevertheless should not produce invalid HTML.