From 1e211d9bce1e3af6c58eb2a04a84f92f83e0d7d7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 5 Mar 2018 13:58:43 +0200 Subject: Set "code" style for code-only paragraphs, cleanup nested --- cli/context.cxx | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/cli/context.cxx b/cli/context.cxx index d2daab4..fa63dd1 100644 --- a/cli/context.cxx +++ b/cli/context.cxx @@ -1684,7 +1684,60 @@ format (semantics::scope& scope, string const& s, bool para) format_line (ot, t, l, n); string s (html_margin (t)); - v += (s.empty () ? "

" : "

"); + // If the entire paragraph is wrapped in then signal this + // fact via the "code" class. This can be used, for example, to + // change alignment from "justify" to "left" in order to support + // custom alignments (in combination with non-ignorable space + // escaping; think multi-line synopsis in man pages). + // + // While at it also cleanup nested fragments (we + // may end up with quite a few of them due to the + // translation). + // + string c; + { + size_t n (t.size ()); + + if (n >= 13 && + t.compare (0, 6, "") == 0 && + t.compare (n - 7, 7, "") == 0) + { + string tt; + + // Make sure this is one contigous . + // + size_t b (1); // / balance. + for (size_t i (6), j (0); + i != n && (i = t.find ("code>", i)) != string::npos; + j = i = i + 5) + { + if (t[i - 1] == '<') b++; + else if (t[i - 1] == '/' && t[i - 2] == '<') b--; + else continue; + + // Append previous chunk. + // + tt.append (t, j, i - j - (t[i - 1] == '<' ? 1 : 2)); + + if (b == 0) + { + if (i + 5 == n) + { + tt.append (t, i - 2, 7); // Closing . + t = move (tt); + c = "code"; + } + + break; + } + } + } + } + + v += "