From f9df174fd9b6bb8f89e33fc2d70c6ec0dbe59cb3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 5 May 2009 14:00:12 -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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/calibre/ebooks/mobi/reader.py b/src/calibre/ebooks/mobi/reader.py index fa1c0fc0d8..44d3fbd9f7 100644 --- a/src/calibre/ebooks/mobi/reader.py +++ b/src/calibre/ebooks/mobi/reader.py @@ -296,6 +296,14 @@ class MobiReader(object): from lxml.html import soupparser print 'Markup contains unclosed

tags, parsing using BeatifulSoup' root = soupparser.fromstring(self.processed_html) + if root[0].tag != 'html': + 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