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

Slashes in TOC file paths are converted to backslashes in EpubNav (on Windows) #284

Open
LunarTulip opened this issue Jul 2, 2023 · 3 comments

Comments

@LunarTulip
Copy link

LunarTulip commented Jul 2, 2023

On my Windows machine—I imagine the same wouldn't happen on Linux-likes, although I haven't tested to confirm—the EpubNav's file paths contain backslashes in place of any forward slashes that might have been present in the file paths.

So, for example, if I run the following bit of code:

from ebooklib import epub
book = epub.EpubBook()
item = epub.EpubHtml(uid="chapter", file_name="text/content.xhtml", media_type="application/xhtml+xml", content="""<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Sample</title></head><body><p>Sample paragraph.</p></body></html>""")
book.add_item(item)
book.toc = [item]
book.add_item(epub.EpubNcx())
book.add_item(epub.EpubNav())
book.spine = ["nav", "chapter"]
epub.write_epub("sample.epub", book)

...the output EPUB file's nav.xhtml's link to the chapter will be this:

<li>
  <a href="text\content.xhtml">Sample</a>
</li>

...which you'll note features a backslash, unlike the originally-specified file path and unlike the (correct) rendition within the same file's toc.ncx:

<navPoint id="chapter">
  <navLabel>
    <text>Sample</text>
  </navLabel>
  <content src="text/content.xhtml"/>
</navPoint>

This is a problem, because the EPUB specification explicitly forbids backslashes in file paths and any readers exposed to files with navs generated in this fashion will as such potentially throw errors over the invalid paths.

@c1924959470
Copy link

c1924959470 commented Jul 2, 2023 via email

@clach04
Copy link
Contributor

clach04 commented Jul 29, 2023

#267 may fix this

@aerkalov
Copy link
Owner

I have deployed the changes to the master branch. Tested it with a sample file on windows and seems to be working. Will check some other PR and see when to do proper release.

For now just download source and install locally from master until the release is here.

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

No branches or pull requests

4 participants