@@ -167,6 +167,7 @@ ParsedText::ParsedText(const wchar_t *text)
167
167
168
168
m_element = NULL ;
169
169
m_paragraph = NULL ;
170
+ m_end_paragraph_reason = ER_NONE;
170
171
171
172
parse (text);
172
173
}
@@ -191,7 +192,7 @@ void ParsedText::parse(const wchar_t *text)
191
192
cursor++;
192
193
// If text has begun, don't skip empty line
193
194
if (m_paragraph) {
194
- endParagraph ();
195
+ endParagraph (ER_NEWLINE );
195
196
enterElement (ELEMENT_SEPARATOR);
196
197
}
197
198
escape = false ;
@@ -201,7 +202,7 @@ void ParsedText::parse(const wchar_t *text)
201
202
if (c == L' \n ' ) { // Unix breaks
202
203
// If text has begun, don't skip empty line
203
204
if (m_paragraph) {
204
- endParagraph ();
205
+ endParagraph (ER_NEWLINE );
205
206
enterElement (ELEMENT_SEPARATOR);
206
207
}
207
208
escape = false ;
@@ -232,19 +233,28 @@ void ParsedText::parse(const wchar_t *text)
232
233
pushChar (c);
233
234
}
234
235
235
- endParagraph ();
236
+ endParagraph (ER_NONE );
236
237
}
237
238
238
239
void ParsedText::endElement ()
239
240
{
240
241
m_element = NULL ;
241
242
}
242
243
243
- void ParsedText::endParagraph ()
244
+ void ParsedText::endParagraph (EndReason reason )
244
245
{
245
246
if (!m_paragraph)
246
247
return ;
247
248
249
+ EndReason previous = m_end_paragraph_reason;
250
+ m_end_paragraph_reason = reason;
251
+ if (m_empty_paragraph && (reason == ER_TAG ||
252
+ (reason == ER_NEWLINE && previous == ER_TAG))) {
253
+ // Ignore last empty paragraph
254
+ m_paragraph = nullptr ;
255
+ m_paragraphs.pop_back ();
256
+ return ;
257
+ }
248
258
endElement ();
249
259
m_paragraph = NULL ;
250
260
}
@@ -255,6 +265,7 @@ void ParsedText::enterParagraph()
255
265
m_paragraphs.emplace_back ();
256
266
m_paragraph = &m_paragraphs.back ();
257
267
m_paragraph->setStyle (m_style);
268
+ m_empty_paragraph = true ;
258
269
}
259
270
}
260
271
@@ -274,11 +285,15 @@ void ParsedText::enterElement(ElementType type)
274
285
void ParsedText::pushChar (wchar_t c)
275
286
{
276
287
// New word if needed
277
- if (c == L' ' || c == L' \t ' )
278
- enterElement (ELEMENT_SEPARATOR);
279
- else
288
+ if (c == L' ' || c == L' \t ' ) {
289
+ if (!m_empty_paragraph)
290
+ enterElement (ELEMENT_SEPARATOR);
291
+ else
292
+ return ;
293
+ } else {
294
+ m_empty_paragraph = false ;
280
295
enterElement (ELEMENT_TEXT);
281
-
296
+ }
282
297
m_element->text += c;
283
298
}
284
299
@@ -571,7 +586,7 @@ u32 ParsedText::parseTag(const wchar_t *text, u32 cursor)
571
586
} else {
572
587
openTag (name, attrs)->style = m_paragraphtags[name];
573
588
}
574
- endParagraph ();
589
+ endParagraph (ER_TAG );
575
590
576
591
} else
577
592
return 0 ; // Unknown tag
0 commit comments