From 4f46eb74f4dc805ead981aec395321e98bbd234e Mon Sep 17 00:00:00 2001 From: JB Date: Fri, 10 Oct 2025 12:08:22 -0700 Subject: [PATCH] feat: Add original text preservation in chunk overlays and enhance whitespace handling in EPUB export --- abogen/epub3/exporter.py | 20 +++++++++++++++++--- tests/test_epub_exporter.py | 13 +++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/abogen/epub3/exporter.py b/abogen/epub3/exporter.py index b032dfa..e3e29f1 100644 --- a/abogen/epub3/exporter.py +++ b/abogen/epub3/exporter.py @@ -18,6 +18,7 @@ from abogen.text_extractor import ExtractedChapter, ExtractionResult class ChunkOverlay: id: str text: str + original_text: Optional[str] start: Optional[float] end: Optional[float] speaker_id: str @@ -259,6 +260,7 @@ class EPUB3PackageBuilder: ChunkOverlay( id=normalized_id, text=text or self.extraction.chapters[chapter_index].text, + original_text=None, start=_safe_float(marker.get("start")), end=_safe_float(marker.get("end")), speaker_id=speaker_id, @@ -284,11 +286,11 @@ class EPUB3PackageBuilder: chunk_html = "

" original_block = "" if chapter.chunks: - original_text = "".join(chunk.text or "" for chunk in chapter.chunks) + original_text = "".join((chunk.original_text if chunk.original_text is not None else (chunk.text or "")) for chunk in chapter.chunks) if original_text: safe_original = html.escape(original_text) original_block = ( - "