From 4e1e5d9a86ac22533ee950b50f1cfd8f9b0ccd58 Mon Sep 17 00:00:00 2001 From: John Schember Date: Mon, 14 Oct 2013 20:11:20 -0400 Subject: [PATCH 1/3] Fix issue #1239527: Htmlz inline css doesn't single quote fonts & thus destroys html. --- src/calibre/ebooks/htmlz/oeb2html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/ebooks/htmlz/oeb2html.py b/src/calibre/ebooks/htmlz/oeb2html.py index b162d9e19c..820f6e5839 100644 --- a/src/calibre/ebooks/htmlz/oeb2html.py +++ b/src/calibre/ebooks/htmlz/oeb2html.py @@ -267,7 +267,7 @@ class OEB2HTMLInlineCSSizer(OEB2HTML): # Turn style into strings for putting in the tag. style_t = '' if style_a: - style_t = ' style="%s"' % style_a + style_t = ' style="%s"' % style_a.replace('"', "'") # Write the tag. text.append('<%s%s%s>' % (tag, at, style_t)) From 219f4c632fbf98f8b337068af1e3f195797ac728 Mon Sep 17 00:00:00 2001 From: John Schember Date: Mon, 14 Oct 2013 20:13:14 -0400 Subject: [PATCH 2/3] Fix issue #1239530: Htmlz conversion places in , not before. --- src/calibre/ebooks/htmlz/oeb2html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/ebooks/htmlz/oeb2html.py b/src/calibre/ebooks/htmlz/oeb2html.py index 820f6e5839..e9ebd676a0 100644 --- a/src/calibre/ebooks/htmlz/oeb2html.py +++ b/src/calibre/ebooks/htmlz/oeb2html.py @@ -49,7 +49,7 @@ class OEB2HTML(object): return self.mlize_spine(oeb_book) def mlize_spine(self, oeb_book): - output = [u''] + output = [u''] for item in oeb_book.spine: self.log.debug('Converting %s to HTML...' % item.href) self.rewrite_ids(item.data, item) From 8b9f5bfe85543fea34a935a1e347a400b29560aa Mon Sep 17 00:00:00 2001 From: John Schember Date: Mon, 14 Oct 2013 20:22:37 -0400 Subject: [PATCH 3/3] Fix issue #1239555: Htmlz conversion incorrectly handles
. --- src/calibre/ebooks/htmlz/oeb2html.py | 39 +++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/htmlz/oeb2html.py b/src/calibre/ebooks/htmlz/oeb2html.py index e9ebd676a0..2130b95fb8 100644 --- a/src/calibre/ebooks/htmlz/oeb2html.py +++ b/src/calibre/ebooks/htmlz/oeb2html.py @@ -22,6 +22,18 @@ from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace,\ from calibre.ebooks.oeb.stylizer import Stylizer from calibre.utils.logging import default_log +SELF_CLOSING_TAGS = [ + 'area', + 'base', + 'basefont', + 'br', + 'hr', + 'input', + 'img', + 'link', + 'meta' +] + class OEB2HTML(object): ''' 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)) # 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. if style['font-weight'] in ('bold', 'bolder'): @@ -210,7 +226,8 @@ class OEB2HTMLNoCSSizer(OEB2HTML): # Close all open tags. tags.reverse() for t in tags: - text.append('' % t) + if t not in SELF_CLOSING_TAGS: + text.append('' % t) # Add the text that is outside of the tag. if hasattr(elem, 'tail') and elem.tail: @@ -270,7 +287,11 @@ class OEB2HTMLInlineCSSizer(OEB2HTML): style_t = ' style="%s"' % style_a.replace('"', "'") # 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. if hasattr(elem, 'text') and elem.text: @@ -283,7 +304,8 @@ class OEB2HTMLInlineCSSizer(OEB2HTML): # Close all open tags. tags.reverse() for t in tags: - text.append('' % t) + if t not in SELF_CLOSING_TAGS: + text.append('' % t) # Add the text that is outside of the tag. 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)) # 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. if hasattr(elem, 'text') and elem.text: @@ -363,7 +389,8 @@ class OEB2HTMLClassCSSizer(OEB2HTML): # Close all open tags. tags.reverse() for t in tags: - text.append('' % t) + if t not in SELF_CLOSING_TAGS: + text.append('' % t) # Add the text that is outside of the tag. if hasattr(elem, 'tail') and elem.tail: