mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Check book: When fixing named entities, fix in all files not just current file.
This commit is contained in:
parent
e95c878293
commit
a309d3ba13
@ -19,7 +19,7 @@ from calibre.ebooks.oeb.polish.check.links import check_links, check_mimetypes
|
|||||||
from calibre.ebooks.oeb.polish.check.fonts import check_fonts
|
from calibre.ebooks.oeb.polish.check.fonts import check_fonts
|
||||||
from calibre.ebooks.oeb.polish.check.opf import check_opf
|
from calibre.ebooks.oeb.polish.check.opf import check_opf
|
||||||
|
|
||||||
XML_TYPES = frozenset(map(guess_type, ('a.xml', 'a.svg', 'a.opf', 'a.ncx')))
|
XML_TYPES = frozenset(map(guess_type, ('a.xml', 'a.svg', 'a.opf', 'a.ncx'))) | {'application/oebps-page-map+xml'}
|
||||||
|
|
||||||
def run_checks(container):
|
def run_checks(container):
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class HTMLParseError(XMLParseError):
|
|||||||
class NamedEntities(BaseError):
|
class NamedEntities(BaseError):
|
||||||
|
|
||||||
level = WARN
|
level = WARN
|
||||||
INDIVIDUAL_FIX = _('Replace all named entities with their character equivalents in this file')
|
INDIVIDUAL_FIX = _('Replace all named entities with their character equivalents in this book')
|
||||||
HELP = _('Named entities are often only incompletely supported by various book reading software.'
|
HELP = _('Named entities are often only incompletely supported by various book reading software.'
|
||||||
' Therefore, it is best to not use them, replacing them with the actual characters they'
|
' Therefore, it is best to not use them, replacing them with the actual characters they'
|
||||||
' represent. This can be done automatically.')
|
' represent. This can be done automatically.')
|
||||||
@ -60,11 +60,18 @@ class NamedEntities(BaseError):
|
|||||||
BaseError.__init__(self, _('Named entities present'), name)
|
BaseError.__init__(self, _('Named entities present'), name)
|
||||||
|
|
||||||
def __call__(self, container):
|
def __call__(self, container):
|
||||||
raw = container.raw_data(self.name)
|
changed = False
|
||||||
nraw = replace_pat.sub(lambda m:html5_entities[m.group(1)], raw)
|
from calibre.ebooks.oeb.polish.check.main import XML_TYPES
|
||||||
with container.open(self.name, 'wb') as f:
|
check_types = XML_TYPES | OEB_DOCS
|
||||||
f.write(nraw.encode('utf-8'))
|
for name, mt in container.mime_map.iteritems():
|
||||||
return True
|
if mt in check_types:
|
||||||
|
raw = container.raw_data(name)
|
||||||
|
nraw = replace_pat.sub(lambda m:html5_entities[m.group(1)], raw)
|
||||||
|
if raw != nraw:
|
||||||
|
changed = True
|
||||||
|
with container.open(name, 'wb') as f:
|
||||||
|
f.write(nraw.encode('utf-8'))
|
||||||
|
return changed
|
||||||
|
|
||||||
class EscapedName(BaseError):
|
class EscapedName(BaseError):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user