Fix inline custom emojis in codeblocks

Make sure that custom emojis in inline code blocks are not turned into images.

By calling preprocess text in `texthandler` the whole function can be simplified as it will now never be called on any text inside any code block (which was the reason for all the split stuff previously).

BUG: 477512
This commit is contained in:
James Graham
2023-12-09 14:28:00 +00:00
parent c396024a26
commit d25340bc31
5 changed files with 64 additions and 19 deletions

View File

@@ -188,22 +188,14 @@ QHash<int, QByteArray> CustomEmojiModel::roleNames() const
};
}
QString CustomEmojiModel::preprocessText(const QString &text)
QString CustomEmojiModel::preprocessText(QString text)
{
auto parts = text.split("```"_ls);
bool skip = true;
for (auto &part : parts) {
skip = !skip;
if (skip) {
continue;
}
for (const auto &emoji : std::as_const(m_emojis)) {
part.replace(
emoji.regexp,
QStringLiteral(R"(<img data-mx-emoticon="" src="%1" alt="%2" title="%2" height="32" vertical-align="middle" />)").arg(emoji.url, emoji.name));
}
for (const auto &emoji : std::as_const(m_emojis)) {
text.replace(
emoji.regexp,
QStringLiteral(R"(<img data-mx-emoticon="" src="%1" alt="%2" title="%2" height="32" vertical-align="middle" />)").arg(emoji.url, emoji.name));
}
return parts.join("```"_ls);
return text;
}
QVariantList CustomEmojiModel::filterModel(const QString &filter)