mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Added "Replace single newlines with spaces" and small improvements
This commit is contained in:
+7
-3
@@ -69,13 +69,17 @@ def get_user_config_path():
|
||||
_sleep_procs = {"Darwin": None, "Linux": None} # Store sleep prevention processes
|
||||
|
||||
|
||||
def clean_text(text):
|
||||
def clean_text(text, *args, **kwargs):
|
||||
# Load replace_single_newlines from config
|
||||
cfg = load_config()
|
||||
replace_single_newlines = cfg.get("replace_single_newlines", False)
|
||||
# Trim spaces and tabs at the start and end of each line, preserving blank lines
|
||||
text = "\n".join(line.strip() for line in text.splitlines())
|
||||
# Standardize paragraph breaks (multiple newlines become exactly two) and trim overall whitespace
|
||||
text = re.sub(r"\n{3,}", "\n\n", text).strip()
|
||||
# Replace single newlines with spaces, but preserve double newlines
|
||||
# text = re.sub(r"(?<!\n)\n(?!\n)", " ", text)
|
||||
# Optionally replace single newlines with spaces, but preserve double newlines
|
||||
if replace_single_newlines:
|
||||
text = re.sub(r"(?<!\n)\n(?!\n)", " ", text)
|
||||
# Collapse multiple spaces and tabs into a single space
|
||||
text = re.sub(r"[ \t]+", " ", text)
|
||||
return text
|
||||
|
||||
Reference in New Issue
Block a user