diff --git a/src/calibre/ebooks/conversion/plugins/htmlz_output.py b/src/calibre/ebooks/conversion/plugins/htmlz_output.py index ac7a6d4231..0f5d9b5333 100644 --- a/src/calibre/ebooks/conversion/plugins/htmlz_output.py +++ b/src/calibre/ebooks/conversion/plugins/htmlz_output.py @@ -89,7 +89,7 @@ class HTMLZOutput(OutputFormatPlugin): # CSS if opts.htmlz_css_type == 'class' and opts.htmlz_class_style == 'external': with open(os.path.join(tdir, u'style.css'), 'wb') as tf: - tf.write(htmlizer.get_css(oeb_book)) + tf.write(htmlizer.get_css(oeb_book).encode('utf-8')) # Images images = htmlizer.images diff --git a/src/calibre/ebooks/htmlz/oeb2html.py b/src/calibre/ebooks/htmlz/oeb2html.py index 0fcf6a67d4..0470109d6d 100644 --- a/src/calibre/ebooks/htmlz/oeb2html.py +++ b/src/calibre/ebooks/htmlz/oeb2html.py @@ -20,7 +20,7 @@ from calibre.ebooks.oeb.base import ( XHTML, XHTML_NS, SVG_NS, barename, namespace, OEB_IMAGES, XLINK, rewrite_links, urlnormalize) from calibre.ebooks.oeb.stylizer import Stylizer from calibre.utils.logging import default_log -from polyglot.builtins import unicode_type, string_or_bytes, as_bytes +from polyglot.builtins import unicode_type, string_or_bytes, as_unicode from polyglot.urllib import urldefrag SELF_CLOSING_TAGS = {'area', 'base', 'basefont', 'br', 'hr', 'input', 'img', 'link', 'meta'} @@ -131,10 +131,10 @@ class OEB2HTML(object): el.attrib['id'] = self.get_link_id(page.href, el.attrib['id'])[1:] def get_css(self, oeb_book): - css = b'' + css = '' for item in oeb_book.manifest: if item.media_type == 'text/css': - css += as_bytes(item.data.cssText) + b'\n\n' + css += as_unicode(item.data.cssText) + '\n\n' return css def prepare_string_for_html(self, raw): @@ -337,9 +337,9 @@ class OEB2HTMLClassCSSizer(OEB2HTML): output += self.dump_text(item.data.find(XHTML('body')), stylizer, item) output.append('\n\n') if self.opts.htmlz_class_style == 'external': - css = u'' + css = '' else: - css = u'' + css = '' title = u'%s' % prepare_string_for_xml(self.book_title) output = [u''] + \ [css] + [title, u''] + output + [u'']