diff --git a/src/calibre/ebooks/mobi/writer.py b/src/calibre/ebooks/mobi/writer.py index 62d444ee95..d9f3a841ab 100644 --- a/src/calibre/ebooks/mobi/writer.py +++ b/src/calibre/ebooks/mobi/writer.py @@ -180,7 +180,6 @@ class Serializer(object): if not isinstance(elem.tag, basestring) \ or namespace(elem.tag) not in nsrmap: return - hrefs = self.oeb.manifest.hrefs tag = prefixname(elem.tag, nsrmap) for attr in ('name', 'id'): if attr in elem.attrib: @@ -203,7 +202,7 @@ class Serializer(object): continue elif attr == 'src': href = item.abshref(val) - if href in hrefs: + if href in self.images: index = self.images[href] buffer.write('recindex="%05d"' % index) continue diff --git a/src/calibre/ebooks/oeb/transforms/trimmanifest.py b/src/calibre/ebooks/oeb/transforms/trimmanifest.py index bd2c388245..b150a12831 100644 --- a/src/calibre/ebooks/oeb/transforms/trimmanifest.py +++ b/src/calibre/ebooks/oeb/transforms/trimmanifest.py @@ -41,8 +41,9 @@ class ManifestTrimmer(object): while unchecked: new = set() for item in unchecked: - if item.media_type in OEB_DOCS or \ - item.media_type[-4:] in ('/xml', '+xml'): + if (item.media_type in OEB_DOCS or + item.media_type[-4:] in ('/xml', '+xml')) and \ + item.data is not None: hrefs = [sel(item.data) for sel in LINK_SELECTORS] for href in chain(*hrefs): href = item.abshref(href)