summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-11-20 15:53:00 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-11-20 15:53:00 +0200
commit49e1a3e6c7b756763e6a7d2f1ea33d23a5c9da04 (patch)
treea1b0a4e44573484569db16b80c1e3ab1483c0279
parent3aa35e220c7c900b78a551cc366eafad2700f6d3 (diff)
Escape more line-leading characters in man output
Failed that, groff will treat them as macros/special.
-rw-r--r--cli/man.cxx15
1 files changed, 12 insertions, 3 deletions
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);