[ruby/rdoc] Print warnings for rdoc-ref links that can't be resolved
(https://github.com/ruby/rdoc/pull/1241) https://github.com/ruby/rdoc/commit/4a5206ae56
This commit is contained in:
parent
80b8feb929
commit
a6fd6cb72f
@ -58,7 +58,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
||||
# 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.
|
||||
|
||||
def cross_reference name, text = nil, code = true
|
||||
def cross_reference name, text = nil, code = true, rdoc_ref: false
|
||||
lookup = name
|
||||
|
||||
name = name[1..-1] unless @show_hash if name[0, 1] == '#'
|
||||
@ -70,7 +70,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
||||
text ||= name
|
||||
end
|
||||
|
||||
link lookup, text, code
|
||||
link lookup, text, code, rdoc_ref: rdoc_ref
|
||||
end
|
||||
|
||||
##
|
||||
@ -92,7 +92,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
||||
return name if name =~ /\A[a-z]*\z/
|
||||
end
|
||||
|
||||
cross_reference name
|
||||
cross_reference name, rdoc_ref: false
|
||||
end
|
||||
|
||||
##
|
||||
@ -100,9 +100,14 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
||||
# handle other schemes.
|
||||
|
||||
def handle_regexp_HYPERLINK target
|
||||
return cross_reference $' if target.text =~ /\Ardoc-ref:/
|
||||
url = target.text
|
||||
|
||||
super
|
||||
case url
|
||||
when /\Ardoc-ref:/
|
||||
cross_reference $', rdoc_ref: true
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
@ -117,8 +122,8 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
||||
url = target.text
|
||||
|
||||
case url
|
||||
when /\Ardoc-ref:/ then
|
||||
cross_reference $'
|
||||
when /\Ardoc-ref:/
|
||||
cross_reference $', rdoc_ref: true
|
||||
else
|
||||
super
|
||||
end
|
||||
@ -129,16 +134,18 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
||||
# RDoc::Markup::ToHtml to handle other schemes.
|
||||
|
||||
def gen_url url, text
|
||||
return super unless url =~ /\Ardoc-ref:/
|
||||
|
||||
name = $'
|
||||
cross_reference name, text, name == text
|
||||
if url =~ /\Ardoc-ref:/
|
||||
name = $'
|
||||
cross_reference name, text, name == text, rdoc_ref: true
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Creates an HTML link to +name+ with the given +text+.
|
||||
|
||||
def link name, text, code = true
|
||||
def link name, text, code = true, rdoc_ref: false
|
||||
if !(name.end_with?('+@', '-@')) and name =~ /(.*[^#:])?@/
|
||||
name = $1
|
||||
label = $'
|
||||
@ -148,6 +155,9 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
||||
|
||||
case ref
|
||||
when String then
|
||||
if rdoc_ref && @options.warn_missing_rdoc_ref
|
||||
puts "#{@from_path}: `rdoc-ref:#{name}` can't be resolved for `#{text}`"
|
||||
end
|
||||
ref
|
||||
else
|
||||
path = ref ? ref.as_href(@from_path) : +""
|
||||
|
@ -325,6 +325,12 @@ class RDoc::Options
|
||||
|
||||
attr_accessor :verbosity
|
||||
|
||||
##
|
||||
# Warn if rdoc-ref links can't be resolved
|
||||
# Default is +false+
|
||||
|
||||
attr_accessor :warn_missing_rdoc_ref
|
||||
|
||||
##
|
||||
# URL of web cvs frontend
|
||||
|
||||
@ -393,6 +399,7 @@ class RDoc::Options
|
||||
@update_output_dir = true
|
||||
@verbosity = 1
|
||||
@visibility = :protected
|
||||
@warn_missing_rdoc_ref = false
|
||||
@webcvs = nil
|
||||
@write_options = false
|
||||
@encoding = Encoding::UTF_8
|
||||
@ -457,6 +464,8 @@ class RDoc::Options
|
||||
@visibility = map['visibility'] if map.has_key?('visibility')
|
||||
@webcvs = map['webcvs'] if map.has_key?('webcvs')
|
||||
|
||||
@warn_missing_rdoc_ref = map['warn_missing_rdoc_ref'] if map.has_key?('warn_missing_rdoc_ref')
|
||||
|
||||
if map.has_key?('rdoc_include')
|
||||
@rdoc_include = sanitize_path map['rdoc_include']
|
||||
end
|
||||
@ -1104,6 +1113,13 @@ Usage: #{opt.program_name} [options] [names...]
|
||||
|
||||
opt.separator nil
|
||||
|
||||
opt.on("--warn-missing-rdoc-ref",
|
||||
"Warn if rdoc-ref links can't be resolved") do |value|
|
||||
@warn_missing_rdoc_ref = value
|
||||
end
|
||||
|
||||
opt.separator nil
|
||||
|
||||
opt.on("--[no-]ignore-invalid",
|
||||
"Ignore invalid options and continue",
|
||||
"(default true).") do |value|
|
||||
|
@ -1,12 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
require_relative 'xref_test_case'
|
||||
|
||||
class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
||||
class RDocMarkupToHtmlCrossrefTest < XrefTestCase
|
||||
|
||||
def setup
|
||||
super
|
||||
|
||||
@options.hyperlink_all = true
|
||||
@options.warn_missing_rdoc_ref = true
|
||||
|
||||
@to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1
|
||||
end
|
||||
@ -67,6 +68,16 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
||||
assert_equal para("<a href=\"C1.html\"><code>C1</code></a>"), result
|
||||
end
|
||||
|
||||
def test_convert_RDOCLINK_rdoc_ref_not_found
|
||||
result = nil
|
||||
stdout, _ = capture_output do
|
||||
result = @to.convert 'rdoc-ref:FOO'
|
||||
end
|
||||
|
||||
assert_equal para("FOO"), result
|
||||
assert_include stdout, "index.html: `rdoc-ref:FOO` can't be resolved for `FOO`"
|
||||
end
|
||||
|
||||
def test_convert_RDOCLINK_rdoc_ref_method
|
||||
result = @to.convert 'rdoc-ref:C1#m'
|
||||
|
||||
@ -153,6 +164,14 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
|
||||
@to.gen_url('http://example', 'HTTP example')
|
||||
end
|
||||
|
||||
def test_gen_url_rdoc_ref_not_found
|
||||
stdout, _ = capture_output do
|
||||
@to.gen_url 'rdoc-ref:FOO', 'FOO'
|
||||
end
|
||||
|
||||
assert_include stdout, "index.html: `rdoc-ref:FOO` can't be resolved for `FOO`"
|
||||
end
|
||||
|
||||
def test_handle_regexp_CROSSREF
|
||||
assert_equal "<a href=\"C2/C3.html\"><code>C2::C3</code></a>", REGEXP_HANDLING('C2::C3')
|
||||
end
|
||||
|
@ -63,27 +63,28 @@ class TestRDocOptions < RDoc::TestCase
|
||||
encoding = 'UTF-8'
|
||||
|
||||
expected = {
|
||||
'charset' => 'UTF-8',
|
||||
'encoding' => encoding,
|
||||
'embed_mixins' => false,
|
||||
'exclude' => %w[~\z \.orig\z \.rej\z \.bak\z \.gemspec\z],
|
||||
'hyperlink_all' => false,
|
||||
'line_numbers' => false,
|
||||
'locale_dir' => 'locale',
|
||||
'locale_name' => nil,
|
||||
'main_page' => nil,
|
||||
'markup' => 'rdoc',
|
||||
'output_decoration' => true,
|
||||
'page_dir' => nil,
|
||||
'rdoc_include' => [],
|
||||
'show_hash' => false,
|
||||
'static_path' => [],
|
||||
'tab_width' => 8,
|
||||
'template_stylesheets' => [],
|
||||
'title' => nil,
|
||||
'visibility' => :protected,
|
||||
'webcvs' => nil,
|
||||
'skip_tests' => true,
|
||||
'charset' => 'UTF-8',
|
||||
'encoding' => encoding,
|
||||
'embed_mixins' => false,
|
||||
'exclude' => %w[~\z \.orig\z \.rej\z \.bak\z \.gemspec\z],
|
||||
'hyperlink_all' => false,
|
||||
'line_numbers' => false,
|
||||
'locale_dir' => 'locale',
|
||||
'locale_name' => nil,
|
||||
'main_page' => nil,
|
||||
'markup' => 'rdoc',
|
||||
'output_decoration' => true,
|
||||
'page_dir' => nil,
|
||||
'rdoc_include' => [],
|
||||
'show_hash' => false,
|
||||
'static_path' => [],
|
||||
'tab_width' => 8,
|
||||
'template_stylesheets' => [],
|
||||
'title' => nil,
|
||||
'visibility' => :protected,
|
||||
'warn_missing_rdoc_ref' => false,
|
||||
'webcvs' => nil,
|
||||
'skip_tests' => true,
|
||||
}
|
||||
|
||||
assert_equal expected, coder
|
||||
|
Loading…
x
Reference in New Issue
Block a user