Skip to content

codespell ¤

Backend for the codespell tool.

Classes:

Name Description
CodespellBackend

Backend for the codespell tool.

CodespellBackend(config: dict[str, Any], known_words: set[str] | None = None) ¤

Bases: Backend

Backend for the codespell tool.

This backend needs to build a list of misspellings based on dictionaries provided by codespell itself.

Parameters:

Name Type Description Default
config dict[str, Any]

User configuration from mkdocs.yml.

required
known_words set[str] | None

Globally known words.

None
Source code in src/mkdocs_spellcheck/backends/codespell.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def __init__(self, config: dict[str, Any], known_words: set[str] | None = None) -> None:
    """Initialize the `codespell` backend.

    This backend needs to build a list of misspellings based
    on dictionaries provided by `codespell` itself.

    Parameters:
        config: User configuration from `mkdocs.yml`.
        known_words: Globally known words.
    """
    known_words = known_words or set()
    use_dictionaries = []
    for dictionary in config.get("dictionaries", DEFAULT_DICTS):
        for builtin in _builtin_dictionaries:
            if builtin[0] == dictionary:
                use_dictionaries.append(os.path.join(_data_root, f"dictionary{builtin[2]}.txt"))
    self.misspellings: dict[str, Misspelling] = {}
    for dictionary in use_dictionaries:
        build_dict(dictionary, self.misspellings, known_words)