From 68381760c89c01520ac2286f0fe48ce8c2ab9a41 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 16 Apr 2018 14:07:04 +0200 Subject: Add support for note formatting in plain text output --- cli/context.cxx | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'cli/context.cxx') diff --git a/cli/context.cxx b/cli/context.cxx index 7c653a1..66f91c6 100644 --- a/cli/context.cxx +++ b/cli/context.cxx @@ -831,12 +831,9 @@ format_line (output_type ot, string& r, const char* l, size_t n) { if ((s & note) != 0) { - cerr << "error: \\N{} in plain text output not yet supported" - << endl; - throw generation_failed (); + r += "[Note: "; } - - if ((s & link) == 0) + else if ((s & link) == 0) { if (color) { @@ -951,9 +948,11 @@ format_line (output_type ot, string& r, const char* l, size_t n) { case ot_plain: { - assert ((s & note) == 0); - - if (s & link) + if ((s & note) != 0) + { + r += ']'; + } + else if ((s & link) != 0) { string t (link_section.empty () ? link_target @@ -1014,11 +1013,11 @@ format_line (output_type ot, string& r, const char* l, size_t n) } case ot_html: { - if (s & note) + if ((s & note) != 0) { r += ""; } - else if (s & link) + else if ((s & link) != 0) { if (link_empty) { @@ -1052,7 +1051,7 @@ format_line (output_type ot, string& r, const char* l, size_t n) { assert ((s & note) == 0); - if (s & link) + if ((s & link) != 0) { string t (link_section.empty () ? link_target @@ -2089,9 +2088,25 @@ format (semantics::scope& scope, string const& s, bool para) } case block::note: { - cerr << "error: " << pb.kind << "| in plain text output not " - << "yet supported" << endl; - throw generation_failed (); + v += dn; + + // Add a special character (bell) plus space in front of every + // line (including blanks). The bell is recognized and + // translated by txt_wrap_lines() to '|'. + // + char p ('\n'); // Previous character. + for (size_t i (0), n (pv.size ()); i != n; ++i) + { + char c (pv[i]); + + if (p == '\n') + v += (c != '\n' ? "\x07 " : "\x07"); + + v += c; + p = c; + } + + break; } case block::text: case block::pre: assert (false); -- cgit v1.1