From 96ff207be28274ae59aa67e941c7a6a261ae0c47 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 11 Feb 2016 07:45:21 +0200 Subject: Assign numbers to TOC headings --- cli/context.cxx | 20 ++++++++++++++++++++ cli/context.hxx | 5 +++++ 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 + "" + n + "" + 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 += "'; // @@ 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 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

Start of part one.

-

Introduction

+

1 Introduction

Beginning of the first chapter.

-

Architecture and Workflow

+

1.1 Architecture and Workflow

Some basics.

-

Benefits

+

1.2 Benefits

You will like them.

-

Hello World

+

2 Hello World

Beginning of the second chapter.

-

Setup

+

2.1 Setup

More basics.

-

Compiling

+

2.2 Compiling

How to build the example

-

Compiling with GCC

+

2.2.1 Compiling with GCC

GCC. For Clang see Compiling with Clang.

-

Compiling with Clang

+

2.2.2 Compiling with Clang

Clang. For GCC see Compiling with GCC.

-

Conclusion

+

2.3 Conclusion

Some remarks.

-- cgit v1.1