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

ruby-changes:65742

From: aycabta <ko1@a...>
Date: Sat, 3 Apr 2021 01:24:05 +0900 (JST)
Subject: [ruby-changes:65742] e84d275fe6 (master): [ruby/rdoc] Treat other tags as word boundaries

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

From e84d275fe6d0c14ba58ce73b13323879c060b7ae Mon Sep 17 00:00:00 2001
From: aycabta <aycabta@g...>
Date: Tue, 16 Mar 2021 18:59:22 +0900
Subject: [ruby/rdoc] Treat other tags as word boundaries

https://github.com/ruby/rdoc/commit/8222f85a17
---
 lib/rdoc/markup/attribute_manager.rb  | 17 +++++++++++++----
 test/rdoc/test_rdoc_markup_to_html.rb |  5 +++++
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/lib/rdoc/markup/attribute_manager.rb b/lib/rdoc/markup/attribute_manager.rb
index 64ef7fd..2de8a7c 100644
--- a/lib/rdoc/markup/attribute_manager.rb
+++ b/lib/rdoc/markup/attribute_manager.rb
@@ -140,6 +140,11 @@ class RDoc::Markup::AttributeManager https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markup/attribute_manager.rb#L140
   # character
 
   def convert_attrs(str, attrs, exclusive = false)
+    convert_attrs_matching_word_pairs(str, attrs, exclusive)
+    convert_attrs_word_pair_map(str, attrs, exclusive)
+  end
+
+  def convert_attrs_matching_word_pairs(str, attrs, exclusive)
     # first do matching ones
     tags = @matching_word_pairs.select { |start, bitmap|
       if exclusive && exclusive?(bitmap)
@@ -149,21 +154,25 @@ class RDoc::Markup::AttributeManager https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markup/attribute_manager.rb#L154
       else
         false
       end
-    }.keys.join("")
+    }.keys
+    return if tags.empty?
+    all_tags = @matching_word_pairs.keys
 
-    re = /(^|\W)([#{tags}])([#\\]?[\w:.\/\[\]-]+?\S?)\2(\W|$)/
+    re = /(^|\W|[#{all_tags.join("")}])([#{tags.join("")}])(\2*[#\\]?[\w:.\/\[\]-]+?\S?)\2(?!\2)([#{all_tags.join("")}]|\W|$)/
 
     1 while str.gsub!(re) { |orig|
       attr = @matching_word_pairs[$2]
-      updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
-      if updated
+      attr_updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
+      if attr_updated
         $1 + NULL * $2.length + $3 + NULL * $2.length + $4
       else
         $1 + NON_PRINTING_START + $2 + NON_PRINTING_END + $3 + NON_PRINTING_START + $2 + NON_PRINTING_END + $4
       end
     }
     str.delete!(NON_PRINTING_START + NON_PRINTING_END)
+  end
 
+  def convert_attrs_word_pair_map(str, attrs, exclusive)
     # then non-matching
     unless @word_pair_map.empty? then
       @word_pair_map.each do |regexp, attr|
diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb
index 6ec5298..0b25f46 100644
--- a/test/rdoc/test_rdoc_markup_to_html.rb
+++ b/test/rdoc/test_rdoc_markup_to_html.rb
@@ -710,6 +710,11 @@ EXPECTED https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_markup_to_html.rb#L710
     assert_equal "\n<p><a href=\":symbol\">aaa</a></p>\n", @to.convert('aaa[:symbol]')
   end
 
+  def test_convert_underscore_adjacent_to_code
+    assert_equal "\n<p><code>aaa</code>_</p>\n", @to.convert(%q{+aaa+_})
+    assert_equal "\n<p>`<code>i386-mswin32_</code><em>MSRTVERSION</em>&#39;</p>\n", @to.convert(%q{`+i386-mswin32_+_MSRTVERSION_'})
+  end
+
   def test_gen_url
     assert_equal '<a href="example">example</a>',
                  @to.gen_url('link:example', 'example')
-- 
cgit v1.1


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

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