Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

underscore is kept in links #9

Open
EdJoPaTo opened this issue Feb 18, 2021 · 4 comments
Open

underscore is kept in links #9

EdJoPaTo opened this issue Feb 18, 2021 · 4 comments

Comments

@EdJoPaTo
Copy link

EdJoPaTo commented Feb 18, 2021

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?

@ycd
Copy link
Owner

ycd commented Feb 18, 2021

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.

@EdJoPaTo
Copy link
Author

EdJoPaTo commented Feb 18, 2021

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.

@ycd
Copy link
Owner

ycd commented Feb 26, 2021

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.

@EdJoPaTo
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants