From 4d02432c918d9ce431bf6c3e3d2b7410093dfbb5 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 11 Feb 2016 08:31:34 +0200 Subject: Add support for re-mapping HTML headings --- cli/context.cxx | 39 +++++++++++++++++++++++++++------------ cli/options.cli | 8 ++++++++ cli/options.cxx | 29 +++++++++++++++++++++++++---- cli/options.hxx | 8 ++++++++ cli/options.ixx | 12 ++++++++++++ 5 files changed, 80 insertions(+), 16 deletions(-) (limited to 'cli') diff --git a/cli/context.cxx b/cli/context.cxx index 5b1d387..1b98322 100644 --- a/cli/context.cxx +++ b/cli/context.cxx @@ -1158,7 +1158,7 @@ format (semantics::scope& scope, string const& s, bool para) // Mapping of \h to HTML tag. By default it is

until we encounter // \h0 or \h1 at which point we change it to

. // - string html_h ("h1"); + char html_h ('1'); bool last (false); for (size_t b (0), e; !last; b = e + 1) @@ -1721,7 +1721,7 @@ format (semantics::scope& scope, string const& s, bool para) case '1': break; // Always unwind. case 'h': { - pop = html_h[1] == '1' || e.type == 'h' || e.type == '2'; + pop = html_h == '1' || e.type == 'h' || e.type == '2'; break; } case '2': pop = e.type == '2'; break; @@ -1815,8 +1815,8 @@ format (semantics::scope& scope, string const& s, bool para) // // @@ This only works for a single string fragment. // - if (ph[0] == '0' || ph[0] == '1') - html_h = "h2"; + if (t == '0' || t == '1') + html_h = '2'; break; } @@ -1906,17 +1906,28 @@ format (semantics::scope& scope, string const& s, bool para) { case block::h: { + char t (ph[0]); + string h; string c; - switch (ph[0]) + typedef map map; + const map& hm (options.html_heading_map ()); + map::const_iterator mi (hm.find (t)); + + if (mi == hm.end ()) { - case '0': h = "h1"; c = "preface"; break; - case 'H': h = "h1"; c = "part"; break; - case '1': h = "h1"; break; - case 'h': h = html_h; break; - case '2': h = "h3"; break; + switch (t) + { + case '0': h = "h1"; c = "preface"; break; + case 'H': h = "h1"; c = "part"; break; + case '1': h = "h1"; break; + case 'h': h = html_h == '1' ? "h1" : "h2"; break; + case '2': h = "h3"; break; + } } + else + h = mi->second; v += '<' + h; if (!pi.empty ()) v += " id=\"" + pi + '"'; @@ -1939,8 +1950,8 @@ format (semantics::scope& scope, string const& s, bool para) // @@ This only works for a single string fragment. // - if (ph[0] == '0' || ph[0] == '1') - html_h = "h2"; + if (t == '0' || t == '1') + html_h = '2'; break; } @@ -2056,6 +2067,8 @@ start_toc () } case ot_man: break; } + + return string (); } string context:: @@ -2095,6 +2108,8 @@ end_toc () } case ot_man: break; } + + return string (); } void context:: diff --git a/cli/options.cli b/cli/options.cli index 8a4a3e0..501cc82 100644 --- a/cli/options.cli +++ b/cli/options.cli @@ -256,6 +256,14 @@ class options expressions don't do what you expected them to do." }; + std::map --html-heading-map + { + "=", + "Map CLI heading (valid values: '\cb{H}', '\cb{0}', '\cb{1}', + '\cb{h}', and '\cb{2}') to HTML heading (for example, '\cb{h1}', + '\cb{h2}', etc)." + }; + // Prologues. // std::vector --hxx-prologue diff --git a/cli/options.cxx b/cli/options.cxx index cdc2d41..6008a4b 100644 --- a/cli/options.cxx +++ b/cli/options.cxx @@ -418,13 +418,15 @@ namespace cli static void parse (X& x, bool& xs, scanner& s) { - std::string o (s.next ()); + using namespace std; + + string o (s.next ()); if (s.more ()) { - std::string v (s.next ()); - std::istringstream is (v); - if (!(is >> x && is.eof ())) + string v (s.next ()); + istringstream is (v); + if (!(is >> x && is.peek () == istringstream::traits_type::eof ())) throw invalid_value (o, v); } else @@ -604,6 +606,8 @@ options () link_regex_ (), link_regex_specified_ (false), link_regex_trace_ (), + html_heading_map_ (), + html_heading_map_specified_ (false), hxx_prologue_ (), hxx_prologue_specified_ (false), ixx_prologue_ (), @@ -733,6 +737,8 @@ options (int& argc, link_regex_ (), link_regex_specified_ (false), link_regex_trace_ (), + html_heading_map_ (), + html_heading_map_specified_ (false), hxx_prologue_ (), hxx_prologue_specified_ (false), ixx_prologue_ (), @@ -865,6 +871,8 @@ options (int start, link_regex_ (), link_regex_specified_ (false), link_regex_trace_ (), + html_heading_map_ (), + html_heading_map_specified_ (false), hxx_prologue_ (), hxx_prologue_specified_ (false), ixx_prologue_ (), @@ -997,6 +1005,8 @@ options (int& argc, link_regex_ (), link_regex_specified_ (false), link_regex_trace_ (), + html_heading_map_ (), + html_heading_map_specified_ (false), hxx_prologue_ (), hxx_prologue_specified_ (false), ixx_prologue_ (), @@ -1131,6 +1141,8 @@ options (int start, link_regex_ (), link_regex_specified_ (false), link_regex_trace_ (), + html_heading_map_ (), + html_heading_map_specified_ (false), hxx_prologue_ (), hxx_prologue_specified_ (false), ixx_prologue_ (), @@ -1261,6 +1273,8 @@ options (::cli::scanner& s, link_regex_ (), link_regex_specified_ (false), link_regex_trace_ (), + html_heading_map_ (), + html_heading_map_specified_ (false), hxx_prologue_ (), hxx_prologue_specified_ (false), ixx_prologue_ (), @@ -1440,6 +1454,10 @@ print_usage (::std::ostream& os, ::cli::usage_para p) os << "--link-regex-trace Trace the process of applying regular expressions" << ::std::endl << " specified with the --link-regex option." << ::std::endl; + os << "--html-heading-map = Map CLI heading (valid values: 'H', '0', '1'," << ::std::endl + << " 'h', and '2') to HTML heading (for example," << ::std::endl + << " 'h1', 'h2', etc)." << ::std::endl; + os << "--hxx-prologue Insert at the beginning of the generated" << ::std::endl << " C++ header file." << ::std::endl; @@ -1658,6 +1676,9 @@ struct _cli_options_map_init &options::link_regex_specified_ >; _cli_options_map_["--link-regex-trace"] = &::cli::thunk< options, bool, &options::link_regex_trace_ >; + _cli_options_map_["--html-heading-map"] = + &::cli::thunk< options, std::map, &options::html_heading_map_, + &options::html_heading_map_specified_ >; _cli_options_map_["--hxx-prologue"] = &::cli::thunk< options, std::vector, &options::hxx_prologue_, &options::hxx_prologue_specified_ >; diff --git a/cli/options.hxx b/cli/options.hxx index 5edd480..74dfb1e 100644 --- a/cli/options.hxx +++ b/cli/options.hxx @@ -522,6 +522,12 @@ class options const bool& link_regex_trace () const; + const std::map& + html_heading_map () const; + + bool + html_heading_map_specified () const; + const std::vector& hxx_prologue () const; @@ -815,6 +821,8 @@ class options std::vector link_regex_; bool link_regex_specified_; bool link_regex_trace_; + std::map html_heading_map_; + bool html_heading_map_specified_; std::vector hxx_prologue_; bool hxx_prologue_specified_; std::vector ixx_prologue_; diff --git a/cli/options.ixx b/cli/options.ixx index 95c1038..6e7520b 100644 --- a/cli/options.ixx +++ b/cli/options.ixx @@ -469,6 +469,18 @@ link_regex_trace () const return this->link_regex_trace_; } +inline const std::map& options:: +html_heading_map () const +{ + return this->html_heading_map_; +} + +inline bool options:: +html_heading_map_specified () const +{ + return this->html_heading_map_specified_; +} + inline const std::vector& options:: hxx_prologue () const { -- cgit v1.1