Sunday, August 7, 2011

A Tale of Three (Mobi) Table of Contents

‹prev | My Chain | next›

Today, I am going to attempt an alternate git-scribe strategy for generating the mobi version of The SPDY Book.

I would like "real" footnotes like:
Google web browsers run 
<span class="emphasis"><em>significantly</em></span> 
faster with Google web sites 
<sup>[<a id="id395636" href="#ftn.id395636" class="footnote">7</a>]</sup>.
Which point to footnotes at the end of chapters:
<div class="footnotes">
<div class="footnote">...</div>
<div class="footnote">
[<a id="ftn.id395636" href="#id395636" class="simpara">7</a>] 
Google would, of course, claim that Google browsers run faster
against all sites ;-)
But what my current strategy has been producing is this inline mess:
<div class="paragraph">
Google web browsers run <em>significantly</em> faster with Google
web sites 
<span class="footnote">
<br />
[Google would, of course, claim that Google browsers run faster
against all sites ;-)]
<br />
So, instead of using ascidoc directly to generate the HTML for the mobi version of the book, I will use the a2x helper command that comes with asciidoc. The results are very similar, but I have been seeing good results with a2x and epub formats.

So I replace:
asciidoc -a stylesdir=#{styledir} -a theme=scribe #{BOOK_FILE}
a2x -f xhtml -d book--stylesheet=stylesheets/scribe.css -a docinfo -v #{BOOK_FILE}
With that, I find that I have my nice footnotes. I do a little CSS cleanup and I am almost 100% satisfied with with the mobi version of The SPDY Book. Except...

Except for the Table of Contents. There is actually a fairly decent, inline, TOC right at the beginning of the book:

Sure, the formatting could be better, but the chapters are all correct and even the indenting is correct. That's nice.

But if I look at what Calibre thinks is the TOC, I see:

OK. That's not too bad. All of the chapters are still correct. There is no indenting, but I can live with that.

Unfortunately, at the very of the file, I find yet another TOC. And this one is a beast:

Bleargh. The stinkin' Copyright is listed as "Chapter 1"? What's that all about? And why are there three?

Unfortunately, the last one is the one used by the Kindle as the real TOC. It is the toc.html file generated by git-scribe. Part of this is due to my mucking with the asciidoc command and the rest is just how I formatted The SPDY Book (with H2s as the Copyright). I think my way is correct, but obviously it needs work.

The second one, the version is flat but still correct, is also generated by git-scribe, but without attempting to infer chapter numbers. This is the NCX (Navigation Control file for XML applications) file that the Kindle uses to put the little chapter marks in the progress meter at the bottom of the display. This is actually perfect as-is. The marks do show up on the Kindle and the actual structure and contents are unused (as far as I can tell).

I will pick back up with this tomorrow. I think that I will try to pull the "good" TOC out of the HTML and use that at the TOC for the book. I will then see if the NCX can be rearranged a bit.

Day #106

No comments:

Post a Comment