From 4809faa636b0a2631342efc37916a60f44e305d0 Mon Sep 17 00:00:00 2001 From: Dave Allie Date: Mon, 6 Apr 2026 15:25:05 +1000 Subject: [PATCH] fix: Reset block style completely when leaving element to prevent bleeding styles --- lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp index 368a4c60d..071aa14fd 100644 --- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp +++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp @@ -955,17 +955,29 @@ void XMLCALL ChapterHtmlSlimParser::endElement(void* userData, const XML_Char* n self->currentCssStyle.reset(); self->updateEffectiveInlineStyle(); - // Reset alignment on empty text blocks to prevent stale alignment from bleeding + // Reset block style on empty text blocks to prevent stale styling from bleeding // into the next sibling element. This fixes issue #1026 where an empty

(default // Center) followed by an image-only

causes Center to persist through the chain // of empty block reuse into subsequent text paragraphs. - // Margins/padding are preserved so parent element spacing still accumulates correctly. + // Margins/padding are also reset to prevent a closed block's horizontal margins from + // leaking to the next sibling (e.g.

text

+ // would otherwise cause the

to inherit the div's 40% side margins). + // Parent-child margin accumulation is unaffected because it happens at child open time + // via getCombinedBlockStyle(), before the parent closes. if (self->currentTextBlock && self->currentTextBlock->isEmpty()) { auto style = self->currentTextBlock->getBlockStyle(); style.textAlignDefined = false; style.alignment = (self->paragraphAlignment == static_cast(CssTextAlign::None)) ? CssTextAlign::Justify : static_cast(self->paragraphAlignment); + style.marginLeft = 0; + style.marginRight = 0; + style.marginTop = 0; + style.marginBottom = 0; + style.paddingLeft = 0; + style.paddingRight = 0; + style.paddingTop = 0; + style.paddingBottom = 0; self->currentTextBlock->setBlockStyle(style); } }