Skip to content

Commit

Permalink
maintenance: refactor code for managing temporary word list
Browse files Browse the repository at this point in the history
Extract the logic for managing the per-document temporary word list
from the directive so it can be reused outside of the directive.
  • Loading branch information
dhellmann committed Jun 25, 2022
1 parent cb6a4e5 commit 05cc01b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions sphinxcontrib/spelling/directive.py
Expand Up @@ -12,6 +12,16 @@
logger = logging.getLogger(__name__)


def add_good_words_to_document(env, docname, good_words):
# Initialize the per-document good words list
if not hasattr(env, 'spelling_document_words'):
env.spelling_document_words = collections.defaultdict(list)
logger.info('Extending local dictionary for %s with %s',
env.docname, good_words)
print(env.docname, good_words)
env.spelling_document_words[env.docname].extend(good_words)


class SpellingDirective(rst.Directive):
"""Custom directive for passing instructions to the spelling checker.
Expand All @@ -27,19 +37,13 @@ class SpellingDirective(rst.Directive):
def run(self):
env = self.state.document.settings.env

# Initialize the per-document good words list
if not hasattr(env, 'spelling_document_words'):
env.spelling_document_words = collections.defaultdict(list)

good_words = []
for entry in self.content:
if not entry:
continue
good_words.extend(entry.split())
if good_words:
logger.debug('Extending local dictionary for %s with %s',
env.docname, good_words)
env.spelling_document_words[env.docname].extend(good_words)
add_good_words_to_document(env, env.docname, good_words)

return []

Expand Down

0 comments on commit 05cc01b

Please sign in to comment.