diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb
index 6020263799..2fbddeb83b 100644
--- a/lib/rdoc/markup/to_html_crossref.rb
+++ b/lib/rdoc/markup/to_html_crossref.rb
@@ -49,16 +49,19 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
# Creates a link to the reference +name+ if the name exists. If +text+ is
# given it is used as the link text, otherwise +name+ is used.
- def cross_reference name, text = nil
+ def cross_reference name, text = nil, code = true
lookup = name
name = name[1..-1] unless @show_hash if name[0, 1] == '#'
- name = "#{CGI.unescape $'} at #{$1}" if name =~ /(.*[^#:])@/
+ if name =~ /(.*[^#:])@/
+ text ||= "#{CGI.unescape $'} at #{$1}
"
+ code = false
+ else
+ text ||= name
+ end
- text = name unless text
-
- link lookup, text
+ link lookup, text, code
end
##
@@ -119,13 +122,14 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
def gen_url url, text
return super unless url =~ /\Ardoc-ref:/
- cross_reference $', text
+ name = $'
+ cross_reference name, text, name == text
end
##
# Creates an HTML link to +name+ with the given +text+.
- def link name, text
+ def link name, text, code = true
if name =~ /(.*[^#:])@/ then
name = $1
label = $'
@@ -139,6 +143,10 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
else
path = ref.as_href @from_path
+ if code and RDoc::CodeObject === ref and !(RDoc::TopLevel === ref)
+ text = "#{text}
"
+ end
+
if path =~ /#/ then
path << "-label-#{label}"
elsif ref.sections and
diff --git a/test/rdoc/test_rdoc_markup_to_html_crossref.rb b/test/rdoc/test_rdoc_markup_to_html_crossref.rb
index 19cc6a8ec1..598bae3d3f 100644
--- a/test/rdoc/test_rdoc_markup_to_html_crossref.rb
+++ b/test/rdoc/test_rdoc_markup_to_html_crossref.rb
@@ -14,26 +14,26 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
def test_convert_CROSSREF
result = @to.convert 'C1'
- assert_equal para("C1"), result
+ assert_equal para("C1
"), result
end
def test_convert_CROSSREF_label
result = @to.convert 'C1@foo'
- assert_equal para("foo at C1"), result
+ assert_equal para("foo at C1
"), result
result = @to.convert 'C1#m@foo'
- assert_equal para("foo at C1#m"),
+ assert_equal para("foo at C1#m
"),
result
end
def test_convert_CROSSREF_label_period
result = @to.convert 'C1@foo.'
- assert_equal para("foo at C1."), result
+ assert_equal para("foo at C1
."), result
end
def test_convert_CROSSREF_label_space
result = @to.convert 'C1@foo+bar'
- assert_equal para("foo bar at C1"),
+ assert_equal para("foo bar at C1
"),
result
end
@@ -41,31 +41,31 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
@c1.add_section 'Section'
result = @to.convert 'C1@Section'
- assert_equal para("Section at C1"), result
+ assert_equal para("Section at C1
"), result
end
def test_convert_CROSSREF_constant
result = @to.convert 'C1::CONST'
- assert_equal para("C1::CONST"), result
+ assert_equal para("C1::CONST
"), result
end
def test_convert_RDOCLINK_rdoc_ref
result = @to.convert 'rdoc-ref:C1'
- assert_equal para("C1"), result
+ assert_equal para("C1
"), result
end
def test_convert_RDOCLINK_rdoc_ref_method
result = @to.convert 'rdoc-ref:C1#m'
- assert_equal para("C1#m"), result
+ assert_equal para("C1#m
"), result
end
def test_convert_RDOCLINK_rdoc_ref_method_label
result = @to.convert 'rdoc-ref:C1#m@foo'
- assert_equal para("foo at C1#m"),
+ assert_equal para("foo at C1#m
"),
result, 'rdoc-ref:C1#m@foo'
end
@@ -75,13 +75,13 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
result = @to.convert 'rdoc-ref:C1#%'
- assert_equal para("C1#%"), result
+ assert_equal para("C1#%
"), result
m.singleton = true
result = @to.convert 'rdoc-ref:C1::%'
- assert_equal para("C1::%"), result
+ assert_equal para("C1::%
"), result
end
def test_convert_RDOCLINK_rdoc_ref_method_percent_label
@@ -90,21 +90,21 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
result = @to.convert 'rdoc-ref:C1#%@f'
- assert_equal para("f at C1#%"),
+ assert_equal para("f at C1#%
"),
result
m.singleton = true
result = @to.convert 'rdoc-ref:C1::%@f'
- assert_equal para("f at C1::%"),
+ assert_equal para("f at C1::%
"),
result
end
def test_convert_RDOCLINK_rdoc_ref_label
result = @to.convert 'rdoc-ref:C1@foo'
- assert_equal para("foo at C1"), result,
+ assert_equal para("foo at C1
"), result,
'rdoc-ref:C1@foo'
end
@@ -117,18 +117,18 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
end
def test_handle_regexp_CROSSREF
- assert_equal "C2::C3", REGEXP_HANDLING('C2::C3')
+ assert_equal "C2::C3
", REGEXP_HANDLING('C2::C3')
end
def test_handle_regexp_CROSSREF_label
- assert_equal "foo at C1#m",
+ assert_equal "foo at C1#m
",
REGEXP_HANDLING('C1#m@foo')
end
def test_handle_regexp_CROSSREF_show_hash_false
@to.show_hash = false
- assert_equal "m",
+ assert_equal "m
",
REGEXP_HANDLING('#m')
end
@@ -140,11 +140,11 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
link = @to.handle_regexp_HYPERLINK hyper 'C2::C3'
- assert_equal 'C2::C3', link
+ assert_equal 'C2::C3
', link
link = @to.handle_regexp_HYPERLINK hyper 'C4'
- assert_equal 'C4', link
+ assert_equal 'C4
', link
link = @to.handle_regexp_HYPERLINK hyper 'README.txt'
@@ -200,16 +200,16 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
def test_link
assert_equal 'n', @to.link('n', 'n')
- assert_equal 'm', @to.link('m', 'm')
+ assert_equal 'm
', @to.link('m', 'm')
end
def test_link_for_method_traverse
@to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c9
- assert_equal 'C9::B#foo', @to.link('C9::B#foo', 'C9::B#foo')
+ assert_equal 'C9::B#foo
', @to.link('C9::B#foo', 'C9::B#foo')
end
def test_link_class_method_full
- assert_equal 'Parent::m',
+ assert_equal 'Parent::m
',
@to.link('Parent::m', 'Parent::m')
end