From 62757eadffa79722aa1ddf78be95cfe1f0cec923 Mon Sep 17 00:00:00 2001 From: Andrey Efremov Date: Mon, 7 Oct 2019 12:22:07 +0700 Subject: [PATCH] FB2 Output: Remove empty lines from header --- src/calibre/ebooks/fb2/fb2ml.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index 55349cd426..13fbba976d 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -19,7 +19,7 @@ from calibre.constants import __appname__, __version__ from calibre.utils.localization import lang_as_iso639_1 from calibre.utils.img import save_cover_data_to from calibre.ebooks.oeb.base import urlnormalize -from polyglot.builtins import unicode_type, string_or_bytes, range +from polyglot.builtins import unicode_type, string_or_bytes, range, filter from polyglot.binary import as_base64_unicode @@ -195,12 +195,12 @@ class FB2MLizer(object): from calibre.utils.html2text import html2text metadata['comments'] = '{}'.format(prepare_string_for_xml(html2text(comments.value.strip()))) - return textwrap.dedent(''' + header = textwrap.dedent('''\ %(genre)s - %(author)s + %(author)s %(title)s %(cover)s %(lang)s @@ -220,7 +220,10 @@ class FB2MLizer(object): %(year)s %(isbn)s - \n''') % metadata + ''') % metadata + + # Remove empty lines. + return '\n'.join(filter(unicode_type.strip, header.splitlines())) + '\n' def fb2_footer(self): return ''