View Single Post
Old 05-27-2008, 11:38 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 25,374
Karma: 4961459
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
The simplest way to manually create a TOC is just add a section like

Code:
<ul>
<li><a href="#chapter1">Chapter One</a></li>
<li><a href="#chapter2">Chapter Two</a></li>
.
.
.
</ul>
Near the top of the HTML file where you want the TOC to appear. You also have to identify the actual chapter titles in the text like this

Code:
<h2 id="chapter1">Chapter One</h2>
You can of course use any text not necessarily Chapter One

Note that you can manually force a page break before any HTML element by adding style="page-break-before: always" to the HTML tag

Code:
<p style="page-break-before: always">Some paragraph...</p>
So to consolidate, your HTML file should look like this:

Code:
<h1>Book Title</h1>
...
<h2>Table of Contents</h2>

<ul>
<li><a href="#chapter1">Chapter One</a></li>
<li><a href="#chapter2">Chapter Two</a></li>
.
.
.
</ul>

<h2 style="page-break-before: always" id="chapter1">Chapter One</h2>
.
.
.

<h2 style="page-break-before: always" id="chapter2">Chapter Two</h2>
.
.
.
There is an example here http://calibre.kovidgoyal.net/downloads/html-demo.zip
kovidgoyal is offline   Reply With Quote