From fcbaf28cb38d2a848e78d7ba42800eb03fbe6579 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 16 Apr 2010 10:31:05 -0700 Subject: [PATCH] ovsdb-doc: Distinguish hyphens and minus signs in nroff output. 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 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/ovsdb/ovsdb-doc.in b/ovsdb/ovsdb-doc.in index cb21c1f4..c4faf6f2 100755 --- a/ovsdb/ovsdb-doc.in +++ b/ovsdb/ovsdb-doc.in @@ -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' -- 2.30.2