toc
toc copied to clipboard
underscore is kept in links
Used this and found a small bug only relevant to headings containing _
.
This is the current output:
- [ISSUE_TEMPLATE.md](#issue-templatemd)
- [PULL_REQUEST_TEMPLATE.md](#pull-request-templatemd)
These are the ones github uses for its links:
- [ISSUE_TEMPLATE.md](#issue_templatemd)
- [PULL_REQUEST_TEMPLATE.md](#pull_request_templatemd)
Or is there another standard which GitHub does not comply to?
Thanks for the report!
Well, i'm pretty sure, there is something wrong with the ones below. Since markdown treats asterisks (*) and underscores (_) as indicators of emphasis. Text wrapped with one * or _ will be wrapped with an HTML .
Github markdown spec is based on CommonMark spec, as markdown engine, toc
uses Goldmark which is fully CommonMark complaint.
In their specification page (which is written in markdown). This is the link for fragments: https://github.github.com/gfm/#example-509, they also use hyphens instead of underscore.
From reading your answer I think there is a misunderstanding in my first report. Generally GitHub uses the -
for all the spaces and so on but in case of the _
in the source title it does not use a -
in the id tag. GitHub then uses a _
.
Interestingly both cmark and cmark-gfm (both installed from the Arch User Repository) dont generate id tags for the headings. md4c also does not generate id tags. discount does when provided with -f idanchor,toc
but in this case the id tag is different from the one GitHub is generating: <h1 id="PULL_REQUEST_TEMPLATE.md">PULL_REQUEST_TEMPLATE.md</h1>
(GitHub is omiting the dot and uses lowercasing).
This is both the case with # PULL_REQUEST_TEMPLATE.md
and # PULL\_REQUEST\_TEMPLATE.md
.
But you are right, using _ in Markdown is probably ending up in strange behaviour anyway.
Hey again!
Does using underscore's instead of hyphens has any visual differences in the end HTML ? If there is, I can add a flag for using underscores instead of hyphens.
I think the main question ends at the question which markdown to html implementation are you targeting? As these different implementations have different h-tag id implementations they differ quite a lot.
I have not found the exactly same implementation which github uses for the readmes and everything seems to differ at something. As generating a toc is directly depending on that… thats quite annoying.