From 49e1a3e6c7b756763e6a7d2f1ea33d23a5c9da04 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 20 Nov 2018 15:53:00 +0200 Subject: Escape more line-leading characters in man output Failed that, groff will treat them as macros/special. --- cli/man.cxx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'cli') diff --git a/cli/man.cxx b/cli/man.cxx index 6babdf1..b3cf922 100644 --- a/cli/man.cxx +++ b/cli/man.cxx @@ -12,15 +12,24 @@ using namespace std; namespace { + // According to groff_mdoc(7), groff may have issues with any of the + // following characters at the beginning of the line: + // + // {}+-/*%<>=,&`'" + // + // Plus, escaping leading '.' with '\' is not sufficient. + // + static const string escape ("{}+-/*%<>=,&`'\""); + static string escape_line (const string& s, size_t b, size_t e) { string r; size_t n (e - b); - // Escaping leading '.' with '\' is not sufficient. - // - if (n > 1 && s[b] == '\\' && s[b + 1] == '.') + + if (escape.find (s[b]) != string::npos || + (n > 1 && s[b] == '\\' && s[b + 1] == '.')) r = "\\&"; r.append (s, b, n); -- cgit v1.1