From b1ee6be7465b639d174c97b0eb500b85a79a1d7d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 1 May 2018 14:49:18 +0530 Subject: [PATCH] Edit Book: Fix an error caused by a landmark entry in EPUB 3 files that has an tag without an href attribute. --- src/calibre/ebooks/oeb/polish/toc.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/toc.py b/src/calibre/ebooks/oeb/polish/toc.py index 2bdc2e1ccc..242b7d307d 100644 --- a/src/calibre/ebooks/oeb/polish/toc.py +++ b/src/calibre/ebooks/oeb/polish/toc.py @@ -310,12 +310,13 @@ def get_nav_landmarks(container): for li in elem.iterdescendants(XHTML('li')): for a in li.iterdescendants(XHTML('a')): href, rtype = a.get('href'), a.get(et) - title = etree.tostring(a, method='text', encoding=unicode, with_tail=False).strip() - href, frag = href.partition('#')[::2] - name = container.href_to_name(href, nav) - if container.has_name(name): - yield {'dest':name, 'frag':frag, 'title':title or '', 'type':rtype or ''} - break + if href: + title = etree.tostring(a, method='text', encoding=unicode, with_tail=False).strip() + href, frag = href.partition('#')[::2] + name = container.href_to_name(href, nav) + if container.has_name(name): + yield {'dest':name, 'frag':frag, 'title':title or '', 'type':rtype or ''} + break def get_landmarks(container):