mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
FB2 Output: Proper join of XML parts
This commit is contained in:
parent
62757eadff
commit
58352097ad
@ -59,16 +59,18 @@ class FB2MLizer(object):
|
|||||||
return self.fb2mlize_spine()
|
return self.fb2mlize_spine()
|
||||||
|
|
||||||
def fb2mlize_spine(self):
|
def fb2mlize_spine(self):
|
||||||
output = [self.fb2_header()]
|
output = (
|
||||||
output.append(self.get_text())
|
self.fb2_header(),
|
||||||
output.append(self.fb2mlize_images())
|
self.get_text(),
|
||||||
output.append(self.fb2_footer())
|
self.fb2mlize_images(),
|
||||||
output = self.clean_text(''.join(output))
|
self.fb2_footer(),
|
||||||
|
)
|
||||||
|
output = self.clean_text('\n'.join(output))
|
||||||
|
|
||||||
if self.opts.pretty_print:
|
if self.opts.pretty_print:
|
||||||
return '<?xml version="1.0" encoding="UTF-8"?>\n%s' % etree.tostring(etree.fromstring(output), encoding='unicode', pretty_print=True)
|
output = etree.tostring(etree.fromstring(output), encoding='unicode', pretty_print=True)
|
||||||
else:
|
|
||||||
return '<?xml version="1.0" encoding="UTF-8"?>' + output
|
return '<?xml version="1.0" encoding="UTF-8"?>\n' + output
|
||||||
|
|
||||||
def clean_text(self, text):
|
def clean_text(self, text):
|
||||||
# Condense empty paragraphs into a line break.
|
# Condense empty paragraphs into a line break.
|
||||||
@ -223,7 +225,7 @@ class FB2MLizer(object):
|
|||||||
</description>''') % metadata
|
</description>''') % metadata
|
||||||
|
|
||||||
# Remove empty lines.
|
# Remove empty lines.
|
||||||
return '\n'.join(filter(unicode_type.strip, header.splitlines())) + '\n'
|
return '\n'.join(filter(unicode_type.strip, header.splitlines()))
|
||||||
|
|
||||||
def fb2_footer(self):
|
def fb2_footer(self):
|
||||||
return '</FictionBook>'
|
return '</FictionBook>'
|
||||||
@ -295,7 +297,7 @@ class FB2MLizer(object):
|
|||||||
self.section_level -= 1
|
self.section_level -= 1
|
||||||
|
|
||||||
text.append('</body>')
|
text.append('</body>')
|
||||||
return ''.join(text) + '\n'
|
return ''.join(text)
|
||||||
|
|
||||||
def fb2mlize_images(self):
|
def fb2mlize_images(self):
|
||||||
'''
|
'''
|
||||||
@ -324,7 +326,7 @@ class FB2MLizer(object):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.log.error('Error: Could not include file %s because '
|
self.log.error('Error: Could not include file %s because '
|
||||||
'%s.' % (item.href, e))
|
'%s.' % (item.href, e))
|
||||||
return '\n'.join(images) + '\n'
|
return '\n'.join(images)
|
||||||
|
|
||||||
def create_flat_toc(self, nodes, level):
|
def create_flat_toc(self, nodes, level):
|
||||||
for item in nodes:
|
for item in nodes:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user