mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/rdoc] Treat other tags as word boundaries
https://github.com/ruby/rdoc/commit/8222f85a17
This commit is contained in:
parent
54aa11efa8
commit
e84d275fe6
2 changed files with 18 additions and 4 deletions
|
@ -140,6 +140,11 @@ class RDoc::Markup::AttributeManager
|
||||||
# character
|
# character
|
||||||
|
|
||||||
def convert_attrs(str, attrs, exclusive = false)
|
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
|
# first do matching ones
|
||||||
tags = @matching_word_pairs.select { |start, bitmap|
|
tags = @matching_word_pairs.select { |start, bitmap|
|
||||||
if exclusive && exclusive?(bitmap)
|
if exclusive && exclusive?(bitmap)
|
||||||
|
@ -149,21 +154,25 @@ class RDoc::Markup::AttributeManager
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
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|
|
1 while str.gsub!(re) { |orig|
|
||||||
attr = @matching_word_pairs[$2]
|
attr = @matching_word_pairs[$2]
|
||||||
updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
|
attr_updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
|
||||||
if updated
|
if attr_updated
|
||||||
$1 + NULL * $2.length + $3 + NULL * $2.length + $4
|
$1 + NULL * $2.length + $3 + NULL * $2.length + $4
|
||||||
else
|
else
|
||||||
$1 + NON_PRINTING_START + $2 + NON_PRINTING_END + $3 + NON_PRINTING_START + $2 + NON_PRINTING_END + $4
|
$1 + NON_PRINTING_START + $2 + NON_PRINTING_END + $3 + NON_PRINTING_START + $2 + NON_PRINTING_END + $4
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
str.delete!(NON_PRINTING_START + NON_PRINTING_END)
|
str.delete!(NON_PRINTING_START + NON_PRINTING_END)
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert_attrs_word_pair_map(str, attrs, exclusive)
|
||||||
# then non-matching
|
# then non-matching
|
||||||
unless @word_pair_map.empty? then
|
unless @word_pair_map.empty? then
|
||||||
@word_pair_map.each do |regexp, attr|
|
@word_pair_map.each do |regexp, attr|
|
||||||
|
|
|
@ -710,6 +710,11 @@ EXPECTED
|
||||||
assert_equal "\n<p><a href=\":symbol\">aaa</a></p>\n", @to.convert('aaa[:symbol]')
|
assert_equal "\n<p><a href=\":symbol\">aaa</a></p>\n", @to.convert('aaa[:symbol]')
|
||||||
end
|
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>'</p>\n", @to.convert(%q{`+i386-mswin32_+_MSRTVERSION_'})
|
||||||
|
end
|
||||||
|
|
||||||
def test_gen_url
|
def test_gen_url
|
||||||
assert_equal '<a href="example">example</a>',
|
assert_equal '<a href="example">example</a>',
|
||||||
@to.gen_url('link:example', 'example')
|
@to.gen_url('link:example', 'example')
|
||||||
|
|
Loading…
Add table
Reference in a new issue