mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: Check Book: Add a check for nav documents that contain no ToC in EPUB 3 books
This commit is contained in:
parent
1145607df4
commit
3a22851b83
@ -10,7 +10,7 @@ from lxml import etree
|
||||
|
||||
from calibre import prepare_string_for_xml as xml
|
||||
from calibre.ebooks.oeb.polish.check.base import BaseError, WARN
|
||||
from calibre.ebooks.oeb.polish.toc import find_existing_nav_toc
|
||||
from calibre.ebooks.oeb.polish.toc import find_existing_nav_toc, parse_nav
|
||||
from calibre.ebooks.oeb.polish.utils import guess_type
|
||||
from calibre.ebooks.oeb.base import OPF, OPF2_NS, DC, DC11_NS, XHTML_MIME
|
||||
|
||||
@ -119,6 +119,16 @@ class MissingNav(BaseError):
|
||||
BaseError.__init__(self, _('Missing navigation document'), name, lnum)
|
||||
|
||||
|
||||
class EmptyNav(BaseError):
|
||||
|
||||
HELP = _('The nav document for this book contains no table of contents, or an empty table of contents.'
|
||||
' Use the Table of Contents tool to add a Table of Contents to this book.')
|
||||
LEVEL = WARN
|
||||
|
||||
def __init__(self, name, lnum):
|
||||
BaseError.__init__(self, _('Missing ToC in navigation document'), name, lnum)
|
||||
|
||||
|
||||
class MissingHref(BaseError):
|
||||
|
||||
HELP = _('A file listed in the manifest is missing, you should either remove'
|
||||
@ -333,8 +343,13 @@ def check_opf(container):
|
||||
errors.append(MissingNCXRef(container.opf_name, spine.sourceline, ncx_id))
|
||||
|
||||
if opf_version.major > 2:
|
||||
if find_existing_nav_toc(container) is None:
|
||||
existing_nav = find_existing_nav_toc(container)
|
||||
if existing_nav is None:
|
||||
errors.append(MissingNav(container.opf_name, 0))
|
||||
else:
|
||||
toc = parse_nav(container, existing_nav)
|
||||
if len(toc) == 0:
|
||||
errors.append(EmptyNav(existing_nav, 0))
|
||||
|
||||
covers = container.opf_xpath('/opf:package/opf:metadata/opf:meta[@name="cover"]')
|
||||
if len(covers) > 0:
|
||||
|
Loading…
x
Reference in New Issue
Block a user