Resolve "User-generated permalink IDs collide with GitLab interface"
What does this MR do?
Prevents ID values automatically generated by headers in GitLab Flavored Markdown from colliding with IDs used elsewhere in the GitLab interface. This can cause confusion when, for instance, a selector looks for a merge request tab with id="pipelines"
and there is a header with the same ID earlier in the DOM.
How this works:
- All header IDs generated with GitLab Flavored Markdown are namespaced with
id="user-content_foo"
- All anchor links which point to these IDs continue to use the non-namespaced hash
<a href="#foo">...</a>
- When a page is loaded or when the
hashchange
event is triggered, javascript will automatically search for#user-content_foo
if#foo
cannot be found, and scroll to that position instead.
Before
After:
Does this MR meet the acceptance criteria?
-
Changelog entry added - Tests
-
Added for this feature/bug -
All builds are passing
-
-
Conform by the merge request performance guides -
Conform by the style guides -
Branch has no merge conflicts with master
(if it does - rebase it please) -
Squashed related commits together
What are the relevant issue numbers?
Closes #22781 (closed)
See also prior attempts to address this issue: #3908 (closed), !2023 (merged), !2024 (merged)
Merge request reports
Activity
Mentioned in commit f71a1bd1
Marked the task Changelog entry added as completed
@mikegreiling can we add tests to this?
@ClemMakesApps done.
Also noticed this was mentioned in the documentation as a caveat for selecting IDs in frontend code. I removed this since it's no longer necessary...
Added 1 commit:
- 3900986b - update gitlab flavored markdown tests to reflect namespaced ids
Mentioned in commit 2f9f539a
Added 4 commits:
- 23fc5c80 - add transparent namespace to all user-generated anchors in GitLab flavored markdown
- 2f9f539a - add CHANGELOG entry for !7631 (merged)
- afad3d97 - remove id collision caveat from documentation
- 4ed3e07b - update gitlab flavored markdown tests to reflect namespaced ids
Toggle commit list- Resolved by username-removed-408677
- Resolved by username-removed-636429
- Resolved by username-removed-636429
@mikegreiling when I was testing this, I went to http://localhost:3000/gitlab-org/gitlab-ce#user-content_open-source-software-to-collaborate-on-code and it focused the anchor tag. Can we make it not outline the hidden anchor tag?
Reassigned to @mikegreiling
@ClemMakesApps yeah, I can do this. However, I don't think many people are going to ever see or use permalinks formatted with the namespace included like you did there, so I'm not sure how common this will be :)
Added 1 commit:
- b9530852 - prevent anchor tag outline on :focus or :target pseudo-class