diff --git a/autotests/texthandlertest.cpp b/autotests/texthandlertest.cpp index 523b72f55..6e30d53bc 100644 --- a/autotests/texthandlertest.cpp +++ b/autotests/texthandlertest.cpp @@ -63,6 +63,7 @@ private Q_SLOTS: void receiveRichEdited(); void receiveLineSeparator(); void receiveRichCodeUrl(); + void receiveRichColor(); void componentOutput_data(); void componentOutput(); @@ -520,6 +521,25 @@ void TextHandlerTest::receiveRichCodeUrl() QCOMPARE(testTextHandler.handleRecieveRichText(), input); } +void TextHandlerTest::receiveRichColor() +{ + const QString testInputString = QStringLiteral( + "¯\\_()_/¯"); + const QString testOutputString = QStringLiteral( + "¯\\_()_/¯"); + + TextHandler testTextHandler; + testTextHandler.setData(testInputString); + + qInfo() << testTextHandler.handleRecieveRichText(); + + QCOMPARE(testTextHandler.handleRecieveRichText(), testOutputString); +} + void TextHandlerTest::componentOutput_data() { QTest::addColumn("testInputString"); diff --git a/src/texthandler.cpp b/src/texthandler.cpp index 42ac78344..d79d83415 100644 --- a/src/texthandler.cpp +++ b/src/texthandler.cpp @@ -496,6 +496,7 @@ QString TextHandler::cleanAttributes(const QString &tag, const QString &tagStrin nextAttribute = tagString.mid(nextAttributeIndex, nextSpaceIndex - nextAttributeIndex); if (isAllowedAttribute(tag, getAttributeType(nextAttribute))) { + QString style; if (tag == QStringLiteral("img") && getAttributeType(nextAttribute) == QStringLiteral("src")) { QString attributeData = TextRegex::attributeData.match(getAttributeData(nextAttribute)).captured(1); if (isAllowedLink(attributeData, true)) { @@ -516,9 +517,19 @@ QString TextHandler::cleanAttributes(const QString &tag, const QString &tagStrin if (attributeData == customEmojiStyle) { outputString.append(u' ' + nextAttribute); } + } else if (getAttributeType(nextAttribute) == QStringLiteral("data-mx-color")) { + const QString attributeData = TextRegex::attributeData.match(getAttributeData(nextAttribute)).captured(1); + style.append(u"color: " + attributeData + u';'); + } else if (getAttributeType(nextAttribute) == QStringLiteral("data-mx-bg-color")) { + const QString attributeData = TextRegex::attributeData.match(getAttributeData(nextAttribute)).captured(1); + style.append(u"background-color: " + attributeData + u';'); } else { outputString.append(u' ' + nextAttribute); } + + if (!style.isEmpty()) { + outputString.append(u" style=\"" + style + u'"'); + } } nextAttributeIndex = nextSpaceIndex + 1; }