mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Edit Book: Check Book: Add a check for manifest items missing href attributes. Fixes #1339766 [Validator gives error on “href” attribute in manifest item for remote resources](https://bugs.launchpad.net/calibre/+bug/1339766)
This commit is contained in:
parent
54f774c375
commit
9c8357c31b
@ -62,6 +62,25 @@ class IncorrectToc(BaseError):
|
||||
self.HELP = _('The media type for the table of contents must be %s') % guess_type('a.ncx')
|
||||
BaseError.__init__(self, msg, name, lnum)
|
||||
|
||||
class NoHref(BaseError):
|
||||
|
||||
HELP = _('This manifest entry has no href attribute. Either add the href attribute or remove the entry.')
|
||||
INDIVIDUAL_FIX = _('Remove this manifest entry')
|
||||
|
||||
def __init__(self, name, item_id, lnum):
|
||||
BaseError.__init__(self, _('Item in manifest has no href attribute'), name, lnum)
|
||||
self.item_id = item_id
|
||||
|
||||
def __call__(self, container):
|
||||
changed = False
|
||||
for item in container.opf_xpath('/opf:package/opf:manifest/opf:item'):
|
||||
if item.get('id', None) == self.item_id:
|
||||
changed = True
|
||||
container.remove_from_xml(item)
|
||||
container.dirty(container.opf_name)
|
||||
return changed
|
||||
|
||||
|
||||
class MissingHref(BaseError):
|
||||
|
||||
HELP = _('A file listed in the manifest is missing, you should either remove'
|
||||
@ -213,8 +232,11 @@ def check_opf(container):
|
||||
errors.append(NonLinearItems(container.opf_name, nl_items))
|
||||
|
||||
seen, dups = {}, {}
|
||||
for item in container.opf_xpath('/opf:package/opf:manifest/opf:item[@href]'):
|
||||
href = item.get('href')
|
||||
for item in container.opf_xpath('/opf:package/opf:manifest/opf:item'):
|
||||
href = item.get('href', None)
|
||||
if href is None:
|
||||
errors.append(NoHref(container.opf_name, item.get('id', None), item.sourceline))
|
||||
else:
|
||||
hname = container.href_to_name(href, container.opf_name)
|
||||
if not hname or not container.exists(hname):
|
||||
errors.append(MissingHref(container.opf_name, href, item.sourceline))
|
||||
|
Loading…
x
Reference in New Issue
Block a user