From c166b89f7bd9f3aed3113425bf975ca6fc8c43aa Mon Sep 17 00:00:00 2001 From: Jonas Diemer Date: Thu, 22 Jan 2026 17:07:18 +0100 Subject: [PATCH] Make sure img alt text is treated as separate text block --- lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp index 1710eed..275cc01 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp @@ -135,7 +135,10 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char* if (atts != nullptr) { for (int i = 0; atts[i]; i += 2) { if (strcmp(atts[i], "alt") == 0) { - alt = "[Image: " + std::string(atts[i + 1]) + "]"; + // add " " (counts as whitespace) at the end of alt + // so the corresponding text block ends. + // TODO: A zero-width breaking space would be more appropriate (once/if we support it) + alt = "[Image: " + std::string(atts[i + 1]) + "] "; } } Serial.printf("[%lu] [EHP] Image alt: %s\n", millis(), alt.c_str()); @@ -144,7 +147,7 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char* self->italicUntilDepth = min(self->italicUntilDepth, self->depth); self->depth += 1; self->characterData(userData, alt.c_str(), alt.length()); - + return; } else { // Skip for now self->skipUntilDepth = self->depth;