Skip to content

Commit

Permalink
Don't warn on top-level comments
Browse files Browse the repository at this point in the history
Add comment test cases

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
  • Loading branch information
mtrmac committed Sep 25, 2023
1 parent 8363f7d commit e2293e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions md2man/roff.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering
r.handleTableCell(w, node, entering)
case blackfriday.HTMLSpan:
// ignore other HTML tags
case blackfriday.HTMLBlock:
if bytes.HasPrefix(node.Literal, []byte("<!--")) {
break // ignore comments, no warning
}
fmt.Fprintln(os.Stderr, "WARNING: go-md2man does not handle node type "+node.Type.String())
default:
fmt.Fprintln(os.Stderr, "WARNING: go-md2man does not handle node type "+node.Type.String())
}
Expand Down
14 changes: 14 additions & 0 deletions md2man/roff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,20 @@ July 2014, updated by Sven Dowideit (SvenDowideit@home.org.au)
doTestsInline(t, tests)
}

func TestComments(t *testing.T) {
blockTests := []string{
"First paragraph\n\n<!-- Comment, HTML should be separated by blank lines -->\n\nSecond paragraph\n",
".nh\n\n.PP\nFirst paragraph\n\n.PP\nSecond paragraph\n",
}
doTestsParam(t, blockTests, TestParams{})

inlineTests := []string{
"Text with a com<!--...-->ment in the middle\n",
".nh\n\n.PP\nText with a comment in the middle\n",
}
doTestsInlineParam(t, inlineTests, TestParams{})
}

func execRecoverableTestSuite(t *testing.T, tests []string, params TestParams, suite func(candidate *string)) {
// Catch and report panics. This is useful when running 'go test -v' on
// the integration server. When developing, though, crash dump is often
Expand Down

0 comments on commit e2293e7

Please sign in to comment.