#
# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
#
"""Spelling checker extension for Sphinx.
"""

import collections

from docutils.parsers import rst
from sphinx.util import logging

logger = logging.getLogger(__name__)


class SpellingDirective(rst.Directive):
    """Custom directive for passing instructions to the spelling checker.

    .. spelling::

       word1
       word2

    """

    has_content = True

    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)

        return []


class LegacySpellingDirective(SpellingDirective):

    def run(self):
        logger.info('direct use of the spelling directive is deprecated, '
                    'replace ".. spelling::" with ".. spelling:word-list::"')
        return super().run()

@@ -227,16 +227,447 @@
 me__)%0A%0A%0A
+def add_good_words_to_document(env, docname, good_words):%0A    # Initialize the per-document good words list%0A    if not hasattr(env, 'spelling_document_words'):%0A        env.spelling_document_words = collections.defaultdict(list)%0A    logger.info('Extending local dictionary for %25s with %25s',%0A                env.docname, good_words)%0A    print(env.docname, good_words)%0A    env.spelling_document_words%5Benv.docname%5D.extend(good_words)%0A%0A%0A
 class Sp
@@ -923,191 +923,8 @@
 nv%0A%0A
-        # Initialize the per-document good words list%0A        if not hasattr(env, 'spelling_document_words'):%0A            env.spelling_document_words = collections.defaultdict(list)%0A%0A
     
@@ -1113,140 +1113,25 @@
     
-logger.debug('Extending local dictionary for %25s with %25s',%0A                         env.docname, good_words)%0A            env.spelling
+add_good_words_to
 _doc
@@ -1127,39 +1127,38 @@
 ords_to_document
-_words%5B
+(env, 
 env.docname%5D.ext
@@ -1148,33 +1148,26 @@
  env.docname
-%5D.extend(
+, 
 good_words)%0A

refactor code for managing temporary word list