From 988b7d97f2ea125b17d788803e82a61914b08946 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 14 Dec 2021 15:43:34 +0530 Subject: [PATCH] Edit book: Allow adding a comment to an individual HTML/OPF/NCX file to exclude it from being checked when running the spell check tool --- manual/edit.rst | 8 ++++++++ src/calibre/ebooks/oeb/polish/spell.py | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/manual/edit.rst b/manual/edit.rst index d86cc88df3..da09912fda 100644 --- a/manual/edit.rst +++ b/manual/edit.rst @@ -678,6 +678,14 @@ common in your book and to run a simple search and replace on individual words. check tool. If you do not do this and continue to use the Spell check tool, you could lose the changes you have made in the editor. +.. note:: + To exclude an individual file from being spell checked when running the + spell check tool, you can add the following comment just under the first + opening tag in the file:: + + + + Adding new dictionaries ########################### diff --git a/src/calibre/ebooks/oeb/polish/spell.py b/src/calibre/ebooks/oeb/polish/spell.py index 1c25cb898e..78ced6471f 100644 --- a/src/calibre/ebooks/oeb/polish/spell.py +++ b/src/calibre/ebooks/oeb/polish/spell.py @@ -275,6 +275,14 @@ def get_checkable_file_names(container): return file_names, ncx_toc +def root_is_excluded_from_spell_check(root): + for child in root: + q = (getattr(child, 'text', '') or '').strip().lower() + if q == 'calibre-no-spell-check': + return True + return False + + def get_all_words(container, book_locale, get_word_count=False): words = defaultdict(list) words[None] = 0 @@ -283,6 +291,8 @@ def get_all_words(container, book_locale, get_word_count=False): if not container.exists(file_name): continue root = container.parsed(file_name) + if root_is_excluded_from_spell_check(root): + continue if file_name == container.opf_name: read_words_from_opf(root, words, file_name, book_locale) elif file_name == ncx_toc: