Skip to content

Commit 0e9daee

Browse files
authored
Don't auto-link to non-text source files in cross-references (#1646)
## Summary - RDoc's cross-reference system auto-links filenames like `array.c` when encountered in documentation text, but non-text source files are not meant to have their own documentation pages, so these links are always broken (e.g. https://docs.ruby-lang.org/en/master/extension_rdoc.html#class-library) - Only suppress auto-linking in `ToHtmlCrossref#link`. Explicit `rdoc-ref:` links to non-text files (enabled by #1376) continue to work
1 parent 8e07d57 commit 0e9daee

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/rdoc/markup/to_html_crossref.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ def link(name, text, code = true, rdoc_ref: false)
159159

160160
ref = @cross_reference.resolve name, text if name
161161

162+
# Non-text source files (C, Ruby, etc.) don't get HTML pages generated,
163+
# so don't auto-link to them. Explicit rdoc-ref: links are still allowed.
164+
if !rdoc_ref && RDoc::TopLevel === ref && !ref.text?
165+
return text
166+
end
167+
162168
case ref
163169
when String then
164170
if rdoc_ref && @warn_missing_rdoc_ref

test/rdoc/markup/to_html_crossref_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,25 @@ def test_to_html_CROSSREF_email_hyperlink_all
387387
assert_equal 'first.last@example.com', result
388388
end
389389

390+
def test_convert_CROSSREF_c_file_not_autolinked
391+
# C files are not text files, so they don't get HTML pages generated.
392+
# Auto cross-references to them should not produce links.
393+
c_file = @store.add_file 'array.c'
394+
c_file.parser = RDoc::Parser::C
395+
396+
result = @to.convert 'array.c'
397+
assert_equal para("array.c"), result
398+
end
399+
400+
def test_convert_RDOCLINK_rdoc_ref_c_file_linked
401+
# Explicit rdoc-ref: links to non-text files should still work.
402+
c_file = @store.add_file 'array.c'
403+
c_file.parser = RDoc::Parser::C
404+
405+
result = @to.convert 'rdoc-ref:array.c'
406+
assert_equal para("<a href=\"array_c.html\">array.c</a>"), result
407+
end
408+
390409
def test_link
391410
assert_equal 'n', @to.link('n', 'n')
392411

0 commit comments

Comments
 (0)