Ignore metadata and leding/trailing spaces when counting text length

This commit is contained in:
Deniz Şafak
2025-05-22 02:54:29 +03:00
parent 6e96fb6405
commit a0e59564af
+7 -3
View File
@@ -204,11 +204,15 @@ def save_config(config):
def calculate_text_length(text):
# Ignore chapter markers
text_no_markers = re.sub(r"<<CHAPTER_MARKER:.*?>>", "", text)
text = re.sub(r"<<CHAPTER_MARKER:.*?>>", "", text)
# Ignore metadata patterns
text = re.sub(r"<<METADATA_[^:]+:[^>]*>>", "", text)
# Ignore newlines
cleaned_text = text_no_markers.replace("\n", "")
text = text.replace("\n", "")
# Ignore leading/trailing spaces
text = text.strip()
# Calculate character count
char_count = len(cleaned_text)
char_count = len(text)
return char_count