Skip to content

Commit f18b27b

Browse files
committed
Links to document texts without "rdoc-ref:" prefix
While links to generated HTML from RDoc file needs to be prefixed by "rdoc-ref:" currently, in case of explicit references this seems just redundant. Also GitHub RDoc support does not work with this prefix. This patch lets links to such document texts (".rb", ".rdoc" and ".md" now) refer URLs generated by `RDoc::TopLevel#http_url` without the prefix.
1 parent 7a3417e commit f18b27b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/rdoc/markup/to_html.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ def gen_url url, text
357357
url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
358358
"<img src=\"#{url}\" />"
359359
else
360+
if scheme != 'link' and /\.(?:rb|rdoc|md)\z/i =~ url
361+
url = url.sub(%r%\A([./]*)(.*)\z%) { "#$1#{$2.tr('.', '_')}.html" }
362+
end
363+
360364
text = text.sub %r%^#{scheme}:/*%i, ''
361365
text = text.sub %r%^[*\^](\d+)$%, '\1'
362366

test/rdoc/test_rdoc_markup_to_html.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,27 @@ def test_gen_url_ssl_image_url
738738
assert_equal '<img src="https://example.com/image.png" />', @to.gen_url('https://example.com/image.png', 'ignored')
739739
end
740740

741+
def test_gen_url_rdoc_file
742+
assert_equal '<a href="doc/example_rdoc.html">example</a>',
743+
@to.gen_url('doc/example.rdoc', 'example')
744+
assert_equal '<a href="../ex_doc/example_rdoc.html">example</a>',
745+
@to.gen_url('../ex.doc/example.rdoc', 'example')
746+
end
747+
748+
def test_gen_url_md_file
749+
assert_equal '<a href="doc/example_md.html">example</a>',
750+
@to.gen_url('doc/example.md', 'example')
751+
assert_equal '<a href="../ex_doc/example_md.html">example</a>',
752+
@to.gen_url('../ex.doc/example.md', 'example')
753+
end
754+
755+
def test_gen_url_rb_file
756+
assert_equal '<a href="doc/example_rb.html">example</a>',
757+
@to.gen_url('doc/example.rb', 'example')
758+
assert_equal '<a href="../ex_doc/example_rb.html">example</a>',
759+
@to.gen_url('../ex.doc/example.rb', 'example')
760+
end
761+
741762
def test_handle_regexp_HYPERLINK_link
742763
target = RDoc::Markup::RegexpHandling.new 0, 'link:README.txt'
743764

0 commit comments

Comments
 (0)