Skip to content

Preserve # prefix for unresolved cross-references#1676

Merged
st0012 merged 1 commit intomasterfrom
fix-crossref-hash-preservation
Apr 10, 2026
Merged

Preserve # prefix for unresolved cross-references#1676
st0012 merged 1 commit intomasterfrom
fix-crossref-hash-preservation

Conversation

@st0012
Copy link
Copy Markdown
Member

@st0012 st0012 commented Apr 9, 2026

Summary

When #name doesn't resolve to a method, the cross-reference handler was stripping the # and returning just the name. Now the original text including # is restored when the lookup fails.

This fixes rendering of text like #no-space-heading in Markdown paragraphs, where the # was silently dropped in the final HTML.

Refactoring

  • cross_reference no longer mutates its name parameter; uses a separate display variable for #-stripped text
  • link returns nil for unresolved references instead of returning bare text, letting the caller decide what to display
  • Label handling is hoisted out of the case branches so it's shared between resolved refs and bare label references (@foo)
  • Move new test methods before private helper section to follow file convention

Found while investigating blockquote lazy continuation in #1627#text (not a valid heading) inside a blockquote was rendered without the #.

@matzbot
Copy link
Copy Markdown
Collaborator

matzbot commented Apr 9, 2026

🚀 Preview deployment available at: https://bba08f0c.rdoc-6cd.pages.dev (commit: d9383ba)

@st0012 st0012 force-pushed the fix-crossref-hash-preservation branch 2 times, most recently from 5471aac to 64f4ea1 Compare April 9, 2026 16:34
@st0012 st0012 requested a review from Copilot April 9, 2026 17:10
@st0012 st0012 added the bug label Apr 9, 2026
@st0012 st0012 marked this pull request as ready for review April 9, 2026 17:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates RDoc::Markup::ToHtmlCrossref so that when a #method-style cross-reference cannot be resolved, the original text (including the leading #) is preserved instead of being silently stripped, improving Markdown rendering for strings like #no-space-heading.

Changes:

  • Refactors cross_reference to avoid mutating the name argument and to separate display text from lookup text.
  • Changes link to return nil when a reference cannot be resolved, and hoists label (@...) handling to be shared across branches.
  • Updates/extends crossref tests to assert the new unresolved-#... behavior and the new link return contract.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/rdoc/markup/to_html_crossref.rb Adjusts crossref display/lookup behavior, changes unresolved-link handling to nil, refactors label-anchor generation
test/rdoc/markup/to_html_crossref_test.rb Updates link expectation for unresolved refs and adds regression test to ensure # is preserved when unresolved

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@st0012 st0012 force-pushed the fix-crossref-hash-preservation branch from 64f4ea1 to 031de0c Compare April 9, 2026 19:50
@st0012 st0012 requested a review from Copilot April 9, 2026 19:51
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
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 st0012 force-pushed the fix-crossref-hash-preservation branch from 031de0c to c24ebbd Compare April 10, 2026 16:10
When `#name` doesn't resolve to a method, the cross-reference handler
was stripping the `#` and returning just the name. Now the original
text including `#` is restored when the lookup fails.

This fixes rendering of text like `#no-space-heading` in Markdown
paragraphs, where the `#` was silently dropped in the final HTML.

Also refactors `cross_reference` and `link`:

- `cross_reference` no longer mutates its `name` parameter; uses a
  separate `display` variable for `#`-stripped text
- `link` returns `nil` for unresolved references instead of returning
  the bare text, letting the caller decide what to display
- Label handling is hoisted out of the `case` branches so it's shared
  between resolved refs and bare label references (`@foo`)
- Unresolved refs with caller-provided text (e.g. tidy links) now
  preserve the explicit text instead of falling back to the raw name
- Move new test methods before `private` helper section to follow
  file convention
@st0012 st0012 force-pushed the fix-crossref-hash-preservation branch from c24ebbd to d9383ba Compare April 10, 2026 18:13
@st0012 st0012 merged commit caad3b9 into master Apr 10, 2026
78 checks passed
@st0012 st0012 deleted the fix-crossref-hash-preservation branch April 10, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants