From 64f9f512c5837207436203c0ca47523cca2ecc62 Mon Sep 17 00:00:00 2001 From: aycabta Date: Thu, 8 Aug 2019 16:35:34 +0900 Subject: [PATCH] Treat linking to Markdown label correctly --- lib/rdoc/markup/to_html_crossref.rb | 6 +++++- test/rdoc/test_rdoc_markup_to_html_crossref.rb | 5 +++++ test/rdoc/test_rdoc_store.rb | 2 +- test/rdoc/xref_test_case.rb | 5 +++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb index 4a1350a73c..9314f04fae 100644 --- a/lib/rdoc/markup/to_html_crossref.rb +++ b/lib/rdoc/markup/to_html_crossref.rb @@ -153,7 +153,11 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml 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 "#{text}" diff --git a/test/rdoc/test_rdoc_markup_to_html_crossref.rb b/test/rdoc/test_rdoc_markup_to_html_crossref.rb index 3d80980791..bac2569f87 100644 --- a/test/rdoc/test_rdoc_markup_to_html_crossref.rb +++ b/test/rdoc/test_rdoc_markup_to_html_crossref.rb @@ -26,6 +26,11 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase result end + def test_convert_CROSSREF_label_for_md + result = @to.convert 'EXAMPLE@foo' + assert_equal para("foo at EXAMPLE"), result + end + def test_convert_CROSSREF_label_period result = @to.convert 'C1@foo.' assert_equal para("foo at C1."), result diff --git a/test/rdoc/test_rdoc_store.rb b/test/rdoc/test_rdoc_store.rb index 5a884c0b5f..8332d9233e 100644 --- a/test/rdoc/test_rdoc_store.rb +++ b/test/rdoc/test_rdoc_store.rb @@ -172,7 +172,7 @@ class TestRDocStore < XrefTestCase 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 diff --git a/test/rdoc/xref_test_case.rb b/test/rdoc/xref_test_case.rb index d42cf398e7..061c5bda49 100644 --- a/test/rdoc/xref_test_case.rb +++ b/test/rdoc/xref_test_case.rb @@ -22,8 +22,13 @@ class XrefTestCase < RDoc::TestCase 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