Skip to content

Fix broken Markdown link references to headings#179

Merged
jmalloc merged 2 commits intomainfrom
copilot/fix-markdown-heading-links
Apr 6, 2026
Merged

Fix broken Markdown link references to headings#179
jmalloc merged 2 commits intomainfrom
copilot/fix-markdown-heading-links

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

Fixes Markdown link references to headings by slugifying the anchor URLs to match GitHub's heading anchor generation algorithm, using the same semantics as github-slugger.

Changes Made

  • internal/mode/usage/markdown/slug.go (new file): Implements headingSlug() matching the github-slugger algorithm — lowercases the input, keeps Unicode letters, digits, underscores, and hyphens, converts spaces to -, and strips everything else (including backtick characters).
  • internal/mode/usage/markdown/link.go: Updated linkToSpec to apply headingSlug() to the full heading text (e.g. `VARIABLE_NAME`), correctly stripping backtick formatting and producing slugified anchors like #read_dsn instead of #READ_DSN.
  • internal/mode/usage/markdown/slug_test.go (new file): Unit tests for headingSlug covering variable names with backticks, space→hyphen conversion, hyphen preservation, punctuation stripping, Unicode letters, and digits.
  • Test data files: Updated all 19 affected .md test data files to reflect the corrected lowercase anchor URLs.

Testing

  • ✅ All existing tests pass with the updated expected output.
  • ✅ New unit tests validate headingSlug behaviour against the github-slugger algorithm.

Copilot AI requested a review from jmalloc April 2, 2026 18:21
Copilot AI linked an issue Apr 2, 2026 that may be closed by this pull request
Copilot stopped work on behalf of jmalloc due to an error April 2, 2026 18:22
@jmalloc
Copy link
Copy Markdown
Member

jmalloc commented Apr 2, 2026

@copilot try again.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 2, 2026

@copilot try again.

Fixed in 27e3894. The linkToSpec function now uses strings.ToLower(s.Name()) for the heading anchor URL, generating slugified anchors like #read_dsn instead of #READ_DSN to match GitHub's Markdown heading anchor slugification. All 19 affected test data files were updated accordingly.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • makefiles.dev
    • Triggering command: /usr/bin/curl curl -sfL REDACTED /home/REDACTED/go/pkg/mod/golang.ointernal/mode/usage/markdown/testdata/spec/string/with-max-length-deprecated.md -uns�� pec/kubernetes/deprecated.md ltiple-simple.md ux-amd64/pkg/tool/linux_amd64/compile get --global l/linux_amd64/vedf21b9c331f53eef3f3c7734decce359a99263ce:internal/mode/usage/markdown/testdata/complete/non-normative.md ux-amd64/pkg/tool/linux_amd64/compile -ato�� -bool g/with-minmax-length-deprecated.md ep -errorsas -ifaceassert -nilfunc grep (dns block)
    • Triggering command: /usr/bin/curl curl -sfL REDACTED /home/REDACTED/go/pkg/mod/golang.ointernal/mode/usage/markdown/testdata/spec/string/with-sensitive-U0 -ato�� pec/kubernetes/deprecated.md ltiple-simple.md ux-amd64/pkg/tool/linux_amd64/vet -errorsas -ifaceassert l/linux_amd64/vedf21b9c331f53eef3f3c7734decce359a99263ce:internal/mode/usage/markdown/testdata/complete/normative.md ux-amd64/pkg/tool/linux_amd64/vet -ato�� -bool g/with-minmax-length-deprecated.md ndor/bin/grep -errorsas -ifaceassert -nilfunc grep (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix broken Markdown link references to headings Fix broken Markdown link references to headings Apr 2, 2026
Copy link
Copy Markdown
Member

@jmalloc jmalloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 3, 2026

Implementation should have the same semantics as https://github.com/Flet/github-slugger/blob/3461c4350868329c8530904d170358bca1d31448/regex.js

Done in 2eef036. Added headingSlug() in slug.go that implements the github-slugger algorithm: lowercases the input, keeps Unicode letters/digits/underscores/hyphens, converts spaces to -, and strips everything else. linkToSpec now applies it to the full heading text (including backticks, which get stripped by the algorithm).

Copilot AI requested a review from jmalloc April 3, 2026 20:33
@jmalloc jmalloc force-pushed the copilot/fix-markdown-heading-links branch from 2eef036 to 2ee482f Compare April 6, 2026 22:01
@jmalloc jmalloc marked this pull request as ready for review April 6, 2026 22:01
@jmalloc jmalloc enabled auto-merge April 6, 2026 22:01
@jmalloc jmalloc merged commit 36cd7dc into main Apr 6, 2026
9 checks passed
@jmalloc jmalloc deleted the copilot/fix-markdown-heading-links branch April 6, 2026 22:02
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.

Link references to headings in Markdown usage output are broken

2 participants