diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-11-09 16:02:04 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-11-09 16:02:04 +0200 |
commit | 20d84ff8ad4b443da0cc1ff067fb92ebc3d436a5 (patch) | |
tree | 12dbc2bab8f099f3a158028eba460fc6f453a756 /cli/html.cxx | |
parent | 4bd33d0eb078b23d1c9ec181f07159e9141bea69 (diff) |
Implement support pre-formatted fragments
For example:
/
x
y
z
/
Other text.
Diffstat (limited to 'cli/html.cxx')
-rw-r--r-- | cli/html.cxx | 48 |
1 files changed, 44 insertions, 4 deletions
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 <pre>. + // + if (d.compare (i, 5, "<pre>") == 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 </pre> as is. + // + e = d.find ("</pre>", 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 |