Skip to content

EPUB3 nav.xhtml: If <h1> exists inside <nav>, Kavita only shows first-level TOC (children hidden) #4414

@DreamAvalon

Description

@DreamAvalon

What happened?

When an EPUB3 nav.xhtml Table of Contents contains a heading element (e.g., <h1>), Kavita incorrectly treats the heading as the TOC root node.
As a result, only one top-level entry is displayed, and nested TOC items (children) are not shown.

This breaks valid EPUB3 navigation documents, because headings inside <nav epub:type="toc"> are allowed by the spec.

Example

<nav epub:type="toc" id="toc">
  <h1>Table of Contents</h1>
  <ol>
    <li>
      <a href="chapter1.xhtml">Chapter 1</a>
      <ol>
        <li><a href="chapter1_1.xhtml">Chapter 1.1</a></li>
        <li><a href="chapter1_2.xhtml">Chapter 1.2</a></li>
      </ol>
    </li>
  </ol>
</nav>

Only the first-level TOC entry (Chapter 1) is displayed.

Child items (Chapter 1.1, Chapter 1.2) are hidden.

In table-of-contents.component.ts, the method isDisplayingChildrenOnly() uses:

return this.chapters().length === 1;
  • Heading tags (h1, h2) inside nav.xhtml are treated as the TOC root node.
  • chapters().length becomes 1 due to the artificial root, causing the UI to hide nested items.

Replace chapters().length with displayedChapters().length:

- return this.chapters().length === 1;
+ return this.displayedChapters().length === 1;

Affects EPUB3 files from common tools (Calibre, Sigil, etc.) that include headings inside nav.xhtml.

Prevents multi-level TOC from displaying correctly in Kavita.

What did you expect?

Nested TOC items should display normally.

Kavita Version Number - If you don't see your version number listed, please update Kavita and see if your issue still persists.

0.8.9.1 - Stable

Are you accessing kavita through a reverse proxy? If yes, confirm that the issue persists with a direct connection

Yes

What operating system is Kavita being hosted from?

Docker (Dockerhub Container)

If the issue is being seen on Desktop, what OS are you running where you see the issue?

Windows

If the issue is being seen in the UI, what browsers are you seeing the problem on?

Chrome

If the issue is being seen on Mobile, what OS are you running where you see the issue?

iOS

If the issue is being seen on the Mobile UI, what browsers are you seeing the problem on?

Safari

Relevant log output

Additional Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageNeeds to be triaged by a developer and assigned a release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions