diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index 5df3970577..11a718886f 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -57,18 +57,18 @@ class FB2MLizer(object): output += self.fb2mlize_images() output += self.fb2_footer() output = self.clean_text(output) - return etree.tostring(etree.fromstring(output), encoding=unicode, pretty_print=True) + return u'\n%s' % etree.tostring(etree.fromstring(output), encoding=unicode, pretty_print=True) def fb2_header(self): return u' ' \ - '%s ' \ + 'xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">\n' \ + '\n%s ' \ ' ' \ - '%s - %s ' \ - '
' % (self.oeb_book.metadata.title[0].value, __appname__, __version__) + '%s - %s\n' \ + '\n\n
' % (self.oeb_book.metadata.title[0].value, __appname__, __version__) def fb2_body_footer(self): - return u'
' + return u'\n
\n' def fb2_footer(self): return u'
' @@ -77,8 +77,17 @@ class FB2MLizer(object): images = u'' for item in self.oeb_book.manifest: if item.media_type in OEB_IMAGES: - data = b64encode(item.data) - images += '%s' % (os.path.basename(item.href), item.media_type, data) + raw_data = b64encode(item.data) + # Don't put the encoded image on a single line. + data = '' + col = 1 + for char in raw_data: + if col == 72: + data += '\n' + col = 1 + col += 1 + data += char + images += '%s\n' % (os.path.basename(item.href), item.media_type, data) return images def clean_text(self, text): @@ -102,7 +111,7 @@ class FB2MLizer(object): tag_count = 0 if tag == 'img': - fb2_text += '' % os.path.basename(elem.attrib['src']) + fb2_text += '' % os.path.basename(elem.attrib['src']) fb2_tag = TAG_MAP.get(tag, None)