diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index 25ade1e9f1..e2ca18801c 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -782,7 +782,22 @@ def template_for file, page = true, klass = ERB # Returns an excerpt of the content for usage in meta description tags def excerpt(content) - text = content.is_a?(RDoc::Comment) ? content.text : content + text = case content + when RDoc::Comment + content.text + when RDoc::Markup::Document + first_part = content.parts.first + + if first_part.respond_to?(:text) + first_part.text + else + # TODO: We may want to find a way to proceed to the following parts + # instead + return "" + end + else + content + end # Match from a capital letter to the first period, discarding any links, so # that we don't end up matching badges in the README diff --git a/test/rdoc/test_rdoc_generator_darkfish.rb b/test/rdoc/test_rdoc_generator_darkfish.rb index f6c0a1e1cf..cd0de8b289 100644 --- a/test/rdoc/test_rdoc_generator_darkfish.rb +++ b/test/rdoc/test_rdoc_generator_darkfish.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative 'helper' -class TestRDocGeneratorDarkfish < RDoc::TestCase +class RDocGeneratorDarkfishTest < RDoc::TestCase def setup super @@ -367,6 +367,48 @@ def test_meta_tags_for_pages ) end + def test_meta_tags_for_pages + top_level = @store.add_file("MyPage", parser: RDoc::Parser::Simple) + top_level.comment = RDoc::Markup::Document.new(RDoc::Markup::Paragraph.new('this is a comment')) + + @g.generate + + content = File.binread("MyPage.html") + assert_include(content, '') + assert_include( + content, + '', + ) + end + + def test_meta_tags_for_pages_with_non_text_parts + top_level = @store.add_file("MyPage", parser: RDoc::Parser::Simple) + top_level.comment = RDoc::Markup::Document.new(RDoc::Markup::BlankLine.new) + + @g.generate + + content = File.binread("MyPage.html") + assert_include(content, '') + assert_include( + content, + '', + ) + end + + def test_meta_tags_for_empty_document + top_level = @store.add_file("MyPage", parser: RDoc::Parser::Simple) + top_level.comment = RDoc::Markup::Document.new + + @g.generate + + content = File.binread("MyPage.html") + assert_include(content, '') + assert_include( + content, + '', + ) + end + ## # Asserts that +filename+ has a link count greater than 1 if hard links to # @tmpdir are supported.