Skip to content

Commit

Permalink
escape hyphens in links to avoid word-wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
r10r committed Nov 30, 2022
1 parent 8d6b5c5 commit e5bd727
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion md2man/roff.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering
}
case blackfriday.Link:
if !entering {
out(w, linkTag+string(node.LinkData.Destination)+linkCloseTag)
// Hyphens in a link must be escaped to avoid word-wrap in the rendered man page.
escapedLink := strings.ReplaceAll(string(node.LinkData.Destination), "-", "\\-")
out(w, linkTag+escapedLink+linkCloseTag)
}
case blackfriday.Image:
// ignore images
Expand Down
2 changes: 2 additions & 0 deletions md2man/roff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ func TestLinks(t *testing.T) {
var tests = []string{
"See [docs](https://docs.docker.com/) for\nmore",
".nh\n\n.PP\nSee docs\n\\[la]https://docs.docker.com/\\[ra] for\nmore\n",
"See [docs](https://docs-foo.docker.com/) for\nmore",
".nh\n\n.PP\nSee docs\n\\[la]https://docs\\-foo.docker.com/\\[ra] for\nmore\n",
}
doTestsInline(t, tests)
}
Expand Down

0 comments on commit e5bd727

Please sign in to comment.