fix: image centering bleed (#1096)
## Summary * Fixes #1026 * Added a reproducer chapter to the epub generator for this case * The fix is in endElement — when leaving a block/header element that had an empty text block, reset the alignment to the user's default so it doesn't bleed into the next sibling. This preserves accumulated margins from parent elements while preventing stale alignment from carrying across. ## Additional Context ### Before fix    ### After fix   --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**< PARTIALLY **_
This commit is contained in:
@@ -789,6 +789,20 @@ void XMLCALL ChapterHtmlSlimParser::endElement(void* userData, const XML_Char* n
|
||||
if (headerOrBlockTag) {
|
||||
self->currentCssStyle.reset();
|
||||
self->updateEffectiveInlineStyle();
|
||||
|
||||
// Reset alignment on empty text blocks to prevent stale alignment from bleeding
|
||||
// into the next sibling element. This fixes issue #1026 where an empty <h1> (default
|
||||
// Center) followed by an image-only <p> 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.
|
||||
if (self->currentTextBlock && self->currentTextBlock->isEmpty()) {
|
||||
auto style = self->currentTextBlock->getBlockStyle();
|
||||
style.textAlignDefined = false;
|
||||
style.alignment = (self->paragraphAlignment == static_cast<uint8_t>(CssTextAlign::None))
|
||||
? CssTextAlign::Justify
|
||||
: static_cast<CssTextAlign>(self->paragraphAlignment);
|
||||
self->currentTextBlock->setBlockStyle(style);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user