-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove images from push notifications, improved UnifiedPush logic (#1400
- Loading branch information
Showing
5 changed files
with
33 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// This Regex should match HTML img tags in the following formats, where the alt text is placed in Group 2 | ||
// <img src="URL" /> | ||
// <img alt="a" src="URL" /> | ||
// <img alt="" src="URL" /> | ||
// <img src="URL" alt="" /> | ||
// <img src="URL" alt="a" /> | ||
// | ||
// See: https://regex101.com/r/rSMP3Z/1 | ||
RegExp imgTag = RegExp(r'<img\s+([^>]*\s)?alt="([^"]*)"(?:\s[^>]*)?\/>|<img\s+([^>]*?)\/>'); | ||
|
||
/// Removes `img` tags from HTML content and replaces them with an italicize version of their alt text, or just the word "image". | ||
String cleanImagesFromHtml(String htmlContent) { | ||
return htmlContent.replaceAllMapped(imgTag, (match) { | ||
if (match.group(2)?.isNotEmpty == true) { | ||
return '<i>${match.group(2)}</i>'; | ||
} | ||
return '<i>image</i>'; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters