From e46982c485512fd506d4254e6560bc94704f042f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 5 May 2009 14:01:18 -0700 Subject: [PATCH] MOBI Input: Fix conversion of MOBI files that do not have opening tags in their markup --- src/calibre/ebooks/mobi/reader.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/calibre/ebooks/mobi/reader.py b/src/calibre/ebooks/mobi/reader.py index 5010e9e8e8..ff398ca3bb 100644 --- a/src/calibre/ebooks/mobi/reader.py +++ b/src/calibre/ebooks/mobi/reader.py @@ -305,6 +305,15 @@ class MobiReader(object): self.log.warning('Markup contains unclosed

tags, parsing using', 'BeatifulSoup') root = soupparser.fromstring(self.processed_html) + if root[0].tag != 'html': + self.log.warn('File does not have opening tag') + nroot = html.fromstring('') + bod = nroot.find('body') + for child in list(root): + child.getparent().remove(child) + bod.append(child) + root = nroot + self.upshift_markup(root) guides = root.xpath('//guide') guide = guides[0] if guides else None