diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp
index 6b4937f7..705a6f7a 100644
--- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp
+++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp
@@ -137,7 +137,8 @@ void ChapterHtmlSlimParser::startNewTextBlock(const BlockStyle& blockStyle) {
// div's margin should be preserved, even though it has no direct text content.
BlockStyle incoming = blockStyle;
- if (currentTextBlock->getBlockStyle().fromBrElement) {
+ const bool brGapPending = currentTextBlock->getBlockStyle().fromBrElement;
+ if (brGapPending) {
// The empty block was created by a
section separator. Inject a full line of
// blank space before the following paragraph so the scene/section break is visible.
// This only fires when the
block stayed empty (i.e. no inline text was added).
@@ -145,7 +146,11 @@ void ChapterHtmlSlimParser::startNewTextBlock(const BlockStyle& blockStyle) {
incoming.marginTop = static_cast(incoming.marginTop + lineHeight);
}
- currentTextBlock->setBlockStyle(currentTextBlock->getBlockStyle().getCombinedBlockStyle(incoming));
+ BlockStyle merged = currentTextBlock->getBlockStyle().getCombinedBlockStyle(incoming);
+ // Preserve only whether the current empty block still represents
separators.
+ // This lets consecutive
accumulate one line each without leaking the flag to real content blocks.
+ merged.fromBrElement = blockStyle.fromBrElement;
+ currentTextBlock->setBlockStyle(merged);
if (!pendingAnchorId.empty()) {
if (std::find(tocAnchors.begin(), tocAnchors.end(), pendingAnchorId) != tocAnchors.end()) {
@@ -657,7 +662,14 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char*
// the block remains empty (i.e.
is a section separator between paragraphs).
// If the block gets text added before the next block opens it becomes non-empty,
// goes through makePages() normally, and the flag has no effect (inline
case).
- BlockStyle brStyle = self->currentTextBlock->getBlockStyle();
+ // Build a neutral
style that keeps inline alignment/indent context but avoids
+ // carrying cumulative margins from previous empty blocks (which can force spurious page breaks).
+ const BlockStyle& currentStyle = self->currentTextBlock->getBlockStyle();
+ BlockStyle brStyle;
+ brStyle.alignment = currentStyle.alignment;
+ brStyle.textAlignDefined = currentStyle.textAlignDefined;
+ brStyle.textIndent = currentStyle.textIndent;
+ brStyle.textIndentDefined = currentStyle.textIndentDefined;
brStyle.fromBrElement = true;
self->startNewTextBlock(brStyle);
} else {