From 20d84ff8ad4b443da0cc1ff067fb92ebc3d436a5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 9 Nov 2015 16:02:04 +0200 Subject: Implement support pre-formatted fragments For example: / x y z / Other text. --- cli/html.cxx | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'cli/html.cxx') diff --git a/cli/html.cxx b/cli/html.cxx index 1f84fdd..e91fdd7 100644 --- a/cli/html.cxx +++ b/cli/html.cxx @@ -53,26 +53,66 @@ namespace size_t b (0), e (0), i (0); + bool nl (true); // True if last written to os character is a newline. + for (size_t n (d.size ()); i < n; ++i) { + // First handle
.
+      //
+      if (d.compare (i, 5, "
") == 0)
+      {
+        // Write what might have already accumulated.
+        //
+        if (b != i)
+        {
+          if (nl)
+            os << ind;
+
+          os << string (d, b, i - b);
+          nl = false;
+        }
+
+        // Output everything until (and including) closing 
as is. + // + e = d.find ("
", i + 5); + assert (e != string::npos); + e += 6; // Now points past '>'. + + if (nl) + os << ind; + + os << string (d, i, e - i); + + b = e; + i = e - 1; // For ++i in loop header. + nl = false; + continue; + } + if (d[i] == ' ' || d[i] == '\n') e = i; if (d[i] == '\n' || (i - b >= lim && e != b)) { - os << (b != 0 ? "\n" : "") << ind << string (d, b, e - b); + if (nl && b != e) + os << ind; - if (d[i] == '\n') - os << endl; + os << string (d, b, e - b) << endl; b = e = e + 1; + nl = true; } } // Write the last line. // if (b != i) - os << (b != 0 ? "\n" : "") << ind << string (d, b, i - b); + { + if (nl) + os << ind; + + os << string (d, b, i - b); + } } struct doc: traversal::doc, context -- cgit v1.1