summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-02-17 22:14:19 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-02-17 22:14:19 +0100
commitb8c6c716be9e03376bede0a734dbb815a5e92b93 (patch)
treea19eb5de33b205bfb7e306ca0c91ff420e67aaaa /src/timeline
parentFix crash from logging unset indices (leftover after debugging) (diff)
downloadnheko-b8c6c716be9e03376bede0a734dbb815a5e92b93.tar.xz
Make inline images work a bit better
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/TimelineModel.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 3c33692e..80e73440 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -362,6 +362,8 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
                 const static QRegularExpression replyFallback(
                   "<mx-reply>.*</mx-reply>", QRegularExpression::DotMatchesEverythingOption);
 
+                auto ascent = QFontMetrics(UserSettings::instance()->font()).ascent();
+
                 bool isReply = relations(event).reply_to().has_value();
 
                 auto formattedBody_ = QString::fromStdString(formatted_body(event));
@@ -380,8 +382,14 @@ TimelineModel::data(const mtx::events::collections::TimelineEvents &event, int r
                                 formattedBody_ = formattedBody_.remove(replyFallback);
                 }
 
-                formattedBody_.replace("<img src=\"mxc:&#47;&#47;", "<img src=\"image://mxcImage/");
-                formattedBody_.replace("<img src=\"mxc://", "<img src=\"image://mxcImage/");
+                // TODO(Nico): Don't parse html with a regex
+                const static QRegularExpression matchImgUri(
+                  "(<img [^>]*)src=\"mxc://([^\"]*)\"([^>]*>)");
+                formattedBody_.replace(matchImgUri, "\\1 src=\"image://mxcImage/\\2\"\\3");
+                const static QRegularExpression matchEmoticonHeight(
+                  "(<img data-mx-emoticon [^>]*)height=\"([^\"]*)\"([^>]*>)");
+                formattedBody_.replace(matchEmoticonHeight,
+                                       QString("\\1 height=\"%1\"\\3").arg(ascent));
 
                 return QVariant(utils::replaceEmoji(
                   utils::linkifyMessage(utils::escapeBlacklistedHtml(formattedBody_))));