Preserve # prefix for unresolved cross-references#1676
Conversation
|
🚀 Preview deployment available at: https://bba08f0c.rdoc-6cd.pages.dev (commit: d9383ba) |
5471aac to
64f4ea1
Compare
There was a problem hiding this comment.
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_referenceto avoid mutating thenameargument and to separate display text from lookup text. - Changes
linkto returnnilwhen 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 newlinkreturn 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.
64f4ea1 to
031de0c
Compare
There was a problem hiding this comment.
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.
031de0c to
c24ebbd
Compare
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
c24ebbd to
d9383ba
Compare
Summary
When
#namedoesn'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-headingin Markdown paragraphs, where the#was silently dropped in the final HTML.Refactoring
cross_referenceno longer mutates itsnameparameter; uses a separatedisplayvariable for#-stripped textlinkreturnsnilfor unresolved references instead of returning bare text, letting the caller decide what to displaycasebranches so it's shared between resolved refs and bare label references (@foo)privatehelper section to follow file conventionFound while investigating blockquote lazy continuation in #1627 —
#text(not a valid heading) inside a blockquote was rendered without the#.