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

ruby-changes:65739

From: Nobuyoshi <ko1@a...>
Date: Sat, 3 Apr 2021 01:24:03 +0900 (JST)
Subject: [ruby-changes:65739] 64b991b0cd (master): [ruby/rdoc] Links to document texts without "rdoc-ref:" prefix

https://git.ruby-lang.org/ruby.git/commit/?id=64b991b0cd

From 64b991b0cd98ee8f23266b8cbea0fa34bdaab1ec Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 21 Mar 2021 14:36:57 +0900
Subject: [ruby/rdoc] 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.

https://github.com/ruby/rdoc/commit/f18b27b69d
---
 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 e2a00bd..8ae4dd4 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 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" }
+      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 0b25f46..29da968 100644
--- a/test/rdoc/test_rdoc_markup_to_html.rb
+++ b/test/rdoc/test_rdoc_markup_to_html.rb
@@ -738,6 +738,27 @@ EXPECTED https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_markup_to_html.rb#L738
     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'
 
-- 
cgit v1.1


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

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