Fix issue #1239555: Htmlz conversion incorrectly handles <br/>.

This commit is contained in:
John Schember 2013-10-14 20:22:37 -04:00
parent 219f4c632f
commit 8b9f5bfe85

View File

@ -22,6 +22,18 @@ from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace,\
from calibre.ebooks.oeb.stylizer import Stylizer from calibre.ebooks.oeb.stylizer import Stylizer
from calibre.utils.logging import default_log from calibre.utils.logging import default_log
SELF_CLOSING_TAGS = [
'area',
'base',
'basefont',
'br',
'hr',
'input',
'img',
'link',
'meta'
]
class OEB2HTML(object): class OEB2HTML(object):
''' '''
Base class. All subclasses should implement dump_text to actually transform Base class. All subclasses should implement dump_text to actually transform
@ -183,7 +195,11 @@ class OEB2HTMLNoCSSizer(OEB2HTML):
at += ' %s="%s"' % (k, prepare_string_for_xml(v, attribute=True)) at += ' %s="%s"' % (k, prepare_string_for_xml(v, attribute=True))
# Write the tag. # Write the tag.
text.append('<%s%s>' % (tag, at)) text.append('<%s%s' % (tag, at))
if tag in SELF_CLOSING_TAGS:
text.append(' />')
else:
text.append('>')
# Turn styles into tags. # Turn styles into tags.
if style['font-weight'] in ('bold', 'bolder'): if style['font-weight'] in ('bold', 'bolder'):
@ -210,6 +226,7 @@ class OEB2HTMLNoCSSizer(OEB2HTML):
# Close all open tags. # Close all open tags.
tags.reverse() tags.reverse()
for t in tags: for t in tags:
if t not in SELF_CLOSING_TAGS:
text.append('</%s>' % t) text.append('</%s>' % t)
# Add the text that is outside of the tag. # Add the text that is outside of the tag.
@ -270,7 +287,11 @@ class OEB2HTMLInlineCSSizer(OEB2HTML):
style_t = ' style="%s"' % style_a.replace('"', "'") style_t = ' style="%s"' % style_a.replace('"', "'")
# Write the tag. # Write the tag.
text.append('<%s%s%s>' % (tag, at, style_t)) text.append('<%s%s%s' % (tag, at, style_t))
if tag in SELF_CLOSING_TAGS:
text.append(' />')
else:
text.append('>')
# Process tags that contain text. # Process tags that contain text.
if hasattr(elem, 'text') and elem.text: if hasattr(elem, 'text') and elem.text:
@ -283,6 +304,7 @@ class OEB2HTMLInlineCSSizer(OEB2HTML):
# Close all open tags. # Close all open tags.
tags.reverse() tags.reverse()
for t in tags: for t in tags:
if t not in SELF_CLOSING_TAGS:
text.append('</%s>' % t) text.append('</%s>' % t)
# Add the text that is outside of the tag. # Add the text that is outside of the tag.
@ -350,7 +372,11 @@ class OEB2HTMLClassCSSizer(OEB2HTML):
at += ' %s="%s"' % (k, prepare_string_for_xml(v, attribute=True)) at += ' %s="%s"' % (k, prepare_string_for_xml(v, attribute=True))
# Write the tag. # Write the tag.
text.append('<%s%s>' % (tag, at)) text.append('<%s%s' % (tag, at))
if tag in SELF_CLOSING_TAGS:
text.append(' />')
else:
text.append('>')
# Process tags that contain text. # Process tags that contain text.
if hasattr(elem, 'text') and elem.text: if hasattr(elem, 'text') and elem.text:
@ -363,6 +389,7 @@ class OEB2HTMLClassCSSizer(OEB2HTML):
# Close all open tags. # Close all open tags.
tags.reverse() tags.reverse()
for t in tags: for t in tags:
if t not in SELF_CLOSING_TAGS:
text.append('</%s>' % t) text.append('</%s>' % t)
# Add the text that is outside of the tag. # Add the text that is outside of the tag.