Skip to content

use ncx file path as base path for toc#60

Merged
danigm merged 2 commits intodanigm:masterfrom
twilight-flower:fix-ncx-src-base
Jan 23, 2026
Merged

use ncx file path as base path for toc#60
danigm merged 2 commits intodanigm:masterfrom
twilight-flower:fix-ncx-src-base

Conversation

@twilight-flower
Copy link
Copy Markdown
Contributor

Currently, when filling the TOC, this crate uses the EPUB's base path (derived from the OPF's path) to determine the paths of items in the TOC. This works fine when the NCX file is in the same directory as the OPF; but it leads to incorrect TOC-paths when the NCX is in a different directory than the OPF. For example, this IDPF sample EPUB has its NCX in a subfolder relative to the OPF, and accordingly this crate misparses its sole TOC-item's path as EPUB/../Content/pageNum-9.svg when it should properly be EPUB/Navigation/../Content/pageNum-9.svg.

This PR, then, is a fix for that misparsing. It updates the crate to fill TOC items' paths based on the NCX's base path, rather than the OPF's.

(Even more ideally, we might want to factor out ..-like elements and have it parse as EPUB/Content/pageNum-9.svg. But that's currently harder to implement, since Path::normalize_lexically hasn't yet made it out of nightly; thus I restrained this PR to just the more basic fix.)

Copy link
Copy Markdown
Owner

@danigm danigm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread src/doc.rs Outdated
Copy link
Copy Markdown
Owner

@danigm danigm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now looks better, we can merge it

@danigm danigm merged commit 9ddc39d into danigm:master Jan 23, 2026
6 checks passed
@twilight-flower twilight-flower deleted the fix-ncx-src-base branch January 23, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants