From 239744980a9a919c2dc348d74c31edca7f15f090 Mon Sep 17 00:00:00 2001 From: Trinity Quirk Date: Sat, 6 Jan 2024 13:58:49 -0800 Subject: [PATCH] Ensure there is only one NAME section Some documents may include a NAME section in the original text. We'll make sure to check before we add one of our own; if there's already one, we can skip adding a new one. --- lib/ronn/document.rb | 2 +- test/existing_name_section.ronn | 9 +++++++++ test/test_ronn_document.rb | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/existing_name_section.ronn diff --git a/lib/ronn/document.rb b/lib/ronn/document.rb index b549128..7da173d 100644 --- a/lib/ronn/document.rb +++ b/lib/ronn/document.rb @@ -460,7 +460,7 @@ def html_filter_inject_name_section markup = if title? "

#{title}

" - elsif name + elsif name && !@html.css('h2').map(&:text).include?('NAME') "

NAME

\n" \ "

\n #{name}" + (tagline ? " - #{tagline}\n" : "\n") + diff --git a/test/existing_name_section.ronn b/test/existing_name_section.ronn new file mode 100644 index 0000000..f100833 --- /dev/null +++ b/test/existing_name_section.ronn @@ -0,0 +1,9 @@ +# Test # + +## NAME ## + +test - the test manpage + +## DESCRIPTION ## + +Testing items. w00t! diff --git a/test/test_ronn_document.rb b/test/test_ronn_document.rb index 56a8b85..57cf9d2 100644 --- a/test/test_ronn_document.rb +++ b/test/test_ronn_document.rb @@ -200,4 +200,9 @@ def canonicalize(text) @doc = Ronn::Document.new('hello.1.ronn', styles: %w[test boom test]) { '' } assert_equal %w[man test boom], @doc.styles end + + test 'NAME section is not duplicated' do + html = Ronn::Document.new(File.expand_path('existing_name_section.ronn', __dir__)).to_html + assert html.scan(/]*>NAME<\/h2>/).length == 1 + end end