зеркало из https://github.com/github/ruby.git
Mark up code inside link text as <code>
Merged https://github.com/ruby/rdoc/pull/660 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65427 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
c80f3f709f
Коммит
b9ca9169ba
|
@ -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
|
# 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.
|
# 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
|
lookup = name
|
||||||
|
|
||||||
name = name[1..-1] unless @show_hash if name[0, 1] == '#'
|
name = name[1..-1] unless @show_hash if name[0, 1] == '#'
|
||||||
|
|
||||||
name = "#{CGI.unescape $'} at #{$1}" if name =~ /(.*[^#:])@/
|
if name =~ /(.*[^#:])@/
|
||||||
|
text ||= "#{CGI.unescape $'} at <code>#{$1}</code>"
|
||||||
|
code = false
|
||||||
|
else
|
||||||
|
text ||= name
|
||||||
|
end
|
||||||
|
|
||||||
text = name unless text
|
link lookup, text, code
|
||||||
|
|
||||||
link lookup, text
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -119,13 +122,14 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
||||||
def gen_url url, text
|
def gen_url url, text
|
||||||
return super unless url =~ /\Ardoc-ref:/
|
return super unless url =~ /\Ardoc-ref:/
|
||||||
|
|
||||||
cross_reference $', text
|
name = $'
|
||||||
|
cross_reference name, text, name == text
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Creates an HTML link to +name+ with the given +text+.
|
# Creates an HTML link to +name+ with the given +text+.
|
||||||
|
|
||||||
def link name, text
|
def link name, text, code = true
|
||||||
if name =~ /(.*[^#:])@/ then
|
if name =~ /(.*[^#:])@/ then
|
||||||
name = $1
|
name = $1
|
||||||
label = $'
|
label = $'
|
||||||
|
@ -139,6 +143,10 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
||||||
else
|
else
|
||||||
path = ref.as_href @from_path
|
path = ref.as_href @from_path
|
||||||
|
|
||||||
|
if code and RDoc::CodeObject === ref and !(RDoc::TopLevel === ref)
|
||||||
|
text = "<code>#{text}</code>"
|
||||||
|
end
|
||||||
|
|
||||||
if path =~ /#/ then
|
if path =~ /#/ then
|
||||||
path << "-label-#{label}"
|
path << "-label-#{label}"
|
||||||
elsif ref.sections and
|
elsif ref.sections and
|
||||||
|
|
|
@ -14,26 +14,26 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
||||||
def test_convert_CROSSREF
|
def test_convert_CROSSREF
|
||||||
result = @to.convert 'C1'
|
result = @to.convert 'C1'
|
||||||
|
|
||||||
assert_equal para("<a href=\"C1.html\">C1</a>"), result
|
assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_convert_CROSSREF_label
|
def test_convert_CROSSREF_label
|
||||||
result = @to.convert 'C1@foo'
|
result = @to.convert 'C1@foo'
|
||||||
assert_equal para("<a href=\"C1.html#label-foo\">foo at C1</a>"), result
|
assert_equal para("<a href=\"C1.html#label-foo\">foo at <code>C1</code></a>"), result
|
||||||
|
|
||||||
result = @to.convert 'C1#m@foo'
|
result = @to.convert 'C1#m@foo'
|
||||||
assert_equal para("<a href=\"C1.html#method-i-m-label-foo\">foo at C1#m</a>"),
|
assert_equal para("<a href=\"C1.html#method-i-m-label-foo\">foo at <code>C1#m</code></a>"),
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_convert_CROSSREF_label_period
|
def test_convert_CROSSREF_label_period
|
||||||
result = @to.convert 'C1@foo.'
|
result = @to.convert 'C1@foo.'
|
||||||
assert_equal para("<a href=\"C1.html#label-foo\">foo at C1</a>."), result
|
assert_equal para("<a href=\"C1.html#label-foo\">foo at <code>C1</code></a>."), result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_convert_CROSSREF_label_space
|
def test_convert_CROSSREF_label_space
|
||||||
result = @to.convert 'C1@foo+bar'
|
result = @to.convert 'C1@foo+bar'
|
||||||
assert_equal para("<a href=\"C1.html#label-foo+bar\">foo bar at C1</a>"),
|
assert_equal para("<a href=\"C1.html#label-foo+bar\">foo bar at <code>C1</code></a>"),
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,31 +41,31 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
||||||
@c1.add_section 'Section'
|
@c1.add_section 'Section'
|
||||||
|
|
||||||
result = @to.convert 'C1@Section'
|
result = @to.convert 'C1@Section'
|
||||||
assert_equal para("<a href=\"C1.html#Section\">Section at C1</a>"), result
|
assert_equal para("<a href=\"C1.html#Section\">Section at <code>C1</code></a>"), result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_convert_CROSSREF_constant
|
def test_convert_CROSSREF_constant
|
||||||
result = @to.convert 'C1::CONST'
|
result = @to.convert 'C1::CONST'
|
||||||
|
|
||||||
assert_equal para("<a href=\"C1.html#CONST\">C1::CONST</a>"), result
|
assert_equal para("<a href=\"C1.html#CONST\"><code>C1::CONST</code></a>"), result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_convert_RDOCLINK_rdoc_ref
|
def test_convert_RDOCLINK_rdoc_ref
|
||||||
result = @to.convert 'rdoc-ref:C1'
|
result = @to.convert 'rdoc-ref:C1'
|
||||||
|
|
||||||
assert_equal para("<a href=\"C1.html\">C1</a>"), result
|
assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_convert_RDOCLINK_rdoc_ref_method
|
def test_convert_RDOCLINK_rdoc_ref_method
|
||||||
result = @to.convert 'rdoc-ref:C1#m'
|
result = @to.convert 'rdoc-ref:C1#m'
|
||||||
|
|
||||||
assert_equal para("<a href=\"C1.html#method-i-m\">C1#m</a>"), result
|
assert_equal para("<a href=\"C1.html#method-i-m\"><code>C1#m</code></a>"), result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_convert_RDOCLINK_rdoc_ref_method_label
|
def test_convert_RDOCLINK_rdoc_ref_method_label
|
||||||
result = @to.convert 'rdoc-ref:C1#m@foo'
|
result = @to.convert 'rdoc-ref:C1#m@foo'
|
||||||
|
|
||||||
assert_equal para("<a href=\"C1.html#method-i-m-label-foo\">foo at C1#m</a>"),
|
assert_equal para("<a href=\"C1.html#method-i-m-label-foo\">foo at <code>C1#m</code></a>"),
|
||||||
result, 'rdoc-ref:C1#m@foo'
|
result, 'rdoc-ref:C1#m@foo'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -75,13 +75,13 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
||||||
|
|
||||||
result = @to.convert 'rdoc-ref:C1#%'
|
result = @to.convert 'rdoc-ref:C1#%'
|
||||||
|
|
||||||
assert_equal para("<a href=\"C1.html#method-i-25\">C1#%</a>"), result
|
assert_equal para("<a href=\"C1.html#method-i-25\"><code>C1#%</code></a>"), result
|
||||||
|
|
||||||
m.singleton = true
|
m.singleton = true
|
||||||
|
|
||||||
result = @to.convert 'rdoc-ref:C1::%'
|
result = @to.convert 'rdoc-ref:C1::%'
|
||||||
|
|
||||||
assert_equal para("<a href=\"C1.html#method-c-25\">C1::%</a>"), result
|
assert_equal para("<a href=\"C1.html#method-c-25\"><code>C1::%</code></a>"), result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_convert_RDOCLINK_rdoc_ref_method_percent_label
|
def test_convert_RDOCLINK_rdoc_ref_method_percent_label
|
||||||
|
@ -90,21 +90,21 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
||||||
|
|
||||||
result = @to.convert 'rdoc-ref:C1#%@f'
|
result = @to.convert 'rdoc-ref:C1#%@f'
|
||||||
|
|
||||||
assert_equal para("<a href=\"C1.html#method-i-25-label-f\">f at C1#%</a>"),
|
assert_equal para("<a href=\"C1.html#method-i-25-label-f\">f at <code>C1#%</code></a>"),
|
||||||
result
|
result
|
||||||
|
|
||||||
m.singleton = true
|
m.singleton = true
|
||||||
|
|
||||||
result = @to.convert 'rdoc-ref:C1::%@f'
|
result = @to.convert 'rdoc-ref:C1::%@f'
|
||||||
|
|
||||||
assert_equal para("<a href=\"C1.html#method-c-25-label-f\">f at C1::%</a>"),
|
assert_equal para("<a href=\"C1.html#method-c-25-label-f\">f at <code>C1::%</code></a>"),
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_convert_RDOCLINK_rdoc_ref_label
|
def test_convert_RDOCLINK_rdoc_ref_label
|
||||||
result = @to.convert 'rdoc-ref:C1@foo'
|
result = @to.convert 'rdoc-ref:C1@foo'
|
||||||
|
|
||||||
assert_equal para("<a href=\"C1.html#label-foo\">foo at C1</a>"), result,
|
assert_equal para("<a href=\"C1.html#label-foo\">foo at <code>C1</code></a>"), result,
|
||||||
'rdoc-ref:C1@foo'
|
'rdoc-ref:C1@foo'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -117,18 +117,18 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_handle_regexp_CROSSREF
|
def test_handle_regexp_CROSSREF
|
||||||
assert_equal "<a href=\"C2/C3.html\">C2::C3</a>", REGEXP_HANDLING('C2::C3')
|
assert_equal "<a href=\"C2/C3.html\"><code>C2::C3</code></a>", REGEXP_HANDLING('C2::C3')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_handle_regexp_CROSSREF_label
|
def test_handle_regexp_CROSSREF_label
|
||||||
assert_equal "<a href=\"C1.html#method-i-m-label-foo\">foo at C1#m</a>",
|
assert_equal "<a href=\"C1.html#method-i-m-label-foo\">foo at <code>C1#m</code></a>",
|
||||||
REGEXP_HANDLING('C1#m@foo')
|
REGEXP_HANDLING('C1#m@foo')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_handle_regexp_CROSSREF_show_hash_false
|
def test_handle_regexp_CROSSREF_show_hash_false
|
||||||
@to.show_hash = false
|
@to.show_hash = false
|
||||||
|
|
||||||
assert_equal "<a href=\"C1.html#method-i-m\">m</a>",
|
assert_equal "<a href=\"C1.html#method-i-m\"><code>m</code></a>",
|
||||||
REGEXP_HANDLING('#m')
|
REGEXP_HANDLING('#m')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -140,11 +140,11 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
||||||
|
|
||||||
link = @to.handle_regexp_HYPERLINK hyper 'C2::C3'
|
link = @to.handle_regexp_HYPERLINK hyper 'C2::C3'
|
||||||
|
|
||||||
assert_equal '<a href="C2/C3.html">C2::C3</a>', link
|
assert_equal '<a href="C2/C3.html"><code>C2::C3</code></a>', link
|
||||||
|
|
||||||
link = @to.handle_regexp_HYPERLINK hyper 'C4'
|
link = @to.handle_regexp_HYPERLINK hyper 'C4'
|
||||||
|
|
||||||
assert_equal '<a href="C4.html">C4</a>', link
|
assert_equal '<a href="C4.html"><code>C4</code></a>', link
|
||||||
|
|
||||||
link = @to.handle_regexp_HYPERLINK hyper 'README.txt'
|
link = @to.handle_regexp_HYPERLINK hyper 'README.txt'
|
||||||
|
|
||||||
|
@ -200,16 +200,16 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
||||||
def test_link
|
def test_link
|
||||||
assert_equal 'n', @to.link('n', 'n')
|
assert_equal 'n', @to.link('n', 'n')
|
||||||
|
|
||||||
assert_equal '<a href="C1.html#method-c-m">m</a>', @to.link('m', 'm')
|
assert_equal '<a href="C1.html#method-c-m"><code>m</code></a>', @to.link('m', 'm')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_link_for_method_traverse
|
def test_link_for_method_traverse
|
||||||
@to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c9
|
@to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c9
|
||||||
assert_equal '<a href="C9/A.html#method-i-foo">C9::B#foo</a>', @to.link('C9::B#foo', 'C9::B#foo')
|
assert_equal '<a href="C9/A.html#method-i-foo"><code>C9::B#foo</code></a>', @to.link('C9::B#foo', 'C9::B#foo')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_link_class_method_full
|
def test_link_class_method_full
|
||||||
assert_equal '<a href="Parent.html#method-c-m">Parent::m</a>',
|
assert_equal '<a href="Parent.html#method-c-m"><code>Parent::m</code></a>',
|
||||||
@to.link('Parent::m', 'Parent::m')
|
@to.link('Parent::m', 'Parent::m')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче