Fix multi-line quotes being cut off
This was a mistake in the code that was designed to remove the outside paragraphs, which seems to be to make way for the quotation marks we add around the text. Instead of doing that (which turns out, is very brittle and breaks on multiple paragraphs) insert the quotation marks *inside* of the paragraph tags. A test case is added for this as well.
This commit is contained in:
@@ -530,6 +530,9 @@ void TextHandlerTest::componentOutput_data()
|
||||
QTest::newRow("quote") << u"<p>Text</p>\n<blockquote>\n<p>blockquote</p>\n</blockquote>"_s
|
||||
<< QList<MessageComponent>{MessageComponent{MessageComponentType::Text, u"Text"_s, {}},
|
||||
MessageComponent{MessageComponentType::Quote, u"“blockquote”"_s, {}}};
|
||||
QTest::newRow("multiple paragraph quote") << u"<blockquote>\n<p>blockquote</p>\n<p>next paragraph</p>\n</blockquote>"_s
|
||||
<< QList<MessageComponent>{
|
||||
MessageComponent{MessageComponentType::Quote, u"<p>“blockquote</p>\n<p>next paragraph”</p>"_s, {}}};
|
||||
QTest::newRow("no tag first paragraph") << u"Text\n<p>Text</p>"_s
|
||||
<< QList<MessageComponent>{MessageComponent{MessageComponentType::Text, u"Text"_s, {}},
|
||||
MessageComponent{MessageComponentType::Text, u"Text"_s, {}}};
|
||||
|
||||
@@ -381,18 +381,20 @@ QString TextHandler::stripBlockTags(QString string, const QString &tagType) cons
|
||||
}
|
||||
}
|
||||
if (tagType == u"blockquote"_s) {
|
||||
int startQuotationIndex = 0;
|
||||
int endQuotationIndex = string.size();
|
||||
|
||||
// We have to insert the quotation marks inside of the existing
|
||||
// paragraphs, otherwise we add unnecessary line breaks.
|
||||
if (string.startsWith(u"<p>"_s)) {
|
||||
string.remove(0, string.indexOf(u'>') + 1);
|
||||
string.remove(string.indexOf(u"</p>"_s), string.size());
|
||||
startQuotationIndex = string.indexOf(u">") + 1;
|
||||
endQuotationIndex = string.lastIndexOf(u"</p>") + 1;
|
||||
}
|
||||
|
||||
// This is not a normal quotation mark but U+201C
|
||||
if (!string.startsWith(u'“')) {
|
||||
string.prepend(u'“');
|
||||
}
|
||||
string.insert(startQuotationIndex, u'“');
|
||||
// This is U+201D
|
||||
if (!string.endsWith(u'”')) {
|
||||
string.append(u'”');
|
||||
}
|
||||
string.insert(endQuotationIndex, u'”');
|
||||
}
|
||||
|
||||
return string;
|
||||
|
||||
Reference in New Issue
Block a user