diff --git a/abogen/book_parser.py b/abogen/book_parser.py index a5da16a..d81e743 100644 --- a/abogen/book_parser.py +++ b/abogen/book_parser.py @@ -915,7 +915,11 @@ class EpubParser(BaseBookParser): if slice_html.strip(): slice_soup = BeautifulSoup(slice_html, "html.parser") - for tag in slice_soup.find_all(["p", "div"]): + + # Add line breaks after block-level elements to ensure pauses in speech + for tag in slice_soup.find_all( + ["p", "div", "h1", "h2", "h3", "h4", "h5", "h6", "li", "blockquote"] + ): tag.append("\n\n") for ol in slice_soup.find_all("ol"): diff --git a/abogen/text_extractor.py b/abogen/text_extractor.py index 7d6bcf3..066a9da 100644 --- a/abogen/text_extractor.py +++ b/abogen/text_extractor.py @@ -1023,8 +1023,13 @@ class EpubExtractor: if not html: return "" soup = BeautifulSoup(html, "html.parser") - for tag in soup.find_all(["p", "div"]): + + # Add line breaks after block-level elements to ensure pauses in speech + for tag in soup.find_all( + ["p", "div", "h1", "h2", "h3", "h4", "h5", "h6", "li", "blockquote"] + ): tag.append("\n\n") + for ol in soup.find_all("ol"): start_attr = ol.get("start") try: