Skip to content

Support GitHub style markdown heading anchor and link reference#1540

Merged
st0012 merged 2 commits intomasterfrom
support-github-style-markdown-heading-anchor
Jan 4, 2026
Merged

Support GitHub style markdown heading anchor and link reference#1540
st0012 merged 2 commits intomasterfrom
support-github-style-markdown-heading-anchor

Conversation

@st0012
Copy link
Member

@st0012 st0012 commented Jan 3, 2026

I started the work to address #1537, but I think we should just go with the GH markdown style anchor/link generation in the future.

Anchors Generated:

Context Before After
Heading == Hello (standalone) id="label-Hello" id="hello"
Heading == Hello (in class Foo) id="class-Foo-label-Hello" id="class-foo-hello"
Heading == Hello (in method #bar) id="method-i-bar-label-Hello" id="method-i-bar-hello"
Class/Module anchor id="class-Foo::Bar" id="class-foo-bar"

Legacy anchors preserved as hidden <span class="legacy-anchor"> elements. So links targeting old anchors should still work.

Links Generated:

Syntax Before After
rdoc-ref:@foo href="#label-foo" href="#foo"
rdoc-ref:Class@foo href="#class-Class-label-foo" href="#class-class-foo"
rdoc-ref:Class#method@foo href="#method-i-method-label-foo" href="#method-i-method-foo"
rdoc-ref:Class@Section Title href="#Section Title" href="#section-title"

These changes now enable Markdown links to work with GitHub-style anchors.

Markdown [link](#foo) passes through unchanged as href="#foo".

  • Before: Anchor was id="label-Foo" -> link broken
  • After: Anchor is id="foo" -> link works

Supportive Changes:

  • ToC sidebar links updated to use new anchor format

Closes #1537

@matzbot
Copy link
Collaborator

matzbot commented Jan 3, 2026

🚀 Preview deployment available at: https://923ad884.rdoc-6cd.pages.dev (commit: 00bcfa6)

@st0012 st0012 marked this pull request as draft January 3, 2026 13:20
@st0012 st0012 force-pushed the support-github-style-markdown-heading-anchor branch 3 times, most recently from f350f65 to 5172d55 Compare January 3, 2026 14:23
@st0012 st0012 marked this pull request as ready for review January 3, 2026 14:25
Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

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

+1

st0012 added 2 commits January 4, 2026 11:27
Anchors Generated:

| Context | Before | After |
|---------|--------|-------|
| Heading `== Hello` (standalone) | `id="label-Hello"` | `id="hello"` |
| Heading `== Hello` (in class Foo) | `id="class-Foo-label-Hello"` | `id="class-foo-hello"` |
| Heading `== Hello` (in method #bar) | `id="method-i-bar-label-Hello"` | `id="method-i-bar-hello"` |
| Class/Module anchor | `id="class-Foo::Bar"` | `id="class-foo-bar"` |

Legacy anchors preserved as hidden `<span class="legacy-anchor">` elements.

Links Generated:

| Syntax | Before | After |
|--------|--------|-------|
| `rdoc-ref:@foo` | `href="#label-foo"` | `href="#foo"` |
| `rdoc-ref:Class@foo` | `href="#class-Class-label-foo"` | `href="#class-class-foo"` |
| `rdoc-ref:Class#method@foo` | `href="#method-i-method-label-foo"` | `href="#method-i-method-foo"` |
| `rdoc-ref:Class@Section Title` | `href="#Section Title"` | `href="#section-title"` |

These changes now enable Markdown links to work with GitHub-style anchors.

Markdown `[link](#foo)` passes through unchanged as `href="#foo"`.

- Before: Anchor was `id="label-Foo"` -> link broken
- After: Anchor is `id="foo"` -> link works

Supportive Changes:

- ToC sidebar links updated to use new anchor format
@st0012 st0012 force-pushed the support-github-style-markdown-heading-anchor branch from 5172d55 to 00bcfa6 Compare January 4, 2026 11:27
@st0012 st0012 merged commit b2788de into master Jan 4, 2026
66 of 68 checks passed
@st0012 st0012 deleted the support-github-style-markdown-heading-anchor branch January 4, 2026 12:01
st0012 added a commit that referenced this pull request Jan 4, 2026
1. README now has a better section about supported markup formats
2. RDoc markup related reference are now consolidated under
`doc/markup_reference/rdoc.rdoc`
3. Markdown markup now has a more comprehensive reference in
`doc/markup_reference/markdown.md`

(#1536, #1538, #1540, and #1541 were all discovered when I was preparing
for this PR 😄)
@Earlopain
Copy link
Contributor

Legacy anchors preserved as hidden elements. So links targeting old anchors should still work.

I don't believe this is working as intended. I've seen PRs like ruby/ruby#15963 (among others) so I guess something unexpected is happening?

@st0012
Copy link
Member Author

st0012 commented Feb 7, 2026

@Earlopain Thanks for reporting this. I'll take a look. It may be related to #1590 as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In .md files, [link](#header) should be supported

4 participants