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
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