mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 20:48:52 +03:00
parent
e88cfa1b20
commit
bf4d559523
4 changed files with 21 additions and 22 deletions
|
@ -350,11 +350,11 @@ utils::markdownToHtml(const QString &text)
|
||||||
// The buffer is no longer needed.
|
// The buffer is no longer needed.
|
||||||
free((char *)tmp_buf);
|
free((char *)tmp_buf);
|
||||||
|
|
||||||
return QString::fromStdString(html).trimmed();
|
auto result = QString::fromStdString(html).trimmed();
|
||||||
}
|
|
||||||
|
|
||||||
std::string
|
// Strip paragraph tags.
|
||||||
utils::stripHtml(const QString &text)
|
result.replace("<p>", "");
|
||||||
{
|
result.replace("</p>", "");
|
||||||
return text.trimmed().remove(QRegExp("<[^>]*>")).toStdString();
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,10 +204,10 @@ QString
|
||||||
getMessageBody(const RoomMessageT &event)
|
getMessageBody(const RoomMessageT &event)
|
||||||
{
|
{
|
||||||
if (event.content.format.empty())
|
if (event.content.format.empty())
|
||||||
return QString::fromStdString(event.content.body);
|
return QString::fromStdString(event.content.body).toHtmlEscaped();
|
||||||
|
|
||||||
if (event.content.format != common::FORMAT_MSG_TYPE)
|
if (event.content.format != common::FORMAT_MSG_TYPE)
|
||||||
return QString::fromStdString(event.content.body);
|
return QString::fromStdString(event.content.body).toHtmlEscaped();
|
||||||
|
|
||||||
return QString::fromStdString(event.content.formatted_body);
|
return QString::fromStdString(event.content.formatted_body);
|
||||||
}
|
}
|
||||||
|
@ -219,8 +219,4 @@ linkifyMessage(const QString &body);
|
||||||
//! Convert the input markdown text to html.
|
//! Convert the input markdown text to html.
|
||||||
QString
|
QString
|
||||||
markdownToHtml(const QString &text);
|
markdownToHtml(const QString &text);
|
||||||
|
|
||||||
//! Return the plain text version of an html document.
|
|
||||||
std::string
|
|
||||||
stripHtml(const QString &text);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -310,11 +310,12 @@ TimelineItem::TimelineItem(mtx::events::MessageType ty,
|
||||||
auto displayName = Cache::displayName(room_id_, userid);
|
auto displayName = Cache::displayName(room_id_, userid);
|
||||||
auto timestamp = QDateTime::currentDateTime();
|
auto timestamp = QDateTime::currentDateTime();
|
||||||
|
|
||||||
// Generate the html body to rendered.
|
// Generate the html body to be rendered.
|
||||||
auto formatted_body = utils::markdownToHtml(body);
|
auto formatted_body = utils::markdownToHtml(body);
|
||||||
|
|
||||||
// Extract the plain text version for the sidebar.
|
// Escape html if the input is not formatted.
|
||||||
body = QString::fromStdString(utils::stripHtml(formatted_body));
|
if (formatted_body == body.trimmed().toHtmlEscaped())
|
||||||
|
formatted_body = body.toHtmlEscaped();
|
||||||
|
|
||||||
if (ty == mtx::events::MessageType::Emote) {
|
if (ty == mtx::events::MessageType::Emote) {
|
||||||
formatted_body = QString("<em>%1</em>").arg(formatted_body);
|
formatted_body = QString("<em>%1</em>").arg(formatted_body);
|
||||||
|
@ -651,9 +652,7 @@ TimelineItem::markReceived(bool isEncrypted)
|
||||||
void
|
void
|
||||||
TimelineItem::generateBody(const QString &body)
|
TimelineItem::generateBody(const QString &body)
|
||||||
{
|
{
|
||||||
QString content("<span>%1</span>");
|
body_ = new TextLabel(replaceEmoji(body), this);
|
||||||
|
|
||||||
body_ = new TextLabel(content.arg(replaceEmoji(body)), this);
|
|
||||||
body_->setFont(font_);
|
body_->setFont(font_);
|
||||||
body_->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextBrowserInteraction);
|
body_->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextBrowserInteraction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1236,8 +1236,10 @@ toRoomMessage<mtx::events::msg::Emote>(const PendingMessage &m)
|
||||||
auto html = utils::markdownToHtml(m.body);
|
auto html = utils::markdownToHtml(m.body);
|
||||||
|
|
||||||
mtx::events::msg::Emote emote;
|
mtx::events::msg::Emote emote;
|
||||||
emote.body = utils::stripHtml(html);
|
emote.body = m.body.trimmed().toStdString();
|
||||||
emote.formatted_body = html.toStdString();
|
|
||||||
|
if (html != m.body.trimmed().toHtmlEscaped())
|
||||||
|
emote.formatted_body = html.toStdString();
|
||||||
|
|
||||||
return emote;
|
return emote;
|
||||||
}
|
}
|
||||||
|
@ -1261,8 +1263,10 @@ toRoomMessage<mtx::events::msg::Text>(const PendingMessage &m)
|
||||||
auto html = utils::markdownToHtml(m.body);
|
auto html = utils::markdownToHtml(m.body);
|
||||||
|
|
||||||
mtx::events::msg::Text text;
|
mtx::events::msg::Text text;
|
||||||
text.body = utils::stripHtml(html);
|
text.body = m.body.trimmed().toStdString();
|
||||||
text.formatted_body = html.toStdString();
|
|
||||||
|
if (html != m.body.trimmed().toHtmlEscaped())
|
||||||
|
text.formatted_body = html.toStdString();
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue