Skip to content

fix(linkindex): stop trimming leading/trailing hyphens from GithubSlug - #121

Merged
willkg merged 1 commit into
mainfrom
fix/github-slug-hyphen-trim
Aug 30, 2026
Merged

fix(linkindex): stop trimming leading/trailing hyphens from GithubSlug#121
willkg merged 1 commit into
mainfrom
fix/github-slug-hyphen-trim

Conversation

@willkg

@willkg willkg commented Aug 30, 2026

Copy link
Copy Markdown
Member

Summary

  • GithubSlug trimmed leading/trailing hyphens with strings.Trim(s, "-"), but the real github-slugger (the package GitHub itself extracted from its rendering pipeline) trims nothing at all -- not a punctuation-derived hyphen, and not even literal leading/trailing whitespace.
  • Concretely: GithubSlug("--json output") returned "json-output", but GitHub's real anchor for that heading is --json-output -- which is exactly what README.md's own [--json output](#--json-output) links assume, and markfluence check README.md reported both as "anchor not found" until this fix.
  • Removed the trim entirely rather than narrowing it, since a hyphen produced by whitespace-to-hyphen conversion and a hyphen already present in the heading text are the same character by the time trimming would run -- there's no way to "only trim whitespace-derived hyphens" without restructuring the function, and the reference implementation doesn't try to.

Test plan

  • make check (vet, fmt-check, test, build, lint) passes
  • Updated internal/linkindex/slug_test.go cases to the verified-correct values, including the "---" case the issue flagged as needing re-verification
  • Confirmed end to end: markfluence check README.md no longer reports "anchor not found" for the #--json-output links

Fixes #120

Traced the real github-slugger (the package GitHub extracted from its own
rendering pipeline) and it trims nothing at all -- not a leading/trailing
hyphen from stripped punctuation, and not even literal leading/trailing
whitespace. GithubSlug's strings.Trim(s, "-") diverged from that, so a
heading like "`--json` output" slugged to "json-output" instead of the
"--json-output" GitHub actually assigns, breaking check's anchor matching
for README.md's own "#--json-output" links (#120).
@willkg
willkg merged commit 132d0e8 into main Aug 30, 2026
1 check passed
@willkg
willkg deleted the fix/github-slug-hyphen-trim branch August 30, 2026 23:09
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.

GithubSlug trims a leading/trailing hyphen GitHub's real anchor keeps

1 participant