Quote:
Originally Posted by DiapDealer
The problem is that Sigil already does the exact reverse of what you want. The title attribute of an h tag (if present) is used by Sigil to generate the text of the ToC. That's what allows users to generate ToCs that have different text than what's between the h tags.
|
Yes, my point exactly.

That is precisely what makes me think it should be possible to add a variation of that feature.
When the TOC is made, Sigil already knows what each TOC entry should say and what part of the document it is linked to (whether it harvested the info from title attributes or otherwise). It can assemble this info into a new file (nav.xhtml and toc.ncx). It puts it together using appropriate tags.
From there, it should be possible to ask it to redistribute the same elements in the opposite direction: the nav is the source of the information rather than the destination and each title is copied back to its destination. Sigil will either have a toc id there, or an h* (with or without a title=""), or nothing if the link just goes to the file. If there is already a title="" overwriting it could be useful if you've made some changes directly in the nav. If there is no title, it can be added.
If you are worried about potential conflict with existing code, rather than asking it to add this to a title="" it can be added as an html comment or some other code that seems appropriate to you; maybe something like <section title="Text of title" /> or <a title="Text of title" /> or anything else. From there it would be fairly trivial to regex the text into a title="" and be able to easily regenerate the TOC as needed.
Obviously this would be a separate feature to generating the toc even if it's closely related, just like there is a separate "epub3 tools" menu to generate the ncx from the nav, and it wouldn't be necessary for every book, but it would be useful in a lot of cases, and when it's useful it's REALLY useful. I frequently have requests to modify files made by someone else, for example the cases I mentioned above or things like adding a preview of the next book at the end of a book that's already published or a new introduction or something like that. This almost always requires some intervention in the TOC and I have never once seen a book that wasn't my own that made it easy to modify the TOC.
Quote:
Originally Posted by Turtle91
Unfortunately there are so many different examples of how people do them badly...it would be very difficult to encompass all cases. I usually just use regex.
|
Ah, so you also have dealt with this mess. Yes, I use regex too, but it can be really time consuming because of all the variations and ultimately it's always necessary to do some of it by hand. Wouldn't it be nice if you could just grab all the correct titles from the toc and turn them into references and then just click "Generate TOC", instead of messing about with regex?