Skip to content

Commit

Permalink
Ensure there is only one NAME section
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adminspotter committed Jan 6, 2024
1 parent 1c085db commit 2397449
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ronn/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def html_filter_inject_name_section
markup =
if title?
"<h1>#{title}</h1>"
elsif name
elsif name && !@html.css('h2').map(&:text).include?('NAME')
"<h2>NAME</h2>\n" \
"<p class='man-name'>\n <code>#{name}</code>" +
(tagline ? " - <span class='man-whatis'>#{tagline}</span>\n" : "\n") +
Expand Down
9 changes: 9 additions & 0 deletions test/existing_name_section.ronn
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Test #

## NAME ##

test - the test manpage

## DESCRIPTION ##

Testing items. w00t!
5 changes: 5 additions & 0 deletions test/test_ronn_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(/<h2[^>]*>NAME<\/h2>/).length == 1
end
end

0 comments on commit 2397449

Please sign in to comment.