Strip single <p> tags inside TextHandler rather than actions handler

This commit is contained in:
James Graham
2024-10-05 17:05:36 +00:00
parent a4e9794b13
commit aedba5c650
3 changed files with 29 additions and 20 deletions

View File

@@ -126,11 +126,6 @@ void ActionsHandler::handleMessage(NeoChatRoom *room, QString handledText, ChatB
textHandler.setData(handledText);
handledText = textHandler.handleSendText();
if (handledText.count("<p>"_ls) == 1 && handledText.count("</p>"_ls) == 1) {
handledText.remove("<p>"_ls);
handledText.remove("</p>"_ls);
}
if (handledText.length() == 0) {
return;
}

View File

@@ -20,6 +20,8 @@
#include "models/customemojimodel.h"
#include "utils.h"
using namespace Qt::StringLiterals;
static const QStringList allowedTags = {
QStringLiteral("font"), QStringLiteral("del"), QStringLiteral("h1"), QStringLiteral("h2"), QStringLiteral("h3"), QStringLiteral("h4"),
QStringLiteral("h5"), QStringLiteral("h6"), QStringLiteral("blockquote"), QStringLiteral("p"), QStringLiteral("a"), QStringLiteral("ul"),
@@ -93,6 +95,12 @@ QString TextHandler::handleSendText()
m_nextTokenType = nextTokenType(m_dataBuffer, m_pos, m_nextToken, m_nextTokenType);
}
if (outputString.count("<p>"_L1) == 1 && outputString.count("</p>"_L1) == 1 && outputString.startsWith("<p>"_L1) && outputString.endsWith("</p>"_L1)) {
outputString.remove("<p>"_L1);
outputString.remove("</p>"_L1);
}
return outputString;
}
@@ -170,6 +178,12 @@ TextHandler::handleRecieveRichText(Qt::TextFormat inputFormat, const NeoChatRoom
* convert as that is what is needed for Qt::RichText.
*/
outputString.replace(TextRegex::strikethrough, QStringLiteral("<s>\\1</s>"));
if (outputString.count("<p>"_L1) == 1 && outputString.count("</p>"_L1) == 1 && outputString.startsWith("<p>"_L1) && outputString.endsWith("</p>"_L1)) {
outputString.remove("<p>"_L1);
outputString.remove("</p>"_L1);
}
return outputString;
}