diff mbox

[ovs-dev,PATCHv2] python: Fix nroff indentation for <dl> after <h1>.

Message ID 20170106020935.9505-1-joe@ovn.org
State Accepted
Headers show

Commit Message

Joe Stringer Jan. 6, 2017, 2:09 a.m. UTC
When XML is used for writing manpages, in the case that there is a <h1>
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 <joe@ovn.org>
---
 python/build/nroff.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Ben Pfaff Jan. 6, 2017, 4:16 a.m. UTC | #1
On Thu, Jan 05, 2017 at 06:09:35PM -0800, Joe Stringer wrote:
> When XML is used for writing manpages, in the case that there is a <h1>
> 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 <joe@ovn.org>

nroff sucks so much.

I suspect that this should actually apply to all h*, not just to h1.
None of the headings imply indentation.

Acked-by: Ben Pfaff <blp@ovn.org>
Joe Stringer Jan. 6, 2017, 8:41 p.m. UTC | #2
On 5 January 2017 at 20:16, Ben Pfaff <blp@ovn.org> wrote:
> On Thu, Jan 05, 2017 at 06:09:35PM -0800, Joe Stringer wrote:
>> When XML is used for writing manpages, in the case that there is a <h1>
>> 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 <joe@ovn.org>
>
> nroff sucks so much.
>
> I suspect that this should actually apply to all h*, not just to h1.
> None of the headings imply indentation.
>
> Acked-by: Ben Pfaff <blp@ovn.org>

I updated this to work the same for all headers, and pushed to master. Thanks.
diff mbox

Patch

diff --git a/python/build/nroff.py b/python/build/nroff.py
index aed60ebbd592..8af1719f9dc4 100644
--- a/python/build/nroff.py
+++ b/python/build/nroff.py
@@ -221,6 +221,7 @@  fillval = .2
 
 def block_xml_to_nroff(nodes, para='.PP'):
     s = ''
+    prev = ''
     for node in nodes:
         if node.nodeType == node.TEXT_NODE:
             s += text_to_nroff(node.data)
@@ -248,9 +249,13 @@  def block_xml_to_nroff(nodes, para='.PP'):
                                           "<li> children" % node.tagName)
                 s += ".RE\n"
             elif node.tagName == 'dl':
+                indent = True
+                if prev == 'h1':
+                    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
@@ -272,7 +277,8 @@  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"):
@@ -300,6 +306,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: