From f642b1488ab1d4fa0eead0dc00f2bb4398017900 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 9 Apr 2025 19:30:43 -0400 Subject: [PATCH] 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. (cherry picked from commit 704505958ee340563e799ae6a93b6f436eef3e66) --- autotests/texthandlertest.cpp | 3 +++ src/texthandler.cpp | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/autotests/texthandlertest.cpp b/autotests/texthandlertest.cpp index 1ea1487e8..47fb473a3 100644 --- a/autotests/texthandlertest.cpp +++ b/autotests/texthandlertest.cpp @@ -530,6 +530,9 @@ void TextHandlerTest::componentOutput_data() QTest::newRow("quote") << u"

Text

\n
\n

blockquote

\n
"_s << QList{MessageComponent{MessageComponentType::Text, u"Text"_s, {}}, MessageComponent{MessageComponentType::Quote, u"“blockquote”"_s, {}}}; + QTest::newRow("multiple paragraph quote") << u"
\n

blockquote

\n

next paragraph

\n
"_s + << QList{ + MessageComponent{MessageComponentType::Quote, u"

“blockquote

\n

next paragraph”

"_s, {}}}; QTest::newRow("no tag first paragraph") << u"Text\n

Text

"_s << QList{MessageComponent{MessageComponentType::Text, u"Text"_s, {}}, MessageComponent{MessageComponentType::Text, u"Text"_s, {}}}; diff --git a/src/texthandler.cpp b/src/texthandler.cpp index cc4075ee0..6318ed437 100644 --- a/src/texthandler.cpp +++ b/src/texthandler.cpp @@ -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"

"_s)) { - string.remove(0, string.indexOf(u'>') + 1); - string.remove(string.indexOf(u"

"_s), string.size()); + startQuotationIndex = string.indexOf(u">") + 1; + endQuotationIndex = string.lastIndexOf(u"

") + 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;