mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix issue #1239555: Htmlz conversion incorrectly handles <br/>.
This commit is contained in:
parent
219f4c632f
commit
8b9f5bfe85
@ -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,7 +226,8 @@ class OEB2HTMLNoCSSizer(OEB2HTML):
|
|||||||
# Close all open tags.
|
# Close all open tags.
|
||||||
tags.reverse()
|
tags.reverse()
|
||||||
for t in tags:
|
for t in tags:
|
||||||
text.append('</%s>' % t)
|
if t not in SELF_CLOSING_TAGS:
|
||||||
|
text.append('</%s>' % t)
|
||||||
|
|
||||||
# Add the text that is outside of the tag.
|
# Add the text that is outside of the tag.
|
||||||
if hasattr(elem, 'tail') and elem.tail:
|
if hasattr(elem, 'tail') and elem.tail:
|
||||||
@ -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,7 +304,8 @@ class OEB2HTMLInlineCSSizer(OEB2HTML):
|
|||||||
# Close all open tags.
|
# Close all open tags.
|
||||||
tags.reverse()
|
tags.reverse()
|
||||||
for t in tags:
|
for t in tags:
|
||||||
text.append('</%s>' % t)
|
if t not in SELF_CLOSING_TAGS:
|
||||||
|
text.append('</%s>' % t)
|
||||||
|
|
||||||
# Add the text that is outside of the tag.
|
# Add the text that is outside of the tag.
|
||||||
if hasattr(elem, 'tail') and elem.tail:
|
if hasattr(elem, 'tail') and elem.tail:
|
||||||
@ -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,7 +389,8 @@ class OEB2HTMLClassCSSizer(OEB2HTML):
|
|||||||
# Close all open tags.
|
# Close all open tags.
|
||||||
tags.reverse()
|
tags.reverse()
|
||||||
for t in tags:
|
for t in tags:
|
||||||
text.append('</%s>' % t)
|
if t not in SELF_CLOSING_TAGS:
|
||||||
|
text.append('</%s>' % t)
|
||||||
|
|
||||||
# Add the text that is outside of the tag.
|
# Add the text that is outside of the tag.
|
||||||
if hasattr(elem, 'tail') and elem.tail:
|
if hasattr(elem, 'tail') and elem.tail:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user