From 9409781f4a4446078e2a1637d7b4303abdc81bff Mon Sep 17 00:00:00 2001 From: John Schember Date: Fri, 3 Dec 2010 19:43:50 -0500 Subject: [PATCH] FB2 Output: Insert empty lines properly. --- src/calibre/ebooks/fb2/fb2ml.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index e658dce25a..252453d25e 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -32,7 +32,6 @@ TAG_MAP = { 'p' : 'p', 'li' : 'p', 'div': 'p', - 'br' : 'empty-line', } TAG_SPACE = [] @@ -126,7 +125,7 @@ class FB2MLizer(object): '

' \ '' \ '' \ - '%s - %s' \ + '%s %s' \ '' \ '' % tuple(map(prepare_string_for_xml, (author_first, author_middle, author_last, self.oeb_book.metadata.title[0].value, __appname__, __version__))) @@ -180,6 +179,24 @@ class FB2MLizer(object): self.in_p = True return ['

'], ['p'] + def insert_empty_line(self, tags): + if self.in_p: + text = [''] + closed_tags = [] + tags.reverse() + for t in tags: + text.append('' % t) + closed_tags.append(t) + if t == 'p': + break + text.append('') + closed_tags.reverse() + for t in closed_tags: + text.append('<%s>' % t) + return text + else: + return [''] + def close_open_p(self, tags): text = [''] added_p = False @@ -230,6 +247,8 @@ class FB2MLizer(object): if tag == 'h1' and self.opts.h1_to_title or tag == 'h2' and self.opts.h2_to_title or tag == 'h3' and self.opts.h3_to_title: fb2_text.append('') tags.append('title') + if tag == 'br': + fb2_text += self.insert_empty_line(tag_stack+tags) fb2_tag = TAG_MAP.get(tag, None) if fb2_tag == 'p':