diff --git a/lib/rdoc.rb b/lib/rdoc.rb index b42059c712..d93d79e4d1 100644 --- a/lib/rdoc.rb +++ b/lib/rdoc.rb @@ -189,7 +189,6 @@ def self.home autoload :Context, "#{__dir__}/rdoc/code_object/context" autoload :TopLevel, "#{__dir__}/rdoc/code_object/top_level" - autoload :AnonClass, "#{__dir__}/rdoc/code_object/anon_class" autoload :ClassModule, "#{__dir__}/rdoc/code_object/class_module" autoload :NormalClass, "#{__dir__}/rdoc/code_object/normal_class" autoload :NormalModule, "#{__dir__}/rdoc/code_object/normal_module" diff --git a/lib/rdoc/code_object.rb b/lib/rdoc/code_object.rb index 4f5a998fc6..c15c0129f5 100644 --- a/lib/rdoc/code_object.rb +++ b/lib/rdoc/code_object.rb @@ -10,7 +10,6 @@ # * RDoc::Context # * RDoc::TopLevel # * RDoc::ClassModule -# * RDoc::AnonClass (never used so far) # * RDoc::NormalClass # * RDoc::NormalModule # * RDoc::SingleClass diff --git a/lib/rdoc/code_object/anon_class.rb b/lib/rdoc/code_object/anon_class.rb deleted file mode 100644 index 3c2f0e1877..0000000000 --- a/lib/rdoc/code_object/anon_class.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true -## -# An anonymous class like: -# -# c = Class.new do end -# -# AnonClass is currently not used. - -class RDoc::AnonClass < RDoc::ClassModule -end diff --git a/lib/rdoc/code_object/context/section.rb b/lib/rdoc/code_object/context/section.rb index 05e7c688bc..cf91be9d81 100644 --- a/lib/rdoc/code_object/context/section.rb +++ b/lib/rdoc/code_object/context/section.rb @@ -106,6 +106,9 @@ def legacy_aref # # # :section: The title # # The body + # + #-- + # TODO Remove when the ripper parser has been removed def extract_comment(comment) case comment diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index e3f45deeab..574918500f 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -73,11 +73,6 @@ class RDoc::Generator::Darkfish css/rdoc.css ] - ## - # Release Version - - VERSION = '3' - ## # Description of this generator diff --git a/lib/rdoc/markup/formatter.rb b/lib/rdoc/markup/formatter.rb index 433237393d..0532fae5fc 100644 --- a/lib/rdoc/markup/formatter.rb +++ b/lib/rdoc/markup/formatter.rb @@ -14,13 +14,6 @@ class RDoc::Markup::Formatter - ## - # Tag for inline markup containing a +bit+ for the bitmask and the +on+ and - # +off+ triggers. - - InlineTag = Struct.new(:bit, :on, :off) - - ## # Converts a target url to one that is relative to a given path diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb index 6e0d0793be..e088303801 100644 --- a/lib/rdoc/markup/to_html_crossref.rb +++ b/lib/rdoc/markup/to_html_crossref.rb @@ -8,9 +8,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml # :stopdoc: ALL_CROSSREF_REGEXP = RDoc::CrossReference::ALL_CROSSREF_REGEXP - CLASS_REGEXP_STR = RDoc::CrossReference::CLASS_REGEXP_STR CROSSREF_REGEXP = RDoc::CrossReference::CROSSREF_REGEXP - METHOD_REGEXP_STR = RDoc::CrossReference::METHOD_REGEXP_STR # :startdoc: ## diff --git a/lib/rdoc/parser/prism_ruby.rb b/lib/rdoc/parser/prism_ruby.rb index 9ff93eacd6..e8dedd5c18 100644 --- a/lib/rdoc/parser/prism_ruby.rb +++ b/lib/rdoc/parser/prism_ruby.rb @@ -473,15 +473,28 @@ def parse_comment_text_to_directives(comment_text, start_line) # :nodoc: comment.line = start_line markup, = directives['markup'] comment.format = markup&.downcase || @markup - if (section, = directives['section']) + if (section, directive_line = directives['section']) # If comment has :section:, it is not a documentable comment for a code object - @container.set_current_section(section, comment.dup) + comment.text = extract_section_comment(comment_text, directive_line - start_line) + @container.set_current_section(section, comment) return end @preprocess.run_post_processes(comment, @container) [comment, directives] end + # Extracts the comment for this section from the normalized comment block. + # Removes all lines before the line that contains :section: + # If the comment also ends with the same content, remove it as well + + def extract_section_comment(comment_text, prefix_line_count) # :nodoc: + prefix = comment_text.lines[0...prefix_line_count].join + comment_text.delete_prefix!(prefix) + # Comment is already normalized and doesn't end with a newline + comment_text.delete_suffix!(prefix.chomp) + comment_text + end + def slice_tokens(start_pos, end_pos) # :nodoc: start_index = @tokens.bsearch_index { |t| ([t.line_no, t.char_no] <=> start_pos) >= 0 } end_index = @tokens.bsearch_index { |t| ([t.line_no, t.char_no] <=> end_pos) >= 0 } diff --git a/test/rdoc/parser/prism_ruby_test.rb b/test/rdoc/parser/prism_ruby_test.rb index d336b4e740..f018123f7b 100644 --- a/test/rdoc/parser/prism_ruby_test.rb +++ b/test/rdoc/parser/prism_ruby_test.rb @@ -36,6 +36,41 @@ def test_look_for_directives_in_section assert_equal 'new section', section.title end + def test_section_with_divider + util_parser <<~RUBY + # DIVIDER + # :section: section 1 + # foo + # DIVIDER + + # DIVIDER 1 + # DIVIDER 2 + # :section: section 2 + # foo + # DIVIDER 1 + # DIVIDER 2 + + # DIVIDER TOP ONLY + # :section: section 3 + # foo + + # DIVIDER TOP ONLY + # :section: section 4 + RUBY + + section = @top_level.sections_hash['section 1'] + assert_equal "\n

foo

\n", section.description + + section = @top_level.sections_hash['section 2'] + assert_equal "\n

foo

\n", section.description + + section = @top_level.sections_hash['section 3'] + assert_equal "\n

foo

\n", section.description + + section = @top_level.sections_hash['section 4'] + assert_equal '', section.description + end + def test_look_for_directives_in_commented util_parser <<~RUBY # how to make a section: