Format notifications according to the FreeDesktop specification

This commit is contained in:
Loren Burkholder 2021-02-20 11:52:05 -05:00 committed by Nicolas Werner
parent dcd9b80dde
commit c38c6fe49e
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
1 changed files with 13 additions and 2 deletions

View File

@ -151,15 +151,26 @@ NotificationsManager::notificationClosed(uint id, uint reason)
notificationIds.remove(id); notificationIds.remove(id);
} }
/**
* @param text This should be an HTML-formatted string.
*
* If D-Bus says that notifications can have body markup, this function will
* automatically format the notification to follow the supported HTML subset
* specified at https://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/Markup/
*/
QString QString
NotificationsManager::formatNotification(const QString &text) NotificationsManager::formatNotification(const QString &text)
{ {
static auto capabilites = dbus.call("GetCapabilities").arguments(); static auto capabilites = dbus.call("GetCapabilities").arguments();
for (auto x : capabilites) for (auto x : capabilites)
if (x.toStringList().contains("body-markup")) if (x.toStringList().contains("body-markup"))
return utils::markdownToHtml(text); return QString(text)
.replace("<em>", "<i>")
.replace("</em>", "</i>")
.replace("<strong>", "<b>")
.replace("</strong>", "</b>");
return QTextDocumentFragment::fromHtml(utils::markdownToHtml(text)).toPlainText(); return QTextDocumentFragment::fromHtml(text).toPlainText();
} }
/** /**