summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-09-13 11:02:54 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-09-13 11:02:54 +0300
commitbf4d559523e956523a617213fa1cc3c36fab24e4 (patch)
tree58155f4efbb364dab13245313d742a846ed6f51e /src/timeline
parentUse <em></em> for m.emote messages (diff)
downloadnheko-bf4d559523e956523a617213fa1cc3c36fab24e4.tar.xz
Strip paragraph tags
fixes #438
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/TimelineItem.cpp11
-rw-r--r--src/timeline/TimelineView.cpp12
2 files changed, 13 insertions, 10 deletions
diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp

index c4abe7cf..cd12207c 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp
@@ -310,11 +310,12 @@ TimelineItem::TimelineItem(mtx::events::MessageType ty, auto displayName = Cache::displayName(room_id_, userid); auto timestamp = QDateTime::currentDateTime(); - // Generate the html body to rendered. + // Generate the html body to be rendered. auto formatted_body = utils::markdownToHtml(body); - // Extract the plain text version for the sidebar. - body = QString::fromStdString(utils::stripHtml(formatted_body)); + // Escape html if the input is not formatted. + if (formatted_body == body.trimmed().toHtmlEscaped()) + formatted_body = body.toHtmlEscaped(); if (ty == mtx::events::MessageType::Emote) { formatted_body = QString("<em>%1</em>").arg(formatted_body); @@ -651,9 +652,7 @@ TimelineItem::markReceived(bool isEncrypted) void TimelineItem::generateBody(const QString &body) { - QString content("<span>%1</span>"); - - body_ = new TextLabel(content.arg(replaceEmoji(body)), this); + body_ = new TextLabel(replaceEmoji(body), this); body_->setFont(font_); body_->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextBrowserInteraction); } diff --git a/src/timeline/TimelineView.cpp b/src/timeline/TimelineView.cpp
index 08d506bf..90e116c1 100644 --- a/src/timeline/TimelineView.cpp +++ b/src/timeline/TimelineView.cpp
@@ -1236,8 +1236,10 @@ toRoomMessage<mtx::events::msg::Emote>(const PendingMessage &m) auto html = utils::markdownToHtml(m.body); mtx::events::msg::Emote emote; - emote.body = utils::stripHtml(html); - emote.formatted_body = html.toStdString(); + emote.body = m.body.trimmed().toStdString(); + + if (html != m.body.trimmed().toHtmlEscaped()) + emote.formatted_body = html.toStdString(); return emote; } @@ -1261,8 +1263,10 @@ toRoomMessage<mtx::events::msg::Text>(const PendingMessage &m) auto html = utils::markdownToHtml(m.body); mtx::events::msg::Text text; - text.body = utils::stripHtml(html); - text.formatted_body = html.toStdString(); + text.body = m.body.trimmed().toStdString(); + + if (html != m.body.trimmed().toHtmlEscaped()) + text.formatted_body = html.toStdString(); return text; }