[ruby/rdoc] Fix links without paths

https://github.com/ruby/rdoc/commit/424bd5db4d
This commit is contained in:
Nobuyoshi Nakada 2021-07-01 05:39:13 +09:00
parent f88a9097a4
commit 3dacc14fd3
2 changed files with 7 additions and 1 deletions

View File

@ -357,7 +357,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
"<img src=\"#{url}\" />"
else
if scheme != 'link' and %r%\A((?!https?:).*/)([^/]+)\.(rb|rdoc|md)(?=\z|#)%i =~ url
if scheme != 'link' and %r%\A((?!https?:)(?:[^/#]*/)*+)([^/#]+)\.(rb|rdoc|md)(?=\z|#)%i =~ url
url = "#$1#{$2.tr('.', '_')}_#$3.html#$'"
end

View File

@ -739,6 +739,8 @@ EXPECTED
end
def test_gen_url_rdoc_file
assert_equal '<a href="example_rdoc.html">example</a>',
@to.gen_url('example.rdoc', 'example')
assert_equal '<a href="doc/example_rdoc.html">example</a>',
@to.gen_url('doc/example.rdoc', 'example')
assert_equal '<a href="../ex.doc/example_rdoc.html">example</a>',
@ -750,6 +752,8 @@ EXPECTED
end
def test_gen_url_md_file
assert_equal '<a href="example_md.html">example</a>',
@to.gen_url('example.md', 'example')
assert_equal '<a href="doc/example_md.html">example</a>',
@to.gen_url('doc/example.md', 'example')
assert_equal '<a href="../ex.doc/example_md.html">example</a>',
@ -761,6 +765,8 @@ EXPECTED
end
def test_gen_url_rb_file
assert_equal '<a href="example_rb.html">example</a>',
@to.gen_url('example.rb', 'example')
assert_equal '<a href="doc/example_rb.html">example</a>',
@to.gen_url('doc/example.rb', 'example')
assert_equal '<a href="../ex.doc/example_rb.html">example</a>',