Skip to content

Commit 563aa3a

Browse files
committedMar 10, 2021
Ignore unknown HTML tags to prevent noisy warnings
blackfriday v2 introduced "HTMLSpan" as a node-type, causing go-md2man to produce warnings as it didn't have specific handling for these nodes. This patch makes go-md2man ignore these node types (e.g. <span> elements, or <svg>), and skip the element themselves (only rendering their content, if any), to prevent go-md2man printing noisy warnings during generation: WARNING: go-md2man does not handle node type HTMLSpan WARNING: go-md2man does not handle node type HTMLSpan WARNING: go-md2man does not handle node type HTMLSpan WARNING: go-md2man does not handle node type HTMLSpan WARNING: go-md2man does not handle node type HTMLSpan ... Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent af8da76 commit 563aa3a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
 

‎md2man/roff.go

+2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering
157157
case blackfriday.TableRow:
158158
// no action as cell entries do all the nroff formatting
159159
return blackfriday.GoToNext
160+
case blackfriday.HTMLSpan:
161+
// ignore other HTML tags
160162
default:
161163
fmt.Fprintln(os.Stderr, "WARNING: go-md2man does not handle node type "+node.Type.String())
162164
}

‎md2man/roff_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,40 @@ func TestEscapeCharacters(t *testing.T) {
287287
doTestsInline(t, tests)
288288
}
289289

290+
func TestSpan(t *testing.T) {
291+
var tests = []string{
292+
"Text containing a <span>html span</span> element\n",
293+
".nh\n\n.PP\nText containing a html span element\n",
294+
295+
`Text containing an inline <svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"><image href="https://mdn.mozillademos.org/files/6457/mdn_logo_only_color.png" height="200" width="200"/></svg>SVG image`,
296+
".nh\n\n.PP\nText containing an inline SVG image\n",
297+
298+
"Text containing a <span id=\"e-123\" class=\"foo\">html span</span> element\n",
299+
".nh\n\n.PP\nText containing a html span element\n",
300+
}
301+
doTestsInline(t, tests)
302+
}
303+
304+
func TestEmails(t *testing.T) {
305+
var tests = []string{
306+
`April 2014, Originally compiled by William Henry (whenry at redhat dot com)
307+
based on docker.com source material and internal work.
308+
June 2014, updated by Sven Dowideit <SvenDowideit@home.org.au>
309+
July 2014, updated by Sven Dowideit (SvenDowideit@home.org.au)
310+
`,
311+
`.nh
312+
313+
.PP
314+
April 2014, Originally compiled by William Henry (whenry at redhat dot com)
315+
based on docker.com source material and internal work.
316+
June 2014, updated by Sven Dowideit SvenDowideit@home.org.au
317+
\[la]mailto:SvenDowideit@home.org.au\[ra]
318+
July 2014, updated by Sven Dowideit (SvenDowideit@home.org.au)
319+
`,
320+
}
321+
doTestsInline(t, tests)
322+
}
323+
290324
func execRecoverableTestSuite(t *testing.T, tests []string, params TestParams, suite func(candidate *string)) {
291325
// Catch and report panics. This is useful when running 'go test -v' on
292326
// the integration server. When developing, though, crash dump is often

0 commit comments

Comments
 (0)
Please sign in to comment.