summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-02-11 06:14:17 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-02-11 06:14:17 +0200
commitcd73ee1fe287ca77b44370760d72f7eb145f096e (patch)
tree4dbaaf0a6fbbcb22c65b0f838e03b0aa54f528e1
parent01314f53987e57c4fcb49fb86d3971bdb206857f (diff)
Implement links in TOC
-rw-r--r--cli/context.cxx8
-rw-r--r--tests/toc/toc.html30
2 files changed, 25 insertions, 13 deletions
diff --git a/cli/context.cxx b/cli/context.cxx
index b923c4b..cd5d88c 100644
--- a/cli/context.cxx
+++ b/cli/context.cxx
@@ -1696,6 +1696,14 @@ format (semantics::scope& scope, string const& s, bool para)
{
char t (ph[0]);
+ if (pi.empty ())
+ {
+ cerr << "error: TOC heading '" << pv << "' has no id" << endl;
+ throw generation_failed ();
+ }
+
+ pv = "<a href=\"#" + pi + "\">" + pv + "</a>";
+
// Unwind heading levels that are deeper ("more sub") than us.
//
for (; tocs.size () != 1; tocs.pop_back ())
diff --git a/tests/toc/toc.html b/tests/toc/toc.html
index 7da2f0c..5ff1670 100644
--- a/tests/toc/toc.html
+++ b/tests/toc/toc.html
@@ -1,29 +1,33 @@
<h1>Table of Contents</h1>
<table class="toc">
- <tr><th></th><td>Preface
+ <tr><th></th><td><a href="#preface">Preface</a>
<table class="toc">
- <tr><th></th><td>About This Document</td></tr>
- <tr><th></th><td>More Information</td></tr>
+ <tr><th></th><td><a href="#about-document">About This
+Document</a></td></tr>
+ <tr><th></th><td><a href="#more-information">More Information</a></td></tr>
</table>
</td></tr>
- <tr><th colspan="2">PART I</th></tr>
- <tr><th>1</th><td>Introduction
+ <tr><th colspan="2"><a href="#part1">PART I</a></th></tr>
+ <tr><th>1</th><td><a href="#intro">Introduction</a>
<table class="toc">
- <tr><th>1.1</th><td>Architecture and Workflow</td></tr>
- <tr><th>1.2</th><td>Benefits</td></tr>
+ <tr><th>1.1</th><td><a href="#arch-flow">Architecture and
+Workflow</a></td></tr>
+ <tr><th>1.2</th><td><a href="#benefits">Benefits</a></td></tr>
</table>
</td></tr>
- <tr><th>2</th><td>Hello World
+ <tr><th>2</th><td><a href="#hello">Hello World</a>
<table class="toc">
- <tr><th>2.1</th><td>Setup</td></tr>
- <tr><th>2.2</th><td>Compiling
+ <tr><th>2.1</th><td><a href="#hell-setup">Setup</a></td></tr>
+ <tr><th>2.2</th><td><a href="#hello-compile">Compiling</a>
<table class="toc">
- <tr><th>2.2.1</th><td>Compiling with GCC</td></tr>
- <tr><th>2.2.2</th><td>Compiling with Clang</td></tr>
+ <tr><th>2.2.1</th><td><a href="#hello-compile-gcc">Compiling with
+GCC</a></td></tr>
+ <tr><th>2.2.2</th><td><a href="#hello-compile-clang">Compiling
+with Clang</a></td></tr>
</table>
</td></tr>
- <tr><th>2.3</th><td>Conclusion</td></tr>
+ <tr><th>2.3</th><td><a href="#hello-conclusion">Conclusion</a></td></tr>
</table>
</td></tr>
</table>