mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #2652 (NotHTML: File 'foo.htm' does not appear to be (X)HTML)
This commit is contained in:
parent
d1dadc3402
commit
fb2296beb2
@ -759,7 +759,9 @@ class Manifest(object):
|
||||
# Convert to Unicode and normalize line endings
|
||||
data = self.oeb.decode(data)
|
||||
data = self.oeb.html_preprocessor(data)
|
||||
orig_data = data
|
||||
# Try with more & more drastic measures to parse
|
||||
def first_pass(data):
|
||||
try:
|
||||
data = etree.fromstring(data)
|
||||
except etree.XMLSyntaxError:
|
||||
@ -768,7 +770,6 @@ class Manifest(object):
|
||||
try:
|
||||
data = etree.fromstring(data)
|
||||
except etree.XMLSyntaxError:
|
||||
# TODO: Factor out HTML->XML coercion
|
||||
self.oeb.logger.warn('Parsing file %r as HTML' % self.href)
|
||||
data = html.fromstring(data)
|
||||
data.attrib.pop('xmlns', None)
|
||||
@ -780,7 +781,11 @@ class Manifest(object):
|
||||
data = etree.fromstring(data)
|
||||
except etree.XMLSyntaxError:
|
||||
data = etree.fromstring(data, parser=RECOVER_PARSER)
|
||||
return data
|
||||
data = first_pass(data)
|
||||
# Force into the XHTML namespace
|
||||
if barename(data.tag) != 'html':
|
||||
data = first_pass('<html>'+data+'</html>')
|
||||
if barename(data.tag) != 'html':
|
||||
raise NotHTML(
|
||||
'File %r does not appear to be (X)HTML' % self.href)
|
||||
|
Loading…
x
Reference in New Issue
Block a user