Skip to content

Commit

Permalink
python: Fix nroff indentation for <dl> after <hN>.
Browse files Browse the repository at this point in the history
When XML is used for writing manpages, in the case that there is a
header tag followed by <dl>, the nroff python utility indents the <dl>
tag (and children) an extra level which is unnecessary and makes the
formatting inconsistent between manpages written directly in nroff vs
manpages written in XML and converted to nroff. Fix the indentation by
removing the extraneous .RS / .RE tags added to generated nroff in this
case.

This fixes the formatting of ovn/utilities/ovn-nbctl.8 man page.

Signed-off-by: Joe Stringer <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
joestringer committed Jan 6, 2017
1 parent e522804 commit 44b8def
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions python/build/nroff.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ def diagram_to_nroff(nodes, para):


def block_xml_to_nroff(nodes, para='.PP'):
HEADER_TAGS = ('h1', 'h2', 'h3')
s = ''
prev = ''
for node in nodes:
if node.nodeType == node.TEXT_NODE:
s += text_to_nroff(node.data)
Expand Down Expand Up @@ -248,9 +250,13 @@ def block_xml_to_nroff(nodes, para='.PP'):
"<li> children" % node.tagName)
s += ".RE\n"
elif node.tagName == 'dl':
indent = True
if prev in HEADER_TAGS:
indent = False
if s != "":
s += "\n"
s += ".RS\n"
if indent:
s += ".RS\n"
prev = "dd"
for li_node in node.childNodes:
if (li_node.nodeType == node.ELEMENT_NODE
Expand All @@ -272,14 +278,15 @@ def block_xml_to_nroff(nodes, para='.PP'):
raise error.Error("<dl> element may only have "
"<dt> and <dd> children")
s += block_xml_to_nroff(li_node.childNodes, ".IP")
s += ".RE\n"
if indent:
s += ".RE\n"
elif node.tagName == 'p':
if s != "":
if not s.endswith("\n"):
s += "\n"
s += para + "\n"
s += block_xml_to_nroff(node.childNodes, para)
elif node.tagName in ('h1', 'h2', 'h3'):
elif node.tagName in HEADER_TAGS:
if s != "":
if not s.endswith("\n"):
s += "\n"
Expand All @@ -300,6 +307,7 @@ def block_xml_to_nroff(nodes, para='.PP'):
s += diagram_to_nroff(node.childNodes, para)
else:
s += inline_xml_to_nroff(node, r'\fR')
prev = node.tagName
elif node.nodeType == node.COMMENT_NODE:
pass
else:
Expand Down

0 comments on commit 44b8def

Please sign in to comment.