Add custom syntax for tagging spoilers

Currently the only two ways to spoiler text in your message is either:
* Using the /spoiler command
* Manually typing the data-mx-spoiler span HTML blocks

Neither one is discoverable, or friendly to users really. Instead, we
should extend our existing Markdown-based formatting syntax with one
that can handle spoiler tags. I chose the || syntax to match Discord,
since Element doesn't seem to adopt one.

Unfortunately, CMark does not support custom extensions (see
https://github.com/commonmark/cmark/pull/123) so we have to implement
our own parsing function. New tests are also added for this too.
This commit is contained in:
Joshua Goins
2025-04-27 17:04:05 -04:00
parent 86a43c4f7e
commit 6b5996a1bd
3 changed files with 50 additions and 0 deletions

View File

@@ -43,6 +43,8 @@ private Q_SLOTS:
void sendCustomEmoji();
void sendCustomEmojiCode_data();
void sendCustomEmojiCode();
void sendSpoilerTags_data();
void sendSpoilerTags();
void receiveSpacelessSelfClosingTag();
void receiveStripReply();
@@ -249,6 +251,27 @@ void TextHandlerTest::sendCustomEmojiCode()
QCOMPARE(testTextHandler.handleSendText(), testOutputString);
}
void TextHandlerTest::sendSpoilerTags_data()
{
QTest::addColumn<QString>("testInputString");
QTest::addColumn<QString>("testOutputString");
QTest::newRow("incomplete") << u"||test"_s << u"||test"_s;
QTest::newRow("complete") << u"||test||"_s << u"<span data-mx-spoiler>test</span>"_s;
QTest::newRow("multiple") << u"||apple||banana||pear||"_s << u"<span data-mx-spoiler>apple</span>banana<span data-mx-spoiler>pear</span>"_s;
}
void TextHandlerTest::sendSpoilerTags()
{
QFETCH(QString, testInputString);
QFETCH(QString, testOutputString);
TextHandler testTextHandler;
testTextHandler.setData(testInputString);
QCOMPARE(testTextHandler.handleSendText(), testOutputString);
}
void TextHandlerTest::receiveSpacelessSelfClosingTag()
{
const QString testInputString = u"Test...<br/>...ing"_s;