Skip to content

Treat linking to Markdown label correctly #736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/rdoc/markup/to_html_crossref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ def link name, text, code = true
ref.sections.any? { |section| label == section.title } then
path << "##{label}"
else
path << "##{ref.aref}-label-#{label}"
if ref.respond_to?(:aref)
path << "##{ref.aref}-label-#{label}"
else
path << "#label-#{label}"
end
end if label

"<a href=\"#{path}\">#{text}</a>"
Expand Down
5 changes: 5 additions & 0 deletions test/rdoc/test_rdoc_markup_to_html_crossref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def test_convert_CROSSREF_label
result
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
result = @to.convert 'C1@foo.'
assert_equal para("<a href=\"C1.html#class-C1-label-foo\">foo at <code>C1</code></a>."), result
Expand Down
2 changes: 1 addition & 1 deletion test/rdoc/test_rdoc_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def test_all_classes_and_modules
end

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
end

Expand Down
5 changes: 5 additions & 0 deletions test/rdoc/xref_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ def setup

parser = RDoc::Parser::Ruby.new @xref_data, @file_name, XREF_DATA, @options,
stats

@example_md = @store.add_file 'EXAMPLE.md'
@example_md.parser = RDoc::Parser::Markdown

@top_levels = []
@top_levels.push parser.scan
@top_levels.push @example_md

generator = Object.new
def generator.class_dir() nil end
Expand Down