diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-05-08 20:53:10 -0700 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-05-08 20:53:10 -0700 |
| commit | 75b40db9adac93dde9df3ff76bb172c76e3d3a55 (patch) | |
| tree | 1e9088849d7a32ac0f42c933e2b6ab50350ed196 /Hotline/Utility/FoundationExtensions.swift | |
| parent | 01d32910bc1e75533c2f473011296fee6febbadb (diff) | |
Fix about box layout on open. Remove about box from window menu, add expand button to server agreement, add email address highlighting, style server messages, unread badge on admins are red now, play server message sound, some code cleanup.
Diffstat (limited to 'Hotline/Utility/FoundationExtensions.swift')
| -rw-r--r-- | Hotline/Utility/FoundationExtensions.swift | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Hotline/Utility/FoundationExtensions.swift b/Hotline/Utility/FoundationExtensions.swift index 6270ac7..3a325be 100644 --- a/Hotline/Utility/FoundationExtensions.swift +++ b/Hotline/Utility/FoundationExtensions.swift @@ -11,12 +11,22 @@ extension String { let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: self) let matches = self.ranges(of: RegularExpressions.relaxedLink) for match in matches { - attributedString.addAttribute(.link, value: self[match], range: NSRange(match, in: self)) + let matchString = String(self[match]) + if matchString.isEmailAddress() { + attributedString.addAttribute(.link, value: "mailto:\(matchString)", range: NSRange(match, in: self)) + } + else { + attributedString.addAttribute(.link, value: matchString, range: NSRange(match, in: self)) + } // attributedString.addAttribute(.underlineStyle, value: 1, range: NSRange(match, in: self)) } return AttributedString(attributedString) } + func isEmailAddress() -> Bool { + self.wholeMatch(of: RegularExpressions.emailAddress) != nil + } + func isWebURL() -> Bool { guard let url = URL(string: self) else { return false |