diff --git a/lib/rdoc/code_object.rb b/lib/rdoc/code_object.rb index 388863b06c..4f5a998fc6 100644 --- a/lib/rdoc/code_object.rb +++ b/lib/rdoc/code_object.rb @@ -277,7 +277,8 @@ def ignored? # The options instance from the store this CodeObject is attached to, or a # default options instance if the CodeObject is not attached. # - # This is used by Text#snippet + # Used by: store= (visibility check), ClassModule#path, TopLevel#path, + # ClassModule#embed_mixins def options @store&.options || RDoc::Options.new diff --git a/lib/rdoc/generator/markup.rb b/lib/rdoc/generator/markup.rb index 1c39687040..dc4556c019 100644 --- a/lib/rdoc/generator/markup.rb +++ b/lib/rdoc/generator/markup.rb @@ -37,7 +37,15 @@ def formatter options = @store.options this = RDoc::Context === self ? self : @parent - @formatter = RDoc::Markup::ToHtmlCrossref.new options, this.path, this + @formatter = RDoc::Markup::ToHtmlCrossref.new( + this.path, this, + pipe: options.pipe, + output_decoration: options.output_decoration, + hyperlink_all: options.hyperlink_all, + show_hash: options.show_hash, + autolink_excluded_words: options.autolink_excluded_words || [], + warn_missing_rdoc_ref: options.warn_missing_rdoc_ref + ) @formatter.code_object = self @formatter end diff --git a/lib/rdoc/markup/formatter.rb b/lib/rdoc/markup/formatter.rb index e858aa3e74..433237393d 100644 --- a/lib/rdoc/markup/formatter.rb +++ b/lib/rdoc/markup/formatter.rb @@ -48,10 +48,8 @@ def self.gen_relative_url(path, target) ## # Creates a new Formatter - def initialize(options, markup = nil) - @options = options - - @markup = markup || RDoc::Markup.new + def initialize + @markup = RDoc::Markup.new @from_path = '.' end diff --git a/lib/rdoc/markup/heading.rb b/lib/rdoc/markup/heading.rb index 3936d836c8..0ceef85bd8 100644 --- a/lib/rdoc/markup/heading.rb +++ b/lib/rdoc/markup/heading.rb @@ -52,10 +52,7 @@ def self.to_label #: () -> RDoc::Markup::ToHtml def self.to_html @to_html ||= begin - markup = Markup.new - markup.add_regexp_handling CrossReference::CROSSREF_REGEXP, :CROSSREF - - to_html = Markup::ToHtml.new nil + to_html = Markup::ToHtml.new def to_html.handle_regexp_CROSSREF(text) text.sub(/^\\/, '') diff --git a/lib/rdoc/markup/to_ansi.rb b/lib/rdoc/markup/to_ansi.rb index b3556a0744..19a188d197 100644 --- a/lib/rdoc/markup/to_ansi.rb +++ b/lib/rdoc/markup/to_ansi.rb @@ -7,7 +7,7 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc ## # Creates a new ToAnsi visitor that is ready to output vibrant ANSI color! - def initialize(markup = nil) + def initialize super @headings.clear diff --git a/lib/rdoc/markup/to_bs.rb b/lib/rdoc/markup/to_bs.rb index f047e30803..f060d36523 100644 --- a/lib/rdoc/markup/to_bs.rb +++ b/lib/rdoc/markup/to_bs.rb @@ -10,7 +10,7 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc ## # Returns a new ToBs that is ready for hot backspace action! - def initialize(markup = nil) + def initialize super @in_b = false diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index 6d9899000e..90eff47840 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -43,9 +43,11 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter ## # Creates a new formatter that will output HTML - def initialize(options, markup = nil) - super + def initialize(pipe: false, output_decoration: true) + super() + @pipe = pipe + @output_decoration = output_decoration @code_object = nil @from_path = '' @in_list_entry = nil @@ -347,7 +349,7 @@ def accept_verbatim(verbatim) CGI.escapeHTML text end - if @options.pipe then + if @pipe @res << "\n
#{CGI.escapeHTML text}\n\n"
else
@res << "\n#{content}\n"
@@ -418,17 +420,17 @@ def accept_heading(heading)
# Add legacy anchor before the heading for backward compatibility.
# This allows old links with label- prefix to still work.
- if @options.output_decoration && !@options.pipe
+ if @output_decoration && !@pipe
@res << "\n"
end
- @res << if @options.output_decoration
+ @res << if @output_decoration
"\nC1'), result
@@ -53,7 +49,9 @@ def test_convert_CROSSREF_backslash_in_tt
end
def test_convert_CROSSREF_ignored_excluded_words
- @options.autolink_excluded_words = ['C1']
+ @to = RDoc::Markup::ToHtmlCrossref.new 'index.html', @c1,
+ hyperlink_all: true, warn_missing_rdoc_ref: true,
+ autolink_excluded_words: ['C1']
result = @to.convert 'C1'
assert_equal para("C1"), result
@@ -285,7 +283,8 @@ def test_handle_regexp_HYPERLINK_rdoc
readme = @store.add_file 'README.txt'
readme.parser = RDoc::Parser::Simple
- @to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c2
+ @to = RDoc::Markup::ToHtmlCrossref.new 'C2.html', @c2,
+ hyperlink_all: true, warn_missing_rdoc_ref: true
link = @to.handle_regexp_HYPERLINK hyper 'C2::C3'
@@ -304,7 +303,8 @@ def test_handle_TIDYLINK_rdoc
readme = @store.add_file 'README.txt'
readme.parser = RDoc::Parser::Simple
- @to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c2
+ @to = RDoc::Markup::ToHtmlCrossref.new 'C2.html', @c2,
+ hyperlink_all: true, warn_missing_rdoc_ref: true
link = @to.to_html tidy 'C2::C3'
@@ -339,9 +339,7 @@ def test_convert_TIDYLINK_markdown_with_crossrefs
end
def test_to_html_CROSSREF_email
- @options.hyperlink_all = false
-
- @to = RDoc::Markup::ToHtmlCrossref.new @options, 'index.html', @c1
+ @to = RDoc::Markup::ToHtmlCrossref.new 'index.html', @c1
result = @to.to_html 'first.last@example.com'
@@ -361,7 +359,8 @@ def test_link
end
def test_link_for_method_traverse
- @to = RDoc::Markup::ToHtmlCrossref.new @options, 'C2.html', @c9
+ @to = RDoc::Markup::ToHtmlCrossref.new 'C2.html', @c9,
+ hyperlink_all: true, warn_missing_rdoc_ref: true
assert_equal 'C9::B#foo', @to.link('C9::B#foo', 'C9::B#foo')
end
diff --git a/test/rdoc/markup/to_html_snippet_test.rb b/test/rdoc/markup/to_html_snippet_test.rb
index ce9118a18c..b468b57474 100644
--- a/test/rdoc/markup/to_html_snippet_test.rb
+++ b/test/rdoc/markup/to_html_snippet_test.rb
@@ -8,7 +8,7 @@ class RDocMarkupToHtmlSnippetTest < RDoc::Markup::FormatterTestCase
def setup
super
- @to = RDoc::Markup::ToHtmlSnippet.new @options, 100, 100
+ @to = RDoc::Markup::ToHtmlSnippet.new 100, 100
@ellipsis = @to.to_html '...'
end
@@ -436,7 +436,7 @@ def test_accept_verbatim_ruby_error
end
def test_add_paragraph
- @to = RDoc::Markup::ToHtmlSnippet.new @options, 0, 3
+ @to = RDoc::Markup::ToHtmlSnippet.new 0, 3
assert_throws :done do
@to.add_paragraph
@to.add_paragraph
@@ -488,7 +488,7 @@ def test_convert_limit_2
end
def test_convert_limit_paragraphs
- @to = RDoc::Markup::ToHtmlSnippet.new @options, 100, 3
+ @to = RDoc::Markup::ToHtmlSnippet.new 100, 3
rdoc = <<-RDOC
= \RDoc - Ruby Documentation System
@@ -519,7 +519,7 @@ def test_convert_limit_paragraphs
end
def test_convert_limit_in_tag
- @to = RDoc::Markup::ToHtmlSnippet.new @options, 4
+ @to = RDoc::Markup::ToHtmlSnippet.new 4
rdoc = "* ab *c* d\n"
expected = "ab c #{@ellipsis}\n\n" @@ -598,7 +598,7 @@ def test_convert_limit_verbatim_multiline end def test_convert_limit_over - @to = RDoc::Markup::ToHtmlSnippet.new @options, 4 + @to = RDoc::Markup::ToHtmlSnippet.new 4 rdoc = "* text\n" * 2 expected = "
text\n" diff --git a/test/rdoc/markup/to_html_test.rb b/test/rdoc/markup/to_html_test.rb index 4e9ac38176..26d224eac2 100644 --- a/test/rdoc/markup/to_html_test.rb +++ b/test/rdoc/markup/to_html_test.rb @@ -8,7 +8,7 @@ class RDocMarkupToHtmlTest < RDoc::Markup::FormatterTestCase def setup super - @to = RDoc::Markup::ToHtml.new @options + @to = RDoc::Markup::ToHtml.new end def accept_blank_line @@ -351,7 +351,7 @@ def test_accept_heading_aref_method end def test_accept_heading_pipe - @options.pipe = true + @to = RDoc::Markup::ToHtml.new(pipe: true) @to.start_accepting @@ -451,7 +451,7 @@ def test_accept_paragraph_newline end def test_accept_heading_output_decoration - @options.output_decoration = false + @to = RDoc::Markup::ToHtml.new(output_decoration: false) @to.start_accepting @@ -461,8 +461,7 @@ def test_accept_heading_output_decoration end def test_accept_heading_output_decoration_with_pipe - @options.pipe = true - @options.output_decoration = false + @to = RDoc::Markup::ToHtml.new(pipe: true, output_decoration: false) @to.start_accepting @@ -520,7 +519,7 @@ def test_accept_verbatim_nl_after_backslash end def test_accept_verbatim_pipe - @options.pipe = true + @to = RDoc::Markup::ToHtml.new(pipe: true) verb = @RM::Verbatim.new("1 + 1\n") verb.format = :ruby diff --git a/test/rdoc/rdoc_markdown_test.rb b/test/rdoc/rdoc_markdown_test.rb index 1b3e4e96ce..eb7c487f27 100644 --- a/test/rdoc/rdoc_markdown_test.rb +++ b/test/rdoc/rdoc_markdown_test.rb @@ -14,7 +14,7 @@ def setup @parser = RDoc::Markdown.new - @to_html = RDoc::Markup::ToHtml.new(RDoc::Options.new, nil) + @to_html = RDoc::Markup::ToHtml.new end def test_class_parse diff --git a/test/rdoc/rdoc_text_test.rb b/test/rdoc/rdoc_text_test.rb index 03c4167ac5..1230536542 100644 --- a/test/rdoc/rdoc_text_test.rb +++ b/test/rdoc/rdoc_text_test.rb @@ -577,7 +577,7 @@ def test_to_html_tt_tag_mismatch end def formatter - RDoc::Markup::ToHtml.new @options + RDoc::Markup::ToHtml.new end def options