ruby-changes:61358
From: aycabta <ko1@a...>
Date: Sun, 24 May 2020 23:52:58 +0900 (JST)
Subject: [ruby-changes:61358] f52a4690f8 (master): [ruby/rdoc] Process crossref before tidylink
https://git.ruby-lang.org/ruby.git/commit/?id=f52a4690f8 From f52a4690f8fbd495e8517178a0bf95c69ccea47c Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Tue, 14 Apr 2020 19:33:45 +0900 Subject: [ruby/rdoc] Process crossref before tidylink The crossref must be linked before tidylink because Klass.method[:sym] will be processed as a tidylink first and will be broken. https://github.com/ruby/rdoc/commit/0f47baf6d2 diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index 9ae0fff..3b1b0e9 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -52,12 +52,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markup/to_html.rb#L52 @th = nil @hard_break = "<br>\n" - # external links - @markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/, - :HYPERLINK) - - add_regexp_handling_RDOCLINK - add_regexp_handling_TIDYLINK + init_regexp_handlings init_tags end @@ -66,6 +61,24 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markup/to_html.rb#L61 # # These methods are used by regexp handling markup added by RDoc::Markup#add_regexp_handling. + ## + # Adds regexp handlings. + + def init_regexp_handlings + # external links + @markup.add_regexp_handling(/(?:link:|https?:|mailto:|ftp:|irc:|www\.)\S+\w/, + :HYPERLINK) + init_link_notation_regexp_handlings + end + + ## + # Adds regexp handlings about link notations. + + def init_link_notation_regexp_handlings + add_regexp_handling_RDOCLINK + add_regexp_handling_TIDYLINK + end + def handle_RDOCLINK url # :nodoc: case url when /^rdoc-ref:/ diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb index 4a3f028..77e3a94 100644 --- a/lib/rdoc/markup/to_html_crossref.rb +++ b/lib/rdoc/markup/to_html_crossref.rb @@ -39,10 +39,18 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markup/to_html_crossref.rb#L39 @hyperlink_all = @options.hyperlink_all @show_hash = @options.show_hash - crossref_re = @hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP + @cross_reference = RDoc::CrossReference.new @context + end + + def init_link_notation_regexp_handlings + add_regexp_handling_RDOCLINK + + # The crossref must be linked before tidylink because Klass.method[:sym] + # will be processed as a tidylink first and will be broken. + crossref_re = @options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP @markup.add_regexp_handling crossref_re, :CROSSREF - @cross_reference = RDoc::CrossReference.new @context + add_regexp_handling_TIDYLINK end ## diff --git a/test/rdoc/test_rdoc_markup_to_html_crossref.rb b/test/rdoc/test_rdoc_markup_to_html_crossref.rb index 70306c6..f6fabfb 100644 --- a/test/rdoc/test_rdoc_markup_to_html_crossref.rb +++ b/test/rdoc/test_rdoc_markup_to_html_crossref.rb @@ -151,6 +151,13 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_markup_to_html_crossref.rb#L151 REGEXP_HANDLING('#m') end + def test_handle_regexp_CROSSREF_with_arg_looks_like_TIDYLINK + result = @to.convert 'C1.m[:sym]' + + assert_equal para("<a href=\"C1.html#method-c-m\"><code>C1.m[:sym]</code></a>"), result, + 'C1.m[:sym]' + end + def test_handle_regexp_HYPERLINK_rdoc readme = @store.add_file 'README.txt' readme.parser = RDoc::Parser::Simple -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/