Fix a couple of bugs when beautifying files before comparing

This commit is contained in:
Kovid Goyal 2022-02-02 08:32:29 +05:30
parent cceb052cb3
commit 46b550af59
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -48,7 +48,10 @@ def beautify_text(raw, syntax):
from calibre.ebooks.oeb.polish.parsing import parse
from calibre.ebooks.oeb.polish.pretty import pretty_html_tree, pretty_xml_tree
if syntax == 'xml':
try:
root = safe_xml_fromstring(strip_encoding_declarations(raw))
except etree.XMLSyntaxError:
return raw
pretty_xml_tree(root)
elif syntax == 'css':
import logging
@ -63,7 +66,7 @@ def beautify_text(raw, syntax):
# We dont care about @import rules
fetcher=lambda x: (None, None), log=_css_logger)
data = parser.parseString(raw, href='<string>', validate=False)
return serialize(data, 'text/css')
return serialize(data, 'text/css').decode('utf-8')
else:
root = parse(raw, line_numbers=False)
pretty_html_tree(None, root)