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

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

  1. 9ee23a58 - bump: gitlab-glfm-markdown to pick up the new header_slug_prefix option
  2. 48263784 - refactor: extract the slug generation logic previously used for non-Markdown into Gitlab::HeadingSlug, so Markdown can reuse it too
  3. 667773f3 - feat: pass a filename-derived prefix as header_slug_prefix from GlfmMarkdown when use_filename_in_anchor is 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.

Edited by skkzsh

Merge request reports

Loading