Skip to content

Commit 8222f85

Browse files
committed
Treat other tags as word boundaries
1 parent 0cd3b55 commit 8222f85

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/rdoc/markup/attribute_manager.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ def exclusive?(attr)
140140
# character
141141

142142
def convert_attrs(str, attrs, exclusive = false)
143+
convert_attrs_matching_word_pairs(str, attrs, exclusive)
144+
convert_attrs_word_pair_map(str, attrs, exclusive)
145+
end
146+
147+
def convert_attrs_matching_word_pairs(str, attrs, exclusive)
143148
# first do matching ones
144149
tags = @matching_word_pairs.select { |start, bitmap|
145150
if exclusive && exclusive?(bitmap)
@@ -149,21 +154,25 @@ def convert_attrs(str, attrs, exclusive = false)
149154
else
150155
false
151156
end
152-
}.keys.join("")
157+
}.keys
158+
return if tags.empty?
159+
all_tags = @matching_word_pairs.keys
153160

154-
re = /(^|\W)([#{tags}])([#\\]?[\w:.\/\[\]-]+?\S?)\2(\W|$)/
161+
re = /(^|\W|[#{all_tags.join("")}])([#{tags.join("")}])(\2*[#\\]?[\w:.\/\[\]-]+?\S?)\2(?!\2)([#{all_tags.join("")}]|\W|$)/
155162

156163
1 while str.gsub!(re) { |orig|
157164
attr = @matching_word_pairs[$2]
158-
updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
159-
if updated
165+
attr_updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
166+
if attr_updated
160167
$1 + NULL * $2.length + $3 + NULL * $2.length + $4
161168
else
162169
$1 + NON_PRINTING_START + $2 + NON_PRINTING_END + $3 + NON_PRINTING_START + $2 + NON_PRINTING_END + $4
163170
end
164171
}
165172
str.delete!(NON_PRINTING_START + NON_PRINTING_END)
173+
end
166174

175+
def convert_attrs_word_pair_map(str, attrs, exclusive)
167176
# then non-matching
168177
unless @word_pair_map.empty? then
169178
@word_pair_map.each do |regexp, attr|

test/rdoc/test_rdoc_markup_to_html.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,11 @@ def test_convert_with_exclude_tag
710710
assert_equal "\n<p><a href=\":symbol\">aaa</a></p>\n", @to.convert('aaa[:symbol]')
711711
end
712712

713+
def test_convert_underscore_adjacent_to_code
714+
assert_equal "\n<p><code>aaa</code>_</p>\n", @to.convert(%q{+aaa+_})
715+
assert_equal "\n<p>`<code>i386-mswin32_</code><em>MSRTVERSION</em>&#39;</p>\n", @to.convert(%q{`+i386-mswin32_+_MSRTVERSION_'})
716+
end
717+
713718
def test_gen_url
714719
assert_equal '<a href="example">example</a>',
715720
@to.gen_url('link:example', 'example')

0 commit comments

Comments
 (0)