Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add valid word characters as a configuration option #147

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/source/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@

unmaintained

Unreleased
==========

Bug Fixes
---------

None.

New Features
------------

- `#147 <https://github.com/sphinx-contrib/spelling/pull/147>`__
Adds the ability to pass in valid word characters as the
configuration option ``spelling_valid_word_characters``, where its
value is a tuple of strings. For example,
``spelling_valid_word_characters = ("'", "-",)``. By default
PyEnchant considers only ``'`` as a valid word character. This pull
request also adds the hyphen ``-`` as a valid word character to
prevent PyEnchant from tokenizing hyphenated words into two words
and marking them as misspellings.

7.3.2
=====

Expand Down
1 change: 1 addition & 0 deletions docs/source/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pypi
reStructuredText
sphinxcontrib
tokenizer
tokenizing
txt
wikis
wordfiles
Expand Down
2 changes: 2 additions & 0 deletions sphinxcontrib/spelling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def setup(app):
app.add_config_value('spelling_filters', [], 'env')
# Set a user-provided list of files to ignore
app.add_config_value('spelling_exclude_patterns', [], 'env')
# Set valid word characters
app.add_config_value('spelling_valid_word_characters', ("'", "-",), 'env')
# Choose whether or not the misspelled output should be displayed
# in the terminal
app.add_config_value('spelling_verbose', True, 'env')
Expand Down
1 change: 1 addition & 0 deletions sphinxcontrib/spelling/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def init(self):
word_list_filename=word_list,
filters=f,
context_line=self.config.spelling_show_whole_line,
valid_word_chars=self.config.spelling_valid_word_characters,
)

def _load_filter_classes(self, filters):
Expand Down
3 changes: 2 additions & 1 deletion sphinxcontrib/spelling/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class SpellingChecker:
"""

def __init__(self, lang, suggest, word_list_filename,
tokenizer_lang='en_US', filters=None, context_line=False):
tokenizer_lang='en_US', filters=None, context_line=False,
valid_word_chars=None):
if enchant_import_error is not None:
raise RuntimeError(
'Cannot instantiate SpellingChecker '
Expand Down