Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please help, how to get chapter title (navLabel) by spineIdref? #186

Open
hz0324 opened this issue Dec 19, 2017 · 5 comments
Open

Please help, how to get chapter title (navLabel) by spineIdref? #186

hz0324 opened this issue Dec 19, 2017 · 5 comments

Comments

@hz0324
Copy link

hz0324 commented Dec 19, 2017

I want to know the chapter title for certain spineIdref, but I don't know how to get it.

I have managed to use the following method to get book TOC information:

tim 20171219143537

tim 20171219143815

But I cannot find the relation between spineIdref and title text as shown in the toc.ncx file:
tim 20171219143348

Please help, I don't know which method should be used for this purpose.
In fact, what I need is something like this:
{
spineIdref:'id1',
href:'balblablbal',
title:'chapter 1',
spineIndex:2
}

Thank you very much.

BTW, if this is impossible using current API, how I can get access to the toc.ncx content so that I can parse it by myself? Thanks

@hz0324 hz0324 changed the title Please help, how to get chapter title by spineIdref? Please help, how to get chapter title (navLabel) by spineIdref? Dec 19, 2017
@danielweck
Copy link
Member

I like your idea, but I think that the table of content provided by NCX and/or EPUB3 NavDoc doesn't necessarily give spine-level titles (instead: heading labels), so this does not seem deterministic-enough to allow for a reliable implementation within Readium's core parser.
Am I missing something?

@hz0324
Copy link
Author

hz0324 commented Dec 19, 2017

@danielweck well, too bad to hear that.

I think I may find a way to work around.
Since I have known the relationship between text and href from the generateTocDom().
I just need to get the relationship between href and idref. Then I can get a roughly accurate relationship between idref and chapter title text.

Thanks for your reply, appreciate it a lot.

@hz0324
Copy link
Author

hz0324 commented Dec 19, 2017

@danielweck sorry to disturb you again.

Is there a way to get spine items list before loading a document?
Now I can only get spineItem list inside the document loading callbacks.

Thanks.

@danielweck
Copy link
Member

danielweck commented Dec 19, 2017

Technically-speaking, I agree that we can establish accurate "relationships" by cross-referencing the TOC and the OPF spine (parsing href, idref, etc.).

What I meant was - let's say you have the following OPF spine:

  • spine-item-A.html
  • spine-item-B.html
    and the following TOC:
  • spine-item-A.html#section1 "heading 1"
    • spine-item-A.html#section1.1 "heading 1.1"
  • spine-item-A.html#section2 "heading 2"
  • spine-item-B.html#section1 "other heading 1"
  • spine-item-B.html#section2 "other heading 2"

As you can see, the notion of "title" for a given spine item does not necessarily exist, so I don't think you can reliably extract this information from the TOC. In fact the <head><title /> element inside each HTML document is probably a more authoritative source of information, but I have seen many documents with placeholder text, and some without anything at all.

That being said, the TOC of some ebooks do indeed contain a unique textual label (aka "title") for each spine item, so there are definitely cases where this would work :)

@hz0324
Copy link
Author

hz0324 commented Dec 19, 2017

Thank you for the information.

I agree that this is not a reliable approach, but with some exception handling, this could work just fine for common usage.

As for <title> inside Header, I have also seen many books didn't define it correctly. Maybe it can be used as an alternative.

Thank you very much for the help.
^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants