Anchors to headings do not always work

AI-generated summary

Anchors to Headings Issue

eisprinzessin reported an issue with anchors to headings not working as expected. They found that links to headings not part of an enumeration work fine, but those within an enumeration fail, directing users to the top of the topic.

awesomerobot was able to reproduce the issue, discovering that headings starting with numbers cause the problem. Manually adding the ID to the URL while on the same page resolves the issue, but linking from elsewhere does not work.

nbianca identified the root cause: headings starting with a digit are assigned IDs that start with a digit, which are invalid. They merged a PR (https://github.com/discourse/discourse/pull/14840) to fix the problem.

I have been wondering why this link does not take you through to the anchor. It’s working if the heading is not part of an enumeration:

But it fails for these and you end up at the top of the topic:

However, I cannot reproduce this in a new thread. Maybe you just need to rebake that five year old post.

I can repro this on a new topic, it seems that headings that start with numbers aren’t working for some reason. They work if you manually add the id to the URL while on the same page, but do not work when linked from elsewhere.

3 Likes

Headings that start with a digit are assigned IDs that start with a digit and those are invalid. I merged a PR to fix this problem:

https://github.com/discourse/discourse/pull/14840

3 Likes