diff options
-rw-r--r-- | lib/rdoc/markup/to_html.rb | 4 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_markup_to_html.rb | 21 |
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index e2a00bd8a1..8ae4dd4720 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -357,6 +357,10 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then "<img src=\"#{url}\" />" else + if scheme != 'link' and /\.(?:rb|rdoc|md)\z/i =~ url + url = url.sub(%r%\A([./]*)(.*)\z%) { "#$1#{$2.tr('.', '_')}.html" } + end + text = text.sub %r%^#{scheme}:/*%i, '' text = text.sub %r%^[*\^](\d+)$%, '\1' diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb index 0b25f462ae..29da968abc 100644 --- a/test/rdoc/test_rdoc_markup_to_html.rb +++ b/test/rdoc/test_rdoc_markup_to_html.rb @@ -738,6 +738,27 @@ EXPECTED assert_equal '<img src="https://example.com/image.png" />', @to.gen_url('https://example.com/image.png', 'ignored') end + def test_gen_url_rdoc_file + 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>', + @to.gen_url('../ex.doc/example.rdoc', 'example') + end + + def test_gen_url_md_file + 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>', + @to.gen_url('../ex.doc/example.md', 'example') + end + + def test_gen_url_rb_file + 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>', + @to.gen_url('../ex.doc/example.rb', 'example') + end + def test_handle_regexp_HYPERLINK_link target = RDoc::Markup::RegexpHandling.new 0, 'link:README.txt' |