MOBI metadata: Replace HTML entities in the title read from the MOBI file

This commit is contained in:
Kovid Goyal 2010-07-17 18:06:03 -06:00
parent 9825a47254
commit a1cf7ebe59
2 changed files with 6 additions and 2 deletions

View File

@ -440,6 +440,9 @@ xml_entity_to_unicode = partial(entity_to_unicode, result_exceptions = {
'>' : '>', '>' : '>',
'&' : '&'}) '&' : '&'})
def replace_entities(raw):
return _ent_pat.sub(entity_to_unicode, raw)
def prepare_string_for_xml(raw, attribute=False): def prepare_string_for_xml(raw, attribute=False):
raw = _ent_pat.sub(entity_to_unicode, raw) raw = _ent_pat.sub(entity_to_unicode, raw)
raw = raw.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;') raw = raw.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;')

View File

@ -14,7 +14,8 @@ except ImportError:
from lxml import html, etree from lxml import html, etree
from calibre import xml_entity_to_unicode, CurrentDir, entity_to_unicode from calibre import xml_entity_to_unicode, CurrentDir, entity_to_unicode, \
replace_entities
from calibre.utils.filenames import ascii_filename from calibre.utils.filenames import ascii_filename
from calibre.utils.date import parse_date from calibre.utils.date import parse_date
from calibre.ptempfile import TemporaryDirectory from calibre.ptempfile import TemporaryDirectory
@ -70,7 +71,7 @@ class EXTHHeader(object):
#else: #else:
# print 'unknown record', id, repr(content) # print 'unknown record', id, repr(content)
if title: if title:
self.mi.title = title self.mi.title = replace_entities(title)
def process_metadata(self, id, content, codec): def process_metadata(self, id, content, codec):
if id == 100: if id == 100: