question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NavigationItem.Link.ContentFileName is returning incorrectly

See original GitHub issue

Description

The library is returning the wrong text for ContentFileName. In the case for this epub, it should return “Text/chapter01.xhtml” while it is returning “Text/…/Text/chapter01.xhml”. I’m not sure where the extra relative path is coming from, given it’s not in the XML.

Epub structure: image

Code:

var navItems = await book.GetNavigationAsync();
foreach (var navigationItem in navItems)
            {
                if (navigationItem.NestedItems.Count > 0)
                {
                   var nestedChapters = new List<BookChapterItem>();

                    foreach (var nestedChapter in navigationItem.NestedItems)
                    {
                        if (nestedChapter.Link == null) continue;

                        // BUG: nestedChapter.Link.ContentFileName -> Is returning "/Text/../Text/chapter01.xhtml" when it should be "Text/chapter01.xhtml"
                        var key = BookService.CleanContentKeys(nestedChapter.Link.ContentFileName);
                        if (mappings.ContainsKey(key))
                        {
                            nestedChapters.Add(new BookChapterItem()
                            {
                                Title = nestedChapter.Title,
                                Page = mappings[key],
                                Part = nestedChapter.Link.Anchor ?? string.Empty,
                                Children = new List<BookChapterItem>()
                            });
                        }
                    }

                    CreateToCChapter(navigationItem, nestedChapters, chaptersList, mappings);
                }

Toc.ncx:

<navPoint id="navPoint5">
      <navLabel>
        <text>Day 0: Backstory and the Bridal Wars</text>
      </navLabel>
      <content src="Text/chapter1.xhtml"/>
    </navPoint>
    <navPoint id="navPoint6">
      <navLabel>
        <text>Day 1, Morning: The Start of a Slow Life</text>
      </navLabel>
      <content src="Text/chapter2.xhtml"/>
    </navPoint>

Manifest:

<manifest>
    <item id="cover" href="Text/cover.xhtml" media-type="application/xhtml+xml"/>
    <item id="frontmatter1.xhtml" href="Text/frontmatter1.xhtml" media-type="application/xhtml+xml"/>
    <item id="frontmatter2.xhtml" href="Text/frontmatter2.xhtml" media-type="application/xhtml+xml"/>
    <item id="toc.xhtml" href="Text/toc.xhtml" media-type="application/xhtml+xml" properties="nav"/>
    <item id="prologue.xhtml" href="Text/prologue.xhtml" media-type="application/xhtml+xml"/>
    <item id="prologue2.xhtml" href="Text/prologue2.xhtml" media-type="application/xhtml+xml"/>
    <item id="insert1.xhtml" href="Text/insert1.xhtml" media-type="application/xhtml+xml"/>
    <item id="prologue2_1.xhtml" href="Text/prologue2_1.xhtml" media-type="application/xhtml+xml"/>
    <item id="chapter1.xhtml" href="Text/chapter1.xhtml" media-type="application/xhtml+xml"/>
    ...

Sample EPUB file

The file is under copyright

Additional context

This is a EPUB 2 document and I have tested on v3.1.1, v3.1.0 and it is not working.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
majora2007commented, Jun 23, 2022

I have validated it is working. Thanks again.

1reaction
vers-onecommented, Jun 23, 2022

No worries, let me publish it to Nuget then.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PDFKit | Apple Developer Forums
(During practical scenario, I can't use PDFView object, I have to use custom UIView and it will be needed support other customize operation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found