View Full Version : What does the filepos parameter do in an href?


lunixer
08-06-2011, 09:23 PM
I found a few books in my library in which the TOC (table of contents) is off by exactly one chapter in every selection, so I am manually going through using Sigil and adjusting the TOC so that it is correct. However, this always leaves exactly one link at the end of the TOC which I have to create manually, as there is no other chapter that is incorrectly associated with this link.

For example, in Book A the TOC might look like this
Chapter 1
Chapter 2
Chapter 3

The chapter 2 link points to chapter 1, the chapter 1 link points nowhere, and the chapter 3 link points to chapter 2. I can move the first two links, but I have to make a link to point to chapter 3.

When I do this I simply take something from another chapter, such as:


<p class="calibre2"><a class="calibre3" href="../Text/Last_Argument_Of_Kings_split_062.html#filepos15838 84"><span class="bold calibre4 underline">The Beginning</span></a></p><br class="calibre5" />


and adjust the split and filepos number. However, I am confused because it seems no matter what number I put in the filepos, it makes no difference to the book, both when I read it through Calibre/Sigil or on my K3. What exactly does this number do? Obviously the split number chooses which file in the book to look at, but I can't figure out the filepos. Thanks!

charleski
08-06-2011, 09:35 PM
The 'filepos' is just an example of a fragment identifier. It needs to start with a letter and can't include certain characters, but it's really just a marker that identifies a specific place in a file. The target of the link needs to have an identifier with the same text.

i.e. File1.xhtml:
<p><a href="File2.xhtml#Target">Click here</a></p>

File2.xhtml:
<p id="Target">This is where you end up</p>

You probably don't see any difference in this case because the targets in the table of contents they all point to are all elements on the same displayed page.

lunixer
08-07-2011, 12:45 AM
The 'filepos' is just an example of a fragment identifier. It needs to start with a letter and can't include certain characters, but it's really just a marker that identifies a specific place in a file. The target of the link needs to have an identifier with the same text.

i.e. File1.xhtml:
<p><a href="File2.xhtml#Target">Click here</a></p>

File2.xhtml:
<p id="Target">This is where you end up</p>

You probably don't see any difference in this case because the targets in the table of contents they all point to are all elements on the same displayed page.

Thanks for the help! I've got a few more questions if you don't mind.

1) I'm not quite sure what you mean by "all elements on the same displayed page." The page with the inline TOC or the page that I am linking to?

I went back through and checked it out and it seems that you are correct. In the links that I did not make in the TOC, the place where it links to has an ID that matches the filepos tag in the TOC. Of course the tags I made don't match, since I picked the numbers at random.

2) Could it be because they always link to the top of a page? (That is, in the books I am working with the chapter breaks are always a new split_## file.)

3) But anyway, if the books work fine I shouldn't have any problem, correct?

4) If they are built this way, is the filepos even necessary or could the links just be done by identifying a file without a target?

5) Would there be problems with other file formats (eg mobi, pdb) if it was done that way?

Also, while I have your attention, I've noticed that in a number of the files in my library, the entire inline TOC is off by exactly one chapter. Is there anything that you can think of that could cause this? You seem pretty knowledgeable about this stuff. It's just odd because the books come from multiple publishers, are converted using the same settings in Calibre, and I always have to go through and do the exact same thing, manually moving the chapters. It just seems a little odd.

Thanks for the help!

charleski
08-07-2011, 06:00 AM
If you have a page with the following items
<p id="t1">...</p>
<p id="t2">...</p>
<p id="t3">...</p>
<p id="t4">...</p>
Then a link to any of those targets will produce the same displayed page. This may change if you increase the font size so much that the later elements get shuffled off onto the next page or if the ToC is long enough to stretch over several pages. The use of a fragment merely ensures that the result of a link will display the page in the file that contains the target to which it refers. If you omit the fragment identifier then the link will always point to the first page in the file.

I don't know why you're having this problem, but it sounds like a problem with the settings you use for conversion, or maybe a bug in calibre.

Jellby
08-07-2011, 07:19 AM
If you have a page with the following items
<p id="t1">...</p>
<p id="t2">...</p>
<p id="t3">...</p>
<p id="t4">...</p>
Then a link to any of those targets will produce the same displayed page.

That is so in the ADE implementation, where the "pages" are sort of pre-computed, but there are conceivably other ePUB readers that will place the target always on top of the page, or in the middle of the page... so the displayed page could be different.