ZIP Output: Fix an error when building the ToC on macOS for some books with non-ASCII ToC entries

Fixes #1813905 [ebook convert successfully in GUI but failed in command line](https://bugs.launchpad.net/calibre/+bug/1813905) [ebook convert successfully in GUI but failed in command line](https://bugs.launchpad.net/calibre/+bug/1813905)
This commit is contained in:
Kovid Goyal 2019-01-30 15:52:39 +05:30
parent 4590d36660
commit 9ef0060c33
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -49,6 +49,7 @@ class HTMLOutput(OutputFormatPlugin):
from urllib import unquote from urllib import unquote
from calibre.ebooks.oeb.base import element from calibre.ebooks.oeb.base import element
from calibre.utils.cleantext import clean_xml_chars
with CurrentDir(output_dir): with CurrentDir(output_dir):
def build_node(current_node, parent=None): def build_node(current_node, parent=None):
if parent is None: if parent is None:
@ -58,11 +59,15 @@ class HTMLOutput(OutputFormatPlugin):
for node in current_node.nodes: for node in current_node.nodes:
point = element(parent, 'li') point = element(parent, 'li')
href = relpath(abspath(unquote(node.href)), dirname(ref_url)) href = relpath(abspath(unquote(node.href)), dirname(ref_url))
link = element(point, 'a', href=href) if isinstance(href, bytes):
href = href.decode('utf-8')
link = element(point, 'a', href=clean_xml_chars(href))
title = node.title title = node.title
if isinstance(title, bytes):
title = title.decode('utf-8')
if title: if title:
title = re.sub(r'\s+', ' ', title) title = re.sub(r'\s+', ' ', title)
link.text=title link.text = clean_xml_chars(title)
build_node(node, point) build_node(node, point)
return parent return parent
wrap = etree.Element('div') wrap = etree.Element('div')