diff --git a/lib/rdoc/markup/formatter.rb b/lib/rdoc/markup/formatter.rb
index 9daffaabb8f497..fb382df6800de1 100644
--- a/lib/rdoc/markup/formatter.rb
+++ b/lib/rdoc/markup/formatter.rb
@@ -195,18 +195,20 @@ def in_tt?
@in_tt > 0
end
+ def tt_tag? attr_mask, reverse = false
+ each_attr_tag(attr_mask, reverse) do |tag|
+ return true if tt? tag
+ end
+ false
+ end
+
##
# Turns on tags for +item+ on +res+
def on_tags res, item
- attr_mask = item.turn_on
- return if attr_mask.zero?
-
- @attr_tags.each do |tag|
- if attr_mask & tag.bit != 0 then
- res << annotate(tag.on)
- @in_tt += 1 if tt? tag
- end
+ each_attr_tag(item.turn_on) do |tag|
+ res << annotate(tag.on)
+ @in_tt += 1 if tt? tag
end
end
@@ -214,13 +216,18 @@ def on_tags res, item
# Turns off tags for +item+ on +res+
def off_tags res, item
- attr_mask = item.turn_off
+ each_attr_tag(item.turn_off, true) do |tag|
+ @in_tt -= 1 if tt? tag
+ res << annotate(tag.off)
+ end
+ end
+
+ def each_attr_tag attr_mask, reverse = false
return if attr_mask.zero?
- @attr_tags.reverse_each do |tag|
+ @attr_tags.public_send(reverse ? :reverse_each : :each) do |tag|
if attr_mask & tag.bit != 0 then
- @in_tt -= 1 if tt? tag
- res << annotate(tag.off)
+ yield tag
end
end
end
diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb
index 172518c7f9635d..e6661b621e072e 100644
--- a/lib/rdoc/markup/to_html_crossref.rb
+++ b/lib/rdoc/markup/to_html_crossref.rb
@@ -182,4 +182,43 @@ def link name, text, code = true, rdoc_ref: false
end
end
+ def convert_flow(flow)
+ res = []
+
+ i = 0
+ while i < flow.size
+ item = flow[i]
+ i += 1
+ case item
+ when RDoc::Markup::AttrChanger then
+ # Make "+Class#method+" a cross reference
+ if tt_tag?(item.turn_on) and
+ String === (str = flow[i]) and
+ RDoc::Markup::AttrChanger === flow[i+1] and
+ tt_tag?(flow[i+1].turn_off, true) and
+ (@options.hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP).match?(str) and
+ (text = cross_reference str) != str
+ then
+ text = yield text, res if defined?(yield)
+ res << text
+ i += 2
+ next
+ end
+ off_tags res, item
+ on_tags res, item
+ when String then
+ text = convert_string(item)
+ text = yield text, res if defined?(yield)
+ res << text
+ when RDoc::Markup::RegexpHandling then
+ text = convert_regexp_handling(item)
+ text = yield text, res if defined?(yield)
+ res << text
+ else
+ raise "Unknown flow element: #{item.inspect}"
+ end
+ end
+
+ res.join('')
+ end
end
diff --git a/test/rdoc/test_rdoc_markup_to_html_crossref.rb b/test/rdoc/test_rdoc_markup_to_html_crossref.rb
index d5817560e29479..fb0aca29096c55 100644
--- a/test/rdoc/test_rdoc_markup_to_html_crossref.rb
+++ b/test/rdoc/test_rdoc_markup_to_html_crossref.rb
@@ -16,6 +16,18 @@ def test_convert_CROSSREF
result = @to.convert 'C1'
assert_equal para("C1
"), result
+
+ result = @to.convert '+C1+'
+ assert_equal para("C1
"), result
+
+ result = @to.convert 'FOO'
+ assert_equal para("FOO"), result
+
+ result = @to.convert '+FOO+'
+ assert_equal para("FOO
"), result
+
+ result = @to.convert '# :stopdoc::'
+ assert_equal para("# :stopdoc:
:"), result
end
def test_convert_CROSSREF_method