Fix fb2 output.

This commit is contained in:
John Schember 2009-06-06 18:41:59 -04:00
parent 7b121a42e3
commit ee29a571f4

View File

@ -24,7 +24,7 @@ TAG_MAP = {
'b' : 'strong', 'b' : 'strong',
'i' : 'emphasis', 'i' : 'emphasis',
'p' : 'p', 'p' : 'p',
'div' : 'p', 'li' : 'p'
} }
STYLES = [ STYLES = [
@ -109,12 +109,13 @@ class FB2MLizer(object):
fb2_text += '<image xlink:herf="#%s" />' % os.path.basename(elem.attrib['src']) fb2_text += '<image xlink:herf="#%s" />' % os.path.basename(elem.attrib['src'])
fb2_tag = TAG_MAP.get(tag, 'p') fb2_tag = TAG_MAP.get(tag, None)
if fb2_tag and fb2_tag not in tag_stack: if fb2_tag and fb2_tag not in tag_stack:
tag_count += 1 tag_count += 1
fb2_text += '<%s>' % fb2_tag fb2_text += '<%s>' % fb2_tag
tag_stack.append(fb2_tag) tag_stack.append(fb2_tag)
# Processes style information # Processes style information
for s in STYLES: for s in STYLES:
style_tag = s[1].get(style[s[0]], None) style_tag = s[1].get(style[s[0]], None)
@ -132,7 +133,6 @@ class FB2MLizer(object):
close_tag_list = [] close_tag_list = []
for i in range(0, tag_count): for i in range(0, tag_count):
close_tag_list.insert(0, tag_stack.pop()) close_tag_list.insert(0, tag_stack.pop())
fb2_text += self.close_tags(close_tag_list) fb2_text += self.close_tags(close_tag_list)
if hasattr(elem, 'tail') and elem.tail != None and elem.tail.strip() != '': if hasattr(elem, 'tail') and elem.tail != None and elem.tail.strip() != '':
@ -150,4 +150,3 @@ class FB2MLizer(object):
fb2_text += '</%s>' % fb2_tag fb2_text += '</%s>' % fb2_tag
return fb2_text return fb2_text