diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2016-02-11 07:45:21 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2016-02-11 07:45:21 +0200 |
commit | 96ff207be28274ae59aa67e941c7a6a261ae0c47 (patch) | |
tree | 71a10da562ac4ceb1514b227b2b1ecd0ee87ce9d | |
parent | cd73ee1fe287ca77b44370760d72f7eb145f096e (diff) |
Assign numbers to TOC headings
-rw-r--r-- | cli/context.cxx | 20 | ||||
-rw-r--r-- | cli/context.hxx | 5 | ||||
-rw-r--r-- | tests/toc/toc.html | 18 |
3 files changed, 34 insertions, 9 deletions
diff --git a/cli/context.cxx b/cli/context.cxx index cd5d88c..5b1d387 100644 --- a/cli/context.cxx +++ b/cli/context.cxx @@ -117,6 +117,7 @@ context (ostream& os_, link_regex (data_->link_regex_), id_set (data_->id_set_), ref_set (data_->ref_set_), + heading_map (data_->heading_map_), toc (data_->toc_), tocs (data_->tocs_) { @@ -179,6 +180,7 @@ context (context& c) link_regex (c.link_regex), id_set (c.id_set), ref_set (c.ref_set), + heading_map (c.heading_map), toc (c.toc), tocs (c.tocs) { @@ -1798,6 +1800,11 @@ format (semantics::scope& scope, string const& s, bool para) } } + // Save the heading number for later. + // + if (!n.empty ()) + heading_map[pi] = n; + v += in + "<tr><th>" + n + "</th><td>" + pv; // No newline tocs.push_back (toc_entry (t)); break; @@ -1915,7 +1922,19 @@ format (semantics::scope& scope, string const& s, bool para) if (!pi.empty ()) v += " id=\"" + pi + '"'; if (!c.empty ()) v += " class=\"" + c + '"'; v += '>'; + + // See if we have a heading number (assigned by TOC). + // + if (!pi.empty ()) + { + heading_map_type::const_iterator i (heading_map.find (pi)); + + if (i != heading_map.end ()) + v += i->second + ' '; + } + v += pv; + v += "</" + h + '>'; // @@ This only works for a single string fragment. @@ -2099,6 +2118,7 @@ verify_id_ref () id_set.clear (); ref_set.clear (); + heading_map.clear (); } string context:: diff --git a/cli/context.hxx b/cli/context.hxx index c67cec5..cd83421 100644 --- a/cli/context.hxx +++ b/cli/context.hxx @@ -103,6 +103,10 @@ public: id_set_type& id_set; id_set_type& ref_set; + // Map of heading ids to heading number (assigned during TOC generation) + // + typedef std::map<string, string> heading_map_type; + heading_map_type& heading_map; // TOC phase. // @@ -133,6 +137,7 @@ private: regex_mapping link_regex_; id_set_type id_set_; id_set_type ref_set_; + heading_map_type heading_map_; unsigned short toc_; toc_stack tocs_; }; diff --git a/tests/toc/toc.html b/tests/toc/toc.html index 5ff1670..2874edc 100644 --- a/tests/toc/toc.html +++ b/tests/toc/toc.html @@ -48,41 +48,41 @@ with Clang</a></td></tr> <p>Start of part one.</p> - <h1 id="intro">Introduction</h1> + <h1 id="intro">1 Introduction</h1> <p>Beginning of the first chapter.</p> - <h2 id="arch-flow">Architecture and Workflow</h2> + <h2 id="arch-flow">1.1 Architecture and Workflow</h2> <p>Some basics.</p> - <h2 id="benefits">Benefits</h2> + <h2 id="benefits">1.2 Benefits</h2> <p>You will like them.</p> - <h1 id="hello">Hello World</h1> + <h1 id="hello">2 Hello World</h1> <p>Beginning of the second chapter.</p> - <h2 id="hell-setup">Setup</h2> + <h2 id="hell-setup">2.1 Setup</h2> <p>More basics.</p> - <h2 id="hello-compile">Compiling</h2> + <h2 id="hello-compile">2.2 Compiling</h2> <p>How to build the example</p> - <h3 id="hello-compile-gcc">Compiling with GCC</h3> + <h3 id="hello-compile-gcc">2.2.1 Compiling with GCC</h3> <p>GCC. For Clang see <a href="#hello-compile-clang">Compiling with Clang</a>.</p> - <h3 id="hello-compile-clang">Compiling with Clang</h3> + <h3 id="hello-compile-clang">2.2.2 Compiling with Clang</h3> <p>Clang. For GCC see <a href="#hello-compile-gcc">Compiling with GCC</a>.</p> - <h2 id="hello-conclusion">Conclusion</h2> + <h2 id="hello-conclusion">2.3 Conclusion</h2> <p>Some remarks.</p> |