[前][次][番号順一覧][スレッド一覧]

ruby-changes:66692

From: Nobuyoshi <ko1@a...>
Date: Mon, 5 Jul 2021 18:35:34 +0900 (JST)
Subject: [ruby-changes:66692] 7c8aa0a5d2 (master): [ruby/rdoc] Allow a label in a link to another document text

https://git.ruby-lang.org/ruby.git/commit/?id=7c8aa0a5d2

From 7c8aa0a5d2bc3f079077d113b350a58d7b7c2b0d Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 10 Apr 2021 01:58:09 +0900
Subject: [ruby/rdoc] Allow a label in a link to another document text

https://github.com/ruby/rdoc/commit/85bb2d33bb
---
 lib/rdoc/markup/to_html.rb            |  4 ++--
 test/rdoc/test_rdoc_markup_to_html.rb | 12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb
index 8ae4dd4..6a8ca8a 100644
--- a/lib/rdoc/markup/to_html.rb
+++ b/lib/rdoc/markup/to_html.rb
@@ -357,8 +357,8 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markup/to_html.rb#L357
        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" }
+      if scheme != 'link' and %r%\A([./]*+)(.*?\.)(rb|rdoc|md)(?=\z|#)%i =~ url
+        url = "#$1#{$2.tr('.', '_')}#$3.html#{$'}"
       end
 
       text = text.sub %r%^#{scheme}:/*%i, ''
diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb
index 29da968..f7887f0 100644
--- a/test/rdoc/test_rdoc_markup_to_html.rb
+++ b/test/rdoc/test_rdoc_markup_to_html.rb
@@ -743,6 +743,10 @@ EXPECTED https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_markup_to_html.rb#L743
                  @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')
+    assert_equal '<a href="doc/example_rdoc.html#label-one">example</a>',
+                 @to.gen_url('doc/example.rdoc#label-one', 'example')
+    assert_equal '<a href="../ex_doc/example_rdoc.html#label-two">example</a>',
+                 @to.gen_url('../ex.doc/example.rdoc#label-two', 'example')
   end
 
   def test_gen_url_md_file
@@ -750,6 +754,10 @@ EXPECTED https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_markup_to_html.rb#L754
                  @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')
+    assert_equal '<a href="doc/example_md.html#label-one">example</a>',
+                 @to.gen_url('doc/example.md#label-one', 'example')
+    assert_equal '<a href="../ex_doc/example_md.html#label-two">example</a>',
+                 @to.gen_url('../ex.doc/example.md#label-two', 'example')
   end
 
   def test_gen_url_rb_file
@@ -757,6 +765,10 @@ EXPECTED https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_markup_to_html.rb#L765
                  @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')
+    assert_equal '<a href="doc/example_rb.html#label-one">example</a>',
+                 @to.gen_url('doc/example.rb#label-one', 'example')
+    assert_equal '<a href="../ex_doc/example_rb.html#label-two">example</a>',
+                 @to.gen_url('../ex.doc/example.rb#label-two', 'example')
   end
 
   def test_handle_regexp_HYPERLINK_link
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]