From 88159288a87d5e408932edae232378c077739753 Mon Sep 17 00:00:00 2001 From: Andrey Efremov Date: Sun, 6 Oct 2019 13:07:17 +0700 Subject: [PATCH] FB2 Output: Remove extra line breaks and prettify XML markup --- src/calibre/ebooks/fb2/fb2ml.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index 3a191cd54e..91d05f0140 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -78,7 +78,7 @@ class FB2MLizer(object): # Clean up pargraph endings. text = re.sub(r'(?miu)\s*

', '

', text) # Put paragraphs following a paragraph on a separate line. - text = re.sub(r'(?miu)

\s*

', '

\n\n

', text) + text = re.sub(r'(?miu)

\s*

', '

\n

', text) # Remove empty title elements. text = re.sub(r'(?miu)\s*', '', text) @@ -88,11 +88,11 @@ class FB2MLizer(object): text = re.sub(r'(?miu)

\s*
', '', text) # Clean up sections start and ends. text = re.sub(r'(?miu)\s*', '\n', text) - text = re.sub(r'(?miu)\s*', '\n\n', text) + text = re.sub(r'(?miu)\s*', '\n', text) text = re.sub(r'(?miu)\s*
', '\n
', text) text = re.sub(r'(?miu)
\s*', '
\n', text) # Put sectnions followed by sections on a separate line. - text = re.sub(r'(?miu)
\s*
', '
\n\n
', text) + text = re.sub(r'(?miu)
\s*
', '
\n
', text) if self.opts.insert_blank_line: text = re.sub(r'(?miu)

', '

', text) @@ -223,7 +223,7 @@ class FB2MLizer(object): \n''') % metadata def fb2_footer(self): - return '\n' + return '' def get_cover(self): from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES @@ -291,7 +291,8 @@ class FB2MLizer(object): text.append('
') self.section_level -= 1 - return ''.join(text) + '' + text.append('') + return ''.join(text) + '\n' def fb2mlize_images(self): ''' @@ -316,11 +317,11 @@ class FB2MLizer(object): # Don't put the encoded image on a single line. step = 72 data = '\n'.join(raw_data[i:i+step] for i in range(0, len(raw_data), step)) - images.append('%s\n' % (self.image_hrefs[item.href], content_type, data)) + images.append('%s' % (self.image_hrefs[item.href], content_type, data)) except Exception as e: self.log.error('Error: Could not include file %s because ' '%s.' % (item.href, e)) - return ''.join(images) + return '\n'.join(images) + '\n' def create_flat_toc(self, nodes, level): for item in nodes: