Skip to content

Commit bb0ea69

Browse files
authored
Merge pull request #736 from aycabta/treat-markdoewn-label-correctly
Treat linking to Markdown label correctly
2 parents 549b7d7 + acfc509 commit bb0ea69

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

lib/rdoc/markup/to_html_crossref.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ def link name, text, code = true
153153
ref.sections.any? { |section| label == section.title } then
154154
path << "##{label}"
155155
else
156-
path << "##{ref.aref}-label-#{label}"
156+
if ref.respond_to?(:aref)
157+
path << "##{ref.aref}-label-#{label}"
158+
else
159+
path << "#label-#{label}"
160+
end
157161
end if label
158162

159163
"<a href=\"#{path}\">#{text}</a>"

test/rdoc/test_rdoc_markup_to_html_crossref.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ def test_convert_CROSSREF_label
2626
result
2727
end
2828

29+
def test_convert_CROSSREF_label_for_md
30+
result = @to.convert 'EXAMPLE@foo'
31+
assert_equal para("<a href=\"EXAMPLE_md.html#label-foo\">foo at <code>EXAMPLE</code></a>"), result
32+
end
33+
2934
def test_convert_CROSSREF_label_period
3035
result = @to.convert 'C1@foo.'
3136
assert_equal para("<a href=\"C1.html#class-C1-label-foo\">foo at <code>C1</code></a>."), result

test/rdoc/test_rdoc_store.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_all_classes_and_modules
172172
end
173173

174174
def test_all_files
175-
assert_equal %w[xref_data.rb],
175+
assert_equal %w[EXAMPLE.md xref_data.rb],
176176
@store.all_files.map { |m| m.full_name }.sort
177177
end
178178

test/rdoc/xref_test_case.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ def setup
2222

2323
parser = RDoc::Parser::Ruby.new @xref_data, @file_name, XREF_DATA, @options,
2424
stats
25+
26+
@example_md = @store.add_file 'EXAMPLE.md'
27+
@example_md.parser = RDoc::Parser::Markdown
28+
2529
@top_levels = []
2630
@top_levels.push parser.scan
31+
@top_levels.push @example_md
2732

2833
generator = Object.new
2934
def generator.class_dir() nil end

0 commit comments

Comments
 (0)