Ignore chapter markers and single newlines when calculating text length

This commit is contained in:
Deniz Şafak
2025-05-08 16:29:43 +03:00
parent 4d0aabc13e
commit 311cdaeae1
3 changed files with 14 additions and 3 deletions
+4 -2
View File
@@ -119,8 +119,10 @@ def save_config(config):
def calculate_text_length(text):
# Remove double newlines (replace them with single newlines)
cleaned_text = text.replace("\n\n", "")
# Ignore chapter markers
text_no_markers = re.sub(r"<<CHAPTER_MARKER:.*?>>", "", text)
# Ignore newlines
cleaned_text = text_no_markers.replace("\n", "")
# Calculate character count
char_count = len(cleaned_text)
return char_count