Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
This is a PR that de-duplicates the slugs assigned as hashes of headers, if there are multiple headers with the same title in the same file, as is done by https://github.com/valeriangalliat/markdown-it-anchor and most markdown to HTML converters.
For example, if there are two
### Example
headers in the filefile.md
, the first header gets assignedfile.md#example
, and the second one getsfile.md#example-2
(formarkdown-it-anchor
< 6, which VuePress still uses) orfile.md#example-1
(formarkdown-it-anchor
>= 6, as well as markdown-toc, github-slugger, and GitHub).Currently,
check-md
wrongly considers these-n
anchors as broken. This PR fixes it.The behaviour is configurable with the introduced
uniqueSlugStartIndex
option.I took the liberty of setting the default for
uniqueSlugStartIndex
at2
, like VuePress, but of course this could be changed to only be 2 with the VuePress preset, and 1 otherwise.I also had to clear the content caches between runs of the
.check
function, because the cache content depends on the options passed to it, so the tests of theuniqueSlugStartIndex
option would not work without clearing it.Lastly, I updated
README.md
andindex.d.ts
files to reflect my changes, and theignoreFootnotes
change (they had not been updated for it).