From dd12f725d5c9fb668ce91bce8997ee883c71a731 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 2 Aug 2009 14:14:14 -0400 Subject: [PATCH] Fix bug #3050: Prepare string for xml --- src/calibre/ebooks/fb2/fb2ml.py | 15 +++++---------- src/calibre/ebooks/rb/rbml.py | 5 +++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/calibre/ebooks/fb2/fb2ml.py b/src/calibre/ebooks/fb2/fb2ml.py index 11a718886f..2de2c599cf 100644 --- a/src/calibre/ebooks/fb2/fb2ml.py +++ b/src/calibre/ebooks/fb2/fb2ml.py @@ -13,10 +13,11 @@ from base64 import b64encode from lxml import etree +from calibre import prepare_string_for_xml +from calibre.constants import __appname__, __version__ from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace from calibre.ebooks.oeb.stylizer import Stylizer from calibre.ebooks.oeb.base import OEB_IMAGES -from calibre.constants import __appname__, __version__ TAG_MAP = { 'b' : 'strong', @@ -56,7 +57,6 @@ class FB2MLizer(object): output += self.fb2_body_footer() output += self.fb2mlize_images() output += self.fb2_footer() - output = self.clean_text(output) return u'\n%s' % etree.tostring(etree.fromstring(output), encoding=unicode, pretty_print=True) def fb2_header(self): @@ -90,11 +90,6 @@ class FB2MLizer(object): images += '%s\n' % (os.path.basename(item.href), item.media_type, data) return images - def clean_text(self, text): - text = text.replace('&', '') - - return text - def dump_text(self, elem, stylizer, tag_stack=[]): if not isinstance(elem.tag, basestring) \ or namespace(elem.tag) != XHTML_NS: @@ -130,7 +125,7 @@ class FB2MLizer(object): tag_stack.append(style_tag) if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '': - fb2_text += elem.text + fb2_text += prepare_string_for_xml(elem.text) for item in elem: fb2_text += self.dump_text(item, stylizer, tag_stack) @@ -142,9 +137,9 @@ class FB2MLizer(object): if hasattr(elem, 'tail') and elem.tail != None and elem.tail.strip() != '': if 'p' not in tag_stack: - fb2_text += '

%s

' % elem.tail + fb2_text += '

%s

' % prepare_string_for_xml(elem.tail) else: - fb2_text += elem.tail + fb2_text += prepare_string_for_xml(elem.tail) return fb2_text diff --git a/src/calibre/ebooks/rb/rbml.py b/src/calibre/ebooks/rb/rbml.py index bc9248f8b0..82f8a17281 100644 --- a/src/calibre/ebooks/rb/rbml.py +++ b/src/calibre/ebooks/rb/rbml.py @@ -11,6 +11,7 @@ Transform OEB content into RB compatible markup. import os import re +from calibre import prepare_string_for_xml from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace from calibre.ebooks.oeb.stylizer import Stylizer @@ -149,7 +150,7 @@ class RBMLizer(object): # Proccess tags that contain text. if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '': - text += elem.text + text += prepare_string_for_xml(elem.text) for item in elem: text += self.dump_text(item, stylizer, tag_stack) @@ -161,7 +162,7 @@ class RBMLizer(object): text += self.close_tags(close_tag_list) if hasattr(elem, 'tail') and elem.tail != None and elem.tail.strip() != '': - text += elem.tail + text += prepare_string_for_xml(elem.tail) return text