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

Fix README anchor link collision #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yeonsy
Copy link

@yeonsy yeonsy commented Jan 7, 2023

the link to #readme in TOC goes to the top of README file rather than the "readme" section, as the section name collides with an id already inserted into the page by Github. fixed by linking to a different anchor.

image

the link to `#readme` in TOC goes to the top of README file rather than the "readme" section, as the section name collides with an id already inserted into the page by Github. fixed by linking to a different anchor
@joelparkerhenderson
Copy link
Owner

joelparkerhenderson commented Jan 7, 2023

Good find, thank you for reporting this.

You've discovered a much bigger issue that just this repo: what I'm seeing is that any repo that has a "README" headline and uses an editor with a TOC generator (such as VS Code with Markdown TOC plugin) may have a similar kind of failure.

What you've found seems to also be a GitHub software regression. The broken behavior is new, and caused by GitHub staff. The broken behavior is also problematic because in general software should respect explicit user settings (i.e. the headline is definitely explicit "README" and is not "USER-CONTENT-README") rather than munging it.

Would you like the credit for reporting this to GitHub? Or if not, let me know, and I'll report it to them.

You can see the problem in more detail in the new README.md page that I just uploaded, where all the TOC links are explicit, and I replaced all the Markdown headlines "##" with explicit HTML tags e.g. <h2 id="hello-world">Hello World</h2>. GitHub's rendering still screws these up i.e. the TOC README link still fails, in the way you discovered.

You can also see the GitHub rendering problem has a much wider blast radius, by trying any other Markdown renderer. The vast majority of these that generate header ids do default to the explicit header text, as a slug, e.g. "Hello World" becomes "hello-world" (whereas GitHub renders it as "user-content-hello-word").

My preferred solution is for GitHub's internal non-standardized renderer to respect the haader explicit text (and slugify it), and also absolutely for sure respect any existing explicit id items on the page.

@yeonsy
Copy link
Author

yeonsy commented Jan 8, 2023

Interesting that explicitly chosen ids would also get modified. Maybe my memory is faulty but I remember them working fine before. Yes, please go ahead and report this to Github thank you!

@joelparkerhenderson
Copy link
Owner

joelparkerhenderson commented Jan 9, 2023

Good, will do.

I do need the links to work via typical editor "slugification" extensions, because I use tooling that auto-calculates header id anchors and corresponding TOC links, and I also have hundreds of open source repos to maintain, and they need to work similarly on other git hosts.

I'll keep this issue open while GitHub staff looks at the issue. Ticket is https://support.github.com/ticket/personal/0/1958156

@Malix-Labs
Copy link
Contributor

Any updates?

@joelparkerhenderson
Copy link
Owner

Microsoft/GitHub did not fix the issue, and deleted the ticket. For me, it's a can't fix (for the time being) within the repo because the problem is definitely due to Microsoft/GitHub wrapping.

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

Successfully merging this pull request may close these issues.

3 participants