Building a navigation document from heading markup

3 posts / 0 new
Last post

Hi,

I'm still developping my EPUB editor (quite advanced now, I'm happy ^^) and I have again some technical questions for which I need your help. Those questions are related to the building of the table of contents.

Suppose that a user creates a publication with two chapters in the spine.

ch01.xhtml
ch02.xhtml

Each of those files contain some headings.

ch01.xhtml :
<h1 id="ch01_01">Heading 1</h1>
...
<h2 id="ch01_02"> Heading 2</h2>
...
<h2 id="ch01_03"> Heading 2</h2>
....

ch02.xhtml
<h1 id="ch02_01">Heading 1</h1>
...
<h2 id="ch02_02"> Heading 2</h2>
...
<h2 id="ch02_03"> Heading 2</h2>
....

Suppose that I want to generate a table of contents. I have few questions about it:

1) Should I generate this table from heading markup? It is the best way to generate a table of contents?

Some software (e.g. Sigil) generates table of contents from heading markups BUT do not use the markup of heading 1. For example, the content documents given above would give the following table of contents:

<nav epub:type="toc">
<ol>
<li><a href="ch01.xhtml">Heading 1</a>/<li>
<ol>
<li><a href="ch01.xhtml#ch01_02">Heading 2</a>/<li>
...
</ol>
</ol>

</nav>

Is there a right way to generate the table of contents?

2) Suppose there is no heading. Should I just generate a one-level toc, in which each entry corresponds to a file of the spine? In that case, what label should I generate by default? The name of the file?

So:

<nav epub:type="toc">
<li><a href="ch01.xhtml">WHAT LABEL?</a></li>
<li><a href="ch02.xhtml">WHAT LABEL?</a></li>
</nav>

3) The 'href' attribute of an entry should correspond to what kind of id in the content documents? Any id attribute or just id attribute of heading tags?

Thanks a lot.

From several arbitrary generated XHTML files within an EPUB, it is mainly guessing, what the intention of the author might be - typically true for guessing: It is often wrong ;o)
For SVG content documents it is even worse, SVG has no build in structure to construct a cascade of headings for a file, one needs to use structures from other namespaces.
EPUB has an element collection for the OPF-file, which can matter as well for the complete book, if used, it can give hints about splitted content.

I think in the HTML5 recommendation or at least in previous drafts of this, there is described
a method, how to generate automatically a TOC from the structured content, this happened,
because some new elements and new rules implicate a change of meaning of hX elements, some nesting implicates, that the old cascade known from HTML4 does not apply anymore.

In my PHP online generators for EPUB 2 and 3 books I use simply a form, authors have to mention how many chapters they want to have, for each chapter how many sections and what are the headings and the content for them. Obviously with this it is simple both to create the structure of the XHTML-content files, the XHTML-navigation file and the NCX-file automatically,
at least for simply books, most authors usually write. especially those with no knowledge about EPUB, XHTML, SVG etc.

Finally this means - if you want to get it right, ask the authors about their intentions or guide them to a meaningful structure by the design of you editor.

Thanks O.H.

I think I will build it from heading markups (in case of XHTML content document) and let the user the possibility to change it via an interface.

Secondary menu