From 7a3417ea4ce1bf3f1f87754ae3d81ff938a5a338 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 21 Mar 2021 14:34:46 +0900 Subject: [PATCH 1/2] Clarify that dots in URL are replaced The dots in all path components from the document root are replaced with underscores, not only in the basename. --- test/rdoc/test_rdoc_top_level.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/rdoc/test_rdoc_top_level.rb b/test/rdoc/test_rdoc_top_level.rb index e396791ab8..a954fde981 100644 --- a/test/rdoc/test_rdoc_top_level.rb +++ b/test/rdoc/test_rdoc_top_level.rb @@ -157,6 +157,9 @@ def test_hash def test_http_url assert_equal 'prefix/path/top_level_rb.html', @top_level.http_url('prefix') + + other_level = @store.add_file 'path.other/level.rb' + assert_equal 'prefix/path_other/level_rb.html', other_level.http_url('prefix') end def test_last_modified From f18b27b69dcc16ce4672e1cabf916396a1bcf792 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 21 Mar 2021 14:36:57 +0900 Subject: [PATCH 2/2] 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. --- lib/rdoc/markup/to_html.rb | 4 ++++ test/rdoc/test_rdoc_markup_to_html.rb | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) 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 @@ def gen_url url, text url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then "" 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 @@ def test_gen_url_ssl_image_url assert_equal '', @to.gen_url('https://example.com/image.png', 'ignored') end + def test_gen_url_rdoc_file + assert_equal 'example', + @to.gen_url('doc/example.rdoc', 'example') + assert_equal 'example', + @to.gen_url('../ex.doc/example.rdoc', 'example') + end + + def test_gen_url_md_file + assert_equal 'example', + @to.gen_url('doc/example.md', 'example') + assert_equal 'example', + @to.gen_url('../ex.doc/example.md', 'example') + end + + def test_gen_url_rb_file + assert_equal 'example', + @to.gen_url('doc/example.rb', 'example') + assert_equal 'example', + @to.gen_url('../ex.doc/example.rb', 'example') + end + def test_handle_regexp_HYPERLINK_link target = RDoc::Markup::RegexpHandling.new 0, 'link:README.txt'