Don't render custom emojis in code blocks
BUG: 458993
This commit is contained in:
@@ -26,7 +26,7 @@ using namespace Quotient;
|
|||||||
QString markdownToHTML(const QString &markdown)
|
QString markdownToHTML(const QString &markdown)
|
||||||
{
|
{
|
||||||
const auto str = markdown.toUtf8();
|
const auto str = markdown.toUtf8();
|
||||||
char *tmp_buf = cmark_markdown_to_html(str.constData(), str.size(), CMARK_OPT_HARDBREAKS);
|
char *tmp_buf = cmark_markdown_to_html(str.constData(), str.size(), CMARK_OPT_HARDBREAKS | CMARK_OPT_UNSAFE);
|
||||||
|
|
||||||
const std::string html(tmp_buf);
|
const std::string html(tmp_buf);
|
||||||
|
|
||||||
@@ -137,8 +137,8 @@ void ActionsHandler::handleMessage()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handledText = markdownToHTML(handledText);
|
|
||||||
handledText = CustomEmojiModel::instance().preprocessText(handledText);
|
handledText = CustomEmojiModel::instance().preprocessText(handledText);
|
||||||
|
handledText = markdownToHTML(handledText);
|
||||||
|
|
||||||
if (handledText.length() == 0) {
|
if (handledText.length() == 0) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -163,13 +163,20 @@ QHash<int, QByteArray> CustomEmojiModel::roleNames() const
|
|||||||
|
|
||||||
QString CustomEmojiModel::preprocessText(const QString &text)
|
QString CustomEmojiModel::preprocessText(const QString &text)
|
||||||
{
|
{
|
||||||
auto handledText = text;
|
auto parts = text.split("```");
|
||||||
for (const auto &emoji : std::as_const(m_emojis)) {
|
bool skip = true;
|
||||||
handledText.replace(
|
for (auto &part : parts) {
|
||||||
emoji.regexp,
|
skip = !skip;
|
||||||
QStringLiteral(R"(<img data-mx-emoticon="" src="%1" alt="%2" title="%2" height="32" vertical-align="middle" />)").arg(emoji.url, emoji.name));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return handledText;
|
return parts.join("```");
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantList CustomEmojiModel::filterModel(const QString &filter)
|
QVariantList CustomEmojiModel::filterModel(const QString &filter)
|
||||||
|
|||||||
Reference in New Issue
Block a user