diff --git a/ui/text/text.cpp b/ui/text/text.cpp index 3c02a3c..894cd86 100644 --- a/ui/text/text.cpp +++ b/ui/text/text.cpp @@ -195,6 +195,18 @@ QString textcmdStopSemibold() { return result.append(TextCommand).append(QChar(TextCommandNoSemibold)).append(TextCommand); } +QString textcmdStartSpoiler() { + QString result; + result.reserve(3); + return result.append(TextCommand).append(QChar(TextCommandSpoiler)).append(TextCommand); +} + +QString textcmdStopSpoiler() { + QString result; + result.reserve(3); + return result.append(TextCommand).append(QChar(TextCommandNoSpoiler)).append(TextCommand); +} + const QChar *textSkipCommand(const QChar *from, const QChar *end, bool canLink) { const QChar *result = from + 1; if (*from != TextCommand || result >= end) return from; @@ -212,6 +224,8 @@ const QChar *textSkipCommand(const QChar *from, const QChar *end, bool canLink) case TextCommandNoItalic: case TextCommandUnderline: case TextCommandNoUnderline: + case TextCommandSpoiler: + case TextCommandNoSpoiler: break; case TextCommandLinkIndex: @@ -803,6 +817,24 @@ bool Parser::readCommand() { _lnkIndex = kStringLinkIndexShift + _links.size(); } break; + case TextCommandSpoiler: { + if (!_spoilerIndex) { + createBlock(); + _spoilers.push_back(EntityLinkData{ + .data = QString::number(_spoilers.size() + 1), + .type = EntityType::Spoiler, + }); + _spoilerIndex = _spoilers.size(); + } + } break; + + case TextCommandNoSpoiler: + if (_spoilerIndex == _spoilers.size()) { + createBlock(); + _spoilerIndex = 0; + } + break; + case TextCommandSkipBlock: createSkipBlock(_ptr->unicode(), (_ptr + 1)->unicode()); break; diff --git a/ui/text/text.h b/ui/text/text.h index 973b531..21530a3 100644 --- a/ui/text/text.h +++ b/ui/text/text.h @@ -30,6 +30,8 @@ enum TextCommands { TextCommandLinkIndex = 0x0B, // 0 - NoLink TextCommandLinkText = 0x0C, TextCommandSkipBlock = 0x0D, + TextCommandSpoiler = 0x0E, + TextCommandNoSpoiler = 0x0F, TextCommandLangTag = 0x20, }; @@ -269,4 +271,8 @@ QString textcmdLink(ushort lnkIndex, const QString &text); QString textcmdLink(const QString &url, const QString &text); QString textcmdStartSemibold(); QString textcmdStopSemibold(); + +QString textcmdStartSpoiler(); +QString textcmdStopSpoiler(); + const QChar *textSkipCommand(const QChar *from, const QChar *end, bool canLink = true);