diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp
index fdc059c..d77b0c0 100644
--- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp
+++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp
@@ -80,6 +80,26 @@ void ChapterHtmlSlimParser::updateEffectiveInlineStyle() {
}
}
+// Flush the contents of partWordBuffer to currentTextBlock
+void ChapterHtmlSlimParser::flushPartWordBuffer() {
+ if (partWordBufferIndex == 0) return;
+
+ // Determine font style using effective styles
+ EpdFontFamily::Style fontStyle = EpdFontFamily::REGULAR;
+ if (effectiveBold && effectiveItalic) {
+ fontStyle = EpdFontFamily::BOLD_ITALIC;
+ } else if (effectiveBold) {
+ fontStyle = EpdFontFamily::BOLD;
+ } else if (effectiveItalic) {
+ fontStyle = EpdFontFamily::ITALIC;
+ }
+
+ // Flush the buffer
+ partWordBuffer[partWordBufferIndex] = '\0';
+ currentTextBlock->addWord(partWordBuffer, fontStyle, effectiveUnderline);
+ partWordBufferIndex = 0;
+}
+
// start a new text block if needed
void ChapterHtmlSlimParser::startNewTextBlock(const TextBlock::Style style, const BlockStyle& blockStyle) {
if (currentTextBlock) {
@@ -341,6 +361,9 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char*
self->updateEffectiveInlineStyle();
} else if (matches(name, BLOCK_TAGS, NUM_BLOCK_TAGS)) {
if (strcmp(name, "br") == 0) {
+ // Flush word preceding
to currentTextBlock before calling startNewTextBlock
+ // This fixes issue where
incorrectly wrapped the preceding word to a new line
+ self->flushPartWordBuffer();
self->startNewTextBlock(self->currentTextBlock->getStyle());
} else {
// Determine alignment from CSS or default
diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h
index 0d19a68..cad8fad 100644
--- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h
+++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h
@@ -67,6 +67,7 @@ class ChapterHtmlSlimParser {
void updateEffectiveInlineStyle();
void startNewTextBlock(TextBlock::Style style);
void startNewTextBlock(TextBlock::Style style, const BlockStyle& blockStyle);
+ void flushPartWordBuffer();
void makePages();
// XML callbacks
static void XMLCALL startElement(void* userData, const XML_Char* name, const XML_Char** atts);