Edit book: Spell check: Fix EPUB 3 nav document not being spell checked when not in the spine. Fixes #1942773 [[Enhancement] Spell check should cover nav.xhtml](https://bugs.launchpad.net/calibre/+bug/1942773)

This commit is contained in:
Kovid Goyal 2021-09-06 21:19:43 +05:30
parent 2dcc4fce2b
commit 44bf6e3859
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 14 additions and 10 deletions

View File

@ -264,24 +264,28 @@ def group_sort(locations):
def get_checkable_file_names(container): def get_checkable_file_names(container):
file_names = [name for name, linear in container.spine_names] + [container.opf_name] file_names = [name for name, linear in container.spine_names] + [container.opf_name]
for f in (find_existing_ncx_toc, find_existing_nav_toc): ncx_toc = find_existing_ncx_toc(container)
toc = f(container) if ncx_toc is not None and container.exists(ncx_toc) and ncx_toc not in file_names:
if toc is not None and container.exists(toc) and toc not in file_names: file_names.append(ncx_toc)
file_names.append(toc) else:
return file_names, toc ncx_toc = None
toc = find_existing_nav_toc(container)
if toc is not None and container.exists(toc) and toc not in file_names:
file_names.append(toc)
return file_names, ncx_toc
def get_all_words(container, book_locale, get_word_count=False): def get_all_words(container, book_locale, get_word_count=False):
words = defaultdict(list) words = defaultdict(list)
words[None] = 0 words[None] = 0
file_names, toc = get_checkable_file_names(container) file_names, ncx_toc = get_checkable_file_names(container)
for file_name in file_names: for file_name in file_names:
if not container.exists(file_name): if not container.exists(file_name):
continue continue
root = container.parsed(file_name) root = container.parsed(file_name)
if file_name == container.opf_name: if file_name == container.opf_name:
read_words_from_opf(root, words, file_name, book_locale) read_words_from_opf(root, words, file_name, book_locale)
elif file_name == toc: elif file_name == ncx_toc:
read_words_from_ncx(root, words, file_name, book_locale) read_words_from_ncx(root, words, file_name, book_locale)
elif hasattr(root, 'xpath'): elif hasattr(root, 'xpath'):
read_words_from_html(root, words, file_name, book_locale) read_words_from_html(root, words, file_name, book_locale)
@ -294,14 +298,14 @@ def get_all_words(container, book_locale, get_word_count=False):
def count_all_chars(container, book_locale): def count_all_chars(container, book_locale):
ans = CharCounter() ans = CharCounter()
file_names, toc = get_checkable_file_names(container) file_names, ncx_toc = get_checkable_file_names(container)
for file_name in file_names: for file_name in file_names:
if not container.exists(file_name): if not container.exists(file_name):
continue continue
root = container.parsed(file_name) root = container.parsed(file_name)
if file_name == container.opf_name: if file_name == container.opf_name:
count_chars_in_opf(root, ans, file_name, book_locale) count_chars_in_opf(root, ans, file_name, book_locale)
elif file_name == toc: elif file_name == ncx_toc:
count_chars_in_ncx(root, ans, file_name, book_locale) count_chars_in_ncx(root, ans, file_name, book_locale)
elif hasattr(root, 'xpath'): elif hasattr(root, 'xpath'):
count_chars_in_html(root, ans, file_name, book_locale) count_chars_in_html(root, ans, file_name, book_locale)

View File

@ -143,7 +143,7 @@ class TagDelegate(QStyledItemDelegate): # {{{
'the item in all books in your library. Is ' 'the item in all books in your library. Is '
'this really what you want to do?') + '</p>', 'this really what you want to do?') + '</p>',
yes_text=_('Yes, apply in entire library'), yes_text=_('Yes, apply in entire library'),
no_text=_('No, apply only in VL'), no_text=_('No, apply only in Virtual library'),
skip_dialog_name='tag_item_rename_in_entire_library') skip_dialog_name='tag_item_rename_in_entire_library')
if self.completion_data: if self.completion_data:
editor = EditWithComplete(parent) editor = EditWithComplete(parent)