Cherrypick Handle stripnewlines for plain text list to 23.04

Handle stripping new lines when the plain text input is a markdown list.


(cherry picked from commit a0ae8b28b2)
This commit is contained in:
James Graham
2023-03-27 13:30:27 +00:00
committed by Tobias Fella
parent a3b4f05e2c
commit 566743bc19
3 changed files with 16 additions and 8 deletions

View File

@@ -151,12 +151,6 @@ QString TextHandler::handleRecievePlainText(Qt::TextFormat inputFormat, const bo
// Strip mx-reply if present.
m_dataBuffer.remove(TextRegex::removeRichReply);
if (stripNewlines) {
m_dataBuffer.replace(QStringLiteral("<br>"), QStringLiteral(" "));
m_dataBuffer.replace(QStringLiteral("<br />"), QStringLiteral(" "));
m_dataBuffer.replace(u'\n', QStringLiteral(" "));
}
// Escaping then unescaping allows < and > to be maintained in a plain text string
// otherwise markdownToHTML will strip what it thinks is a bad html tag entirely.
if (inputFormat == Qt::PlainText) {
@@ -169,6 +163,14 @@ QString TextHandler::handleRecievePlainText(Qt::TextFormat inputFormat, const bo
*/
m_dataBuffer = markdownToHTML(m_dataBuffer);
if (stripNewlines) {
m_dataBuffer.replace(QStringLiteral("<br>\n"), QStringLiteral(" "));
m_dataBuffer.replace(QStringLiteral("<br>"), QStringLiteral(" "));
m_dataBuffer.replace(QStringLiteral("<br />\n"), QStringLiteral(" "));
m_dataBuffer.replace(QStringLiteral("<br />"), QStringLiteral(" "));
m_dataBuffer.replace(u'\n', QStringLiteral(" "));
}
// Strip all tags/attributes except code blocks which will be escaped.
QString outputString;
nextTokenType();
@@ -193,6 +195,7 @@ QString TextHandler::handleRecievePlainText(Qt::TextFormat inputFormat, const bo
outputString = unescapeHtml(outputString);
}
outputString = outputString.trimmed();
return outputString;
}