### JSON: Filter configuration example Source: https://github.com/aedanbricker/sphinx_rtd_dark_mode/blob/main/tests/preview-build/test.rst Example JSON configuration for filters, including mainFilter, dontFilter, and conditionFilter arrays. ```json { "mainFilter": [ { "find": "find", "word": "word", "censored": "censored" }, { "find": "helo", "word": "hello", "censored": "h3110" } ], "dontFilter": ["word"], "conditionFilter": [ { "find": "find", "word": "word", "censored": "censored", "require_space": true } ] } ``` -------------------------------- ### Python: Using content_filter.Filter Source: https://github.com/aedanbricker/sphinx_rtd_dark_mode/blob/main/tests/preview-build/test.rst Demonstrates the Filter class from content_filter. Shows how to check messages, add words, and add exceptions. Comments indicate return types and behavior. ```python from content_filter import Filter filter = Filter() filter.check('message here') # returns a Check object filter.check('message here').as_bool # returns a bool of True if it found anything, False if not filter.add_words(['word1', 'word2', 'word2']) # adds words to default filter filter.add_exceptions(['word1', 'word2', 'word2']) # ignores words in default filter ``` -------------------------------- ### Shell: Setting environment variable TESTING Source: https://github.com/aedanbricker/sphinx_rtd_dark_mode/blob/main/tests/preview-build/test.rst Exports the environment variable TESTING with value 16. ```sh export TESTING=16 ``` -------------------------------- ### class content_filter.Filter Source: https://github.com/aedanbricker/sphinx_rtd_dark_mode/blob/main/tests/preview-build/api.rst The Filter class manages filter settings, data, and functions. It can be initialized with a custom list file or word list, and provides methods to add or remove words, check messages, and reload the filter from a file. ```APIDOC ## class content_filter.Filter ### Description The Filter object which contains the filter settings, data, and functions. ### Constructor `Filter(list_file: str | None = None, word_list: List[str] | None = None)` ### Parameters - **list_file** (*str*, *optional*) - The path to a file that will be used as the filter list in place of the default filter. - **word_list** (*str*, *optional*) - A list of words to be used as the filter in place of the default filter. ### Raises - **TypeError** - Something other than a `list` was not passed in for word_list. - **FileNotFoundError** - The input file for list_file does not exist. - **ValueError** - The custom file input is not a JSON file. ### Methods #### add_exceptions(words: List[str]) -> None Allows the user to remove words from the list of pre-defined words to filter for. **Parameters:** - **words** (*list*) - A list of strings that will be removed from the default filter checking. **Raises:** - **TypeError** - Words input are not a list of strings. #### add_words(words: List[str]) -> None Allows the user to add words to the list of pre-defined words to filter for. **Parameters:** - **words** (*list*) - A list of strings that will be added to the default filter checking. **Raises:** - **TypeError** - Words input are not a list of strings. #### check(message: str) -> Check Checks the provided message for any words that should be filtered. **Parameters:** - **message** (*str*) - The message to be filtered. This should be a string. **Raises:** - **TypeError** - Message is not a string. **Returns:** - A check object which contains the results of the filter. **Return type:** - .Check #### property list_file: Path Gives you the path to the list file if using a custom filter file. **Raises:** - **RuntimeError** - Not using a custom JSON file. **Returns:** - A path object to the custom json file. **Return type:** - `pathlib.Path` #### reload_file() -> None Updates the filter list when using a custom JSON file. If any changes have been made to the file, they will be applied. **Raises:** - **RuntimeError** - Not using a custom JSON file. ``` -------------------------------- ### class content_filter.check.Check Source: https://github.com/aedanbricker/sphinx_rtd_dark_mode/blob/main/tests/preview-build/api.rst The Check class evaluates a message against the filter and provides results as a boolean or a list of found words. ```APIDOC ## class content_filter.check.Check ### Description Check object which checks a message and can return the results as either a list or a bool. ### Constructor `Check(message: str, exception_list: List[str], additional_list: List[str], custom_list: List[str], use_default_list: bool, use_custom_file: Dict[str, Any], translation_table: Dict[str, Any], filter_file: Path)` ### Properties #### property as_bool: bool Outputs the check results as a bool. **Returns:** - True if the message contains a filter word, False if it doesn't. **Return type:** - `bool` #### property as_list: List[Dict[str, Any]] Outputs the check results as a list. **Returns:** - List of all the words found in the message. A blank list is returned if no words are found. **Return type:** - `list` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.