Skip to content

Commit

Permalink
Stop over-indenting lists that are not nested
Browse files Browse the repository at this point in the history
List items are already indented paragraphs. There is no need to also
increase the relative inset unless the list is nested inside another
list.

Signed-off-by: Cory Snider <[email protected]>
  • Loading branch information
corhere committed Sep 12, 2024
1 parent f486e72 commit 149c352
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
19 changes: 17 additions & 2 deletions md2man/roff.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ func (r *roffRenderer) RenderNode(w io.Writer, node *blackfriday.Node, entering
if r.listDepth > 0 {
// roff .PP markers break lists
if node.Prev != nil { // continued paragraph
out(w, crTag)
if node.Prev.Type == blackfriday.List && node.Prev.ListFlags&blackfriday.ListTypeDefinition == 0 {
out(w, ".IP\n")
} else {
out(w, crTag)
}
}
} else if node.Prev != nil && node.Prev.Type == blackfriday.Heading {
out(w, crTag)
Expand Down Expand Up @@ -227,6 +231,10 @@ func (r *roffRenderer) handleHeading(w io.Writer, node *blackfriday.Node, enteri
func (r *roffRenderer) handleList(w io.Writer, node *blackfriday.Node, entering bool) {
openTag := listTag
closeTag := listCloseTag
if (entering && r.listDepth == 0) || (!entering && r.listDepth == 1) {
openTag = crTag
closeTag = ""
}
if node.ListFlags&blackfriday.ListTypeDefinition != 0 {
// tags for definition lists handled within Item node
openTag = ""
Expand Down Expand Up @@ -262,7 +270,14 @@ func (r *roffRenderer) handleItem(w io.Writer, node *blackfriday.Node, entering
// subsequent ones, as there should be no vertical
// whitespace between the DT and the first DD.
if node.Prev != nil && node.Prev.ListFlags&(blackfriday.ListTypeTerm|blackfriday.ListTypeDefinition) == blackfriday.ListTypeDefinition {
out(w, dd2Tag)
if node.Prev.Type == blackfriday.Item &&
node.Prev.LastChild != nil &&
node.Prev.LastChild.Type == blackfriday.List &&
node.Prev.LastChild.ListFlags&blackfriday.ListTypeDefinition == 0 {
out(w, ".IP\n")
} else {
out(w, dd2Tag)
}
}
} else {
out(w, ".IP \\(bu 2\n")
Expand Down
8 changes: 8 additions & 0 deletions md2man/roff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ func TestCodeSpan(t *testing.T) {
doTestsInline(t, tests)
}

func TestFlatLists(t *testing.T) {
tests := []string{
"Paragraph\n\n- item one\n- item two\n- item three\n",
".nh\n\n.PP\nParagraph\n.IP \\(bu 2\nitem one\n.IP \\(bu 2\nitem two\n.IP \\(bu 2\nitem three\n",
}
doTestsInline(t, tests)
}

func TestListLists(t *testing.T) {
tests := []string{
"\n\n**[grpc]**\n: Section for gRPC socket listener settings. Contains three properties:\n - **address** (Default: \"/run/containerd/containerd.sock\")\n - **uid** (Default: 0)\n - **gid** (Default: 0)",
Expand Down

0 comments on commit 149c352

Please sign in to comment.