Skip to content

Fix HTML tags rendered as plain text in received notifications - #43

Open
shalin-dev wants to merge 1 commit into
ZorinOS:masterfrom
shalin-dev:fix/html-notification-tags
Open

Fix HTML tags rendered as plain text in received notifications#43
shalin-dev wants to merge 1 commit into
ZorinOS:masterfrom
shalin-dev:fix/html-notification-tags

Conversation

@shalin-dev

Copy link
Copy Markdown

Fixes #17

Problem

When receiving notifications from the desktop, HTML tags (<b>, <i>, <br>, etc.) were displayed as raw text in the Android notification shade instead of being rendered or stripped.

This happens because ReceiveNotificationsPlugin.onPacketReceived() passes the notification ticker text directly to NotificationCompat.Builder without parsing HTML.

Fix

Parse notification text through Html.fromHtml() before passing it to the notification builder. This strips HTML tags and preserves intended formatting (bold, italic) as Spanned text that Android notifications can render natively.

Changes

  • Added import android.text.Html to ReceiveNotificationsPlugin.java
  • Added fromHtml() helper method with API level compatibility (uses FROM_HTML_MODE_COMPACT on API 24+, falls back to deprecated overload on older versions)
  • Applied HTML parsing to the ticker text used in setContentText(), setTicker(), and BigTextStyle.bigText()
  • Early-return optimization: skips HTML parsing when text contains neither < nor & characters
  • Added unit tests covering plain text, HTML tags, entities, malformed HTML, and API level edge cases

Testing

  • Verified fromHtml() logic with 14 unit tests covering: plain text identity, bold/italic/br/p tag stripping, HTML entity decoding, malformed HTML, and empty strings
  • Compiled against Android SDK 35 (API level 35) — no errors
  • Method is package-private static to allow direct unit testing without reflection

Screenshots (expected behavior)

Before: Notification shows <b>Important</b> message as raw text
After: Notification shows Important message with bold styling applied

When receiving notifications from the desktop, HTML tags (<b>, <i>, <br>,
etc.) were displayed as raw text in the Android notification shade instead
of being rendered or stripped.

Parse notification text through Html.fromHtml() before passing it to
NotificationCompat.Builder. This strips HTML tags and preserves intended
formatting (bold, italic) as Spanned text that Android notifications can
render natively.

Fixes ZorinOS#17

Co-authored-by: shalin-dev <shalin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] HTML Tags rendered as plain text

1 participant