Skip to content

Commit e2293e7

Browse files
committed
Don't warn on top-level comments
Add comment test cases Signed-off-by: Miloslav Trmač <[email protected]>
1 parent 8363f7d commit e2293e7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

md2man/roff.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering
167167
r.handleTableCell(w, node, entering)
168168
case blackfriday.HTMLSpan:
169169
// ignore other HTML tags
170+
case blackfriday.HTMLBlock:
171+
if bytes.HasPrefix(node.Literal, []byte("<!--")) {
172+
break // ignore comments, no warning
173+
}
174+
fmt.Fprintln(os.Stderr, "WARNING: go-md2man does not handle node type "+node.Type.String())
170175
default:
171176
fmt.Fprintln(os.Stderr, "WARNING: go-md2man does not handle node type "+node.Type.String())
172177
}

md2man/roff_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,20 @@ July 2014, updated by Sven Dowideit ([email protected])
398398
doTestsInline(t, tests)
399399
}
400400

401+
func TestComments(t *testing.T) {
402+
blockTests := []string{
403+
"First paragraph\n\n<!-- Comment, HTML should be separated by blank lines -->\n\nSecond paragraph\n",
404+
".nh\n\n.PP\nFirst paragraph\n\n.PP\nSecond paragraph\n",
405+
}
406+
doTestsParam(t, blockTests, TestParams{})
407+
408+
inlineTests := []string{
409+
"Text with a com<!--...-->ment in the middle\n",
410+
".nh\n\n.PP\nText with a comment in the middle\n",
411+
}
412+
doTestsInlineParam(t, inlineTests, TestParams{})
413+
}
414+
401415
func execRecoverableTestSuite(t *testing.T, tests []string, params TestParams, suite func(candidate *string)) {
402416
// Catch and report panics. This is useful when running 'go test -v' on
403417
// the integration server. When developing, though, crash dump is often

0 commit comments

Comments
 (0)