Fix snippet heading anchors always scrolling to first file (for Markdown)
What does this MR do and why?
Resolves Heading anchors in a snippet always scroll to f... (#604237 - closed) for Markdown, following up to Add `header_slug_prefix` render option (gitlab-org/ruby/gems/gitlab-glfm-markdown!135 - merged).
Note
- Non-Markdown markup is already covered by Fix snippet heading anchors always scrolling to... (!242817 - merged).
- Repository file rendering is unaffected.
Manually verified in GDK-in-a-box; docs updated in doc/user/markdown.md.
Approach
Prefix heading slugs with the snippet's filename so that anchors no longer collide across files:
| File (e.g.) | Before: Both scroll to first heading | After: Each scrolls to its own |
|---|---|---|
planning.md |
<h2 id="user-content-summary"><a href="#summary"> |
<h2 id="user-content-planning-summary"><a href="#planning-summary"> |
review.md |
<h2 id="user-content-summary"><a href="#summary"> ← duplicate! |
<h2 id="user-content-review-summary"><a href="#review-summary"> |
Changes
- 9ee23a58 - bump:
gitlab-glfm-markdownto pick up the newheader_slug_prefixoption - 48263784 - refactor: extract the slug generation logic previously used for non-Markdown into
Gitlab::HeadingSlug, so Markdown can reuse it too - 667773f3 - feat: pass a filename-derived prefix as
header_slug_prefixfromGlfmMarkdownwhenuse_filename_in_anchoris set
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.