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)
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -137,8 +137,8 @@ void ActionsHandler::handleMessage()
|
||||
}
|
||||
}
|
||||
|
||||
handledText = markdownToHTML(handledText);
|
||||
handledText = CustomEmojiModel::instance().preprocessText(handledText);
|
||||
handledText = markdownToHTML(handledText);
|
||||
|
||||
if (handledText.length() == 0) {
|
||||
return;
|
||||
|
||||
@@ -163,13 +163,20 @@ QHash<int, QByteArray> CustomEmojiModel::roleNames() const
|
||||
|
||||
QString CustomEmojiModel::preprocessText(const QString &text)
|
||||
{
|
||||
auto handledText = text;
|
||||
for (const auto &emoji : std::as_const(m_emojis)) {
|
||||
handledText.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));
|
||||
auto parts = text.split("```");
|
||||
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));
|
||||
}
|
||||
}
|
||||
return handledText;
|
||||
return parts.join("```");
|
||||
}
|
||||
|
||||
QVariantList CustomEmojiModel::filterModel(const QString &filter)
|
||||
|
||||
Reference in New Issue
Block a user