HTMLZ Output: Fix special chars like ampersands, etc. not being converted to entities

This commit is contained in:
Kovid Goyal 2011-08-28 08:24:33 -06:00
commit 676dead1d3

View File

@ -127,6 +127,14 @@ class OEB2HTML(object):
break break
return css return css
def prepare_string_for_html(self, raw):
raw = prepare_string_for_xml(raw)
raw = raw.replace(u'\u00ad', '­')
raw = raw.replace(u'\u2014', '—')
raw = raw.replace(u'\u2013', '–')
raw = raw.replace(u'\u00a0', ' ')
return raw
class OEB2HTMLNoCSSizer(OEB2HTML): class OEB2HTMLNoCSSizer(OEB2HTML):
''' '''
@ -194,7 +202,7 @@ class OEB2HTMLNoCSSizer(OEB2HTML):
# Process tags that contain text. # Process tags that contain text.
if hasattr(elem, 'text') and elem.text: if hasattr(elem, 'text') and elem.text:
text.append(elem.text) text.append(self.prepare_string_for_html(elem.text))
# Recurse down into tags within the tag we are in. # Recurse down into tags within the tag we are in.
for item in elem: for item in elem:
@ -207,7 +215,7 @@ class OEB2HTMLNoCSSizer(OEB2HTML):
# 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:
text.append(elem.tail) text.append(self.prepare_string_for_html(elem.tail))
return text return text
@ -267,7 +275,7 @@ class OEB2HTMLInlineCSSizer(OEB2HTML):
# Process tags that contain text. # Process tags that contain text.
if hasattr(elem, 'text') and elem.text: if hasattr(elem, 'text') and elem.text:
text.append(elem.text) text.append(self.prepare_string_for_html(elem.text))
# Recurse down into tags within the tag we are in. # Recurse down into tags within the tag we are in.
for item in elem: for item in elem:
@ -280,7 +288,7 @@ class OEB2HTMLInlineCSSizer(OEB2HTML):
# 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:
text.append(elem.tail) text.append(self.prepare_string_for_html(elem.tail))
return text return text
@ -347,7 +355,7 @@ class OEB2HTMLClassCSSizer(OEB2HTML):
# Process tags that contain text. # Process tags that contain text.
if hasattr(elem, 'text') and elem.text: if hasattr(elem, 'text') and elem.text:
text.append(elem.text) text.append(self.prepare_string_for_html(elem.text))
# Recurse down into tags within the tag we are in. # Recurse down into tags within the tag we are in.
for item in elem: for item in elem:
@ -360,7 +368,7 @@ class OEB2HTMLClassCSSizer(OEB2HTML):
# 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:
text.append(elem.tail) text.append(self.prepare_string_for_html(elem.tail))
return text return text