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

Fix: Some readers cannot click on links containing backslashes (\) #267

Closed
wants to merge 1 commit into from
Closed

Fix: Some readers cannot click on links containing backslashes (\) #267

wants to merge 1 commit into from

Conversation

lemisky
Copy link

@lemisky lemisky commented Nov 10, 2022

Reader

https://www.wps.cn/

or

https://www.wps.com/

Before repair

image

After repair

image

@lemisky
Copy link
Author

lemisky commented Nov 24, 2022

@aerkalov hello

@aerkalov
Copy link
Owner

What would be the code example you are using? I am curious what kind of names are you giving to the chapters?

I am asking because I don't think it is so much the issue of the library but rather of how you use it. Unicode characters, space and all other kind of characters should not be used for the file names inside of EPUB, just because some readers do not support it. I would say without really knowing how are you creating the EPUB.

@lemisky
Copy link
Author

lemisky commented Nov 28, 2022

@aerkalov Hi author, sorry for forgetting to provide a code sample

This is a meaningless example, purely for demonstration

from ebooklib import epub

if __name__ == '__main__':
    epubook = epub.EpubBook()
    for i in range(1, 10):
        i = f'{i}' * i
        item = epub.EpubHtml(
            title=f'{i}', file_name=f'Text/{i}.xhtml',
            content=f'<h1>{i}</h1><p>{i}</p>'.encode('utf8')
        )
        epubook.add_item(item)
        epubook.spine.append(item)
        epubook.toc.append(epub.Link(item.file_name, item.title, item.file_name))

    nav = epub.EpubNav(file_name='nav.xhtml')
    epubook.add_item(nav)
    epubook.spine.insert(0, nav)
    epubook.toc.insert(0, epub.Link(nav.file_name, 'nav_title', 'content'))

    epubook.add_item(epub.EpubNcx())
    epub.write_epub('1.epub', epubook)

The resulting epub file

The resulting epub file 1.zip

image

@lemisky
Copy link
Author

lemisky commented Nov 28, 2022

But with this pr, everything will be normal

image

@topkie
Copy link

topkie commented Mar 20, 2023

I also had this problem because on Windows, os.path.relpath returns the path separator as \ instead of /

ERROR(RSC-020): G://comics//1.epub/EPUB/nav.xhtml(12,42): "text\chapter-1.xhtml" is not a valid URL (Backslash ("\") used as path segment delimiter)

@clach04
Copy link
Contributor

clach04 commented Jul 29, 2023

Also fixes #284 ?

@clach04
Copy link
Contributor

clach04 commented Jul 29, 2023

@aerkalov Hi author, sorry for forgetting to provide a code sample

This is a meaningless example, purely for demonstration

from ebooklib import epub

if __name__ == '__main__':
    epubook = epub.EpubBook()
    for i in range(1, 10):
        i = f'{i}' * i
        item = epub.EpubHtml(
            title=f'{i}', file_name=f'Text/{i}.xhtml',
            content=f'<h1>{i}</h1><p>{i}</p>'.encode('utf8')
        )
        epubook.add_item(item)
        epubook.spine.append(item)
        epubook.toc.append(epub.Link(item.file_name, item.title, item.file_name))

    nav = epub.EpubNav(file_name='nav.xhtml')
    epubook.add_item(nav)
    epubook.spine.insert(0, nav)
    epubook.toc.insert(0, epub.Link(nav.file_name, 'nav_title', 'content'))

    epubook.add_item(epub.EpubNcx())
    epub.write_epub('1.epub', epubook)

The resulting epub file

The resulting epub file 1.zip

image

Presumably this was ran on windows to generate the test book?

@aerkalov
Copy link
Owner

Thanks for this and I am not sure how I managed to miss the original post. Closing this and deploying the change which uses posixpath module rather than replace string.

@aerkalov aerkalov closed this Jul 30, 2023
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.

4 participants