From a0e59564af01664bcc0f4a6975956b2d1afd61ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Deniz=20=C5=9Eafak?= Date: Thu, 22 May 2025 02:54:29 +0300 Subject: [PATCH] Ignore metadata and leding/trailing spaces when counting text length --- abogen/utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/abogen/utils.py b/abogen/utils.py index 4e51ba5..46f77b9 100644 --- a/abogen/utils.py +++ b/abogen/utils.py @@ -204,11 +204,15 @@ def save_config(config): def calculate_text_length(text): # Ignore chapter markers - text_no_markers = re.sub(r"<>", "", text) + text = re.sub(r"<>", "", text) + # Ignore metadata patterns + text = re.sub(r"<]*>>", "", 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