1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Treat linking to Markdown label correctly

This commit is contained in:
aycabta 2019-08-08 16:35:34 +09:00
parent 723a37d038
commit 64f9f512c5
4 changed files with 16 additions and 2 deletions

View file

@ -153,7 +153,11 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
ref.sections.any? { |section| label == section.title } then ref.sections.any? { |section| label == section.title } then
path << "##{label}" path << "##{label}"
else else
path << "##{ref.aref}-label-#{label}" if ref.respond_to?(:aref)
path << "##{ref.aref}-label-#{label}"
else
path << "#label-#{label}"
end
end if label end if label
"<a href=\"#{path}\">#{text}</a>" "<a href=\"#{path}\">#{text}</a>"

View file

@ -26,6 +26,11 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
result result
end end
def test_convert_CROSSREF_label_for_md
result = @to.convert 'EXAMPLE@foo'
assert_equal para("<a href=\"EXAMPLE_md.html#label-foo\">foo at <code>EXAMPLE</code></a>"), result
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#class-C1-label-foo\">foo at <code>C1</code></a>."), result assert_equal para("<a href=\"C1.html#class-C1-label-foo\">foo at <code>C1</code></a>."), result

View file

@ -172,7 +172,7 @@ class TestRDocStore < XrefTestCase
end end
def test_all_files def test_all_files
assert_equal %w[xref_data.rb], assert_equal %w[EXAMPLE.md xref_data.rb],
@store.all_files.map { |m| m.full_name }.sort @store.all_files.map { |m| m.full_name }.sort
end end

View file

@ -22,8 +22,13 @@ class XrefTestCase < RDoc::TestCase
parser = RDoc::Parser::Ruby.new @xref_data, @file_name, XREF_DATA, @options, parser = RDoc::Parser::Ruby.new @xref_data, @file_name, XREF_DATA, @options,
stats stats
@example_md = @store.add_file 'EXAMPLE.md'
@example_md.parser = RDoc::Parser::Markdown
@top_levels = [] @top_levels = []
@top_levels.push parser.scan @top_levels.push parser.scan
@top_levels.push @example_md
generator = Object.new generator = Object.new
def generator.class_dir() nil end def generator.class_dir() nil end