ovsdb-doc: Distinguish hyphens and minus signs in nroff output.
authorBen Pfaff <blp@nicira.com>
Fri, 16 Apr 2010 17:31:05 +0000 (10:31 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 20 Apr 2010 18:01:44 +0000 (11:01 -0700)
In nroff, a minus sign (\-) should generally be used in literal text,
whereas hyphens are generally correct elsewhere.  This roughly corresponds
to bold versus non-bold text, so this commit makes ovsdb-doc output "-"
that appears in input as a minus sign if it is bold or a hyphen if it is
not.

ovsdb/ovsdb-doc.in

index cb21c1f..c4faf6f 100755 (executable)
@@ -14,9 +14,14 @@ from OVSDB import *
 
 argv0 = sys.argv[0]
 
-def textToNroff(s):
+def textToNroff(s, font=r'\fR'):
     def escape(match):
         c = match.group(0)
+        if c == '-':
+            if font == r'\fB':
+                return r'\-'
+            else:
+                return '-'
         if c == '\\':
             return r'\e'
         elif c == '"':
@@ -26,17 +31,18 @@ def textToNroff(s):
         else:
             raise Error("bad escape")
 
-    s = re.sub('([\\\\"\'])', escape, s)
+    # Escape - \ " ' as needed by nroff.
+    s = re.sub('([-"\'\\\\])', escape, s)
     if s.startswith('.'):
         s = '\\' + s
     return s
 
 def escapeNroffLiteral(s):
-    return r'\fB%s\fR' % textToNroff(s)
+    return r'\fB%s\fR' % textToNroff(s, r'\fB')
 
 def inlineXmlToNroff(node, font):
     if node.nodeType == node.TEXT_NODE:
-        return textToNroff(node.data)
+        return textToNroff(node.data, font)
     elif node.nodeType == node.ELEMENT_NODE:
         if node.tagName == 'code' or node.tagName == 'em':
             s = r'\fB'