Added text command for spoilers.

This commit is contained in:
23rd 2021-12-18 16:35:38 +03:00
parent 1819e6e3a5
commit 6b905f7754
2 changed files with 38 additions and 0 deletions

View file

@ -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;

View file

@ -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);