diff --git a/src/fenrirscreenreader/core/punctuationManager.py b/src/fenrirscreenreader/core/punctuationManager.py index 4501b650..4e5ab17e 100644 --- a/src/fenrirscreenreader/core/punctuationManager.py +++ b/src/fenrirscreenreader/core/punctuationManager.py @@ -49,11 +49,38 @@ class PunctuationManager: def remove_unused(self, text, curr_level=""): # dont translate dot and comma because they create a pause curr_all_punct_none = self.allPunctNone.copy() + + # Check if we should replace undefined punctuation with spaces + replace_with_space = self.env["runtime"]["SettingsManager"].get_setting_as_bool( + "general", "replaceUndefinedPunctuationWithSpace" + ) + + # If the setting is disabled, use the old behavior (remove completely) + if not replace_with_space: + # Create a map that removes undefined punctuation instead of replacing with spaces + curr_all_punct_none = dict.fromkeys( + map(ord, string.punctuation + "ยง "), None + ) + # Restore the pause-important characters + for char in [ + ord("'"), + ord("."), + ord(","), + ord(";"), + ord(":"), + ord("?"), + ord("!"), + ord("-"), + ]: + curr_all_punct_none[char] = chr(char) + + # Remove characters that are defined in the current punctuation level for char in curr_level: try: del curr_all_punct_none[ord(char)] except Exception as e: pass + return text.translate(curr_all_punct_none) def use_custom_dict(self, text, customDict, seperator=""): diff --git a/src/fenrirscreenreader/core/settingsData.py b/src/fenrirscreenreader/core/settingsData.py index 944775f8..4d8b99be 100644 --- a/src/fenrirscreenreader/core/settingsData.py +++ b/src/fenrirscreenreader/core/settingsData.py @@ -50,6 +50,7 @@ settings_data = { "punctuationProfile": "default", "punctuationLevel": "some", "respectPunctuationPause": True, + "replaceUndefinedPunctuationWithSpace": True, "newLinePause": True, "numberOfClipboards": 10, "emoticons": True,