Add tappable description links and timestamps in iOS

This commit is contained in:
Arkadiusz Fal
2022-08-19 23:55:02 +02:00
parent eeda7a5c6e
commit 97fc8fa4b7
14 changed files with 308 additions and 70 deletions

View File

@@ -499,6 +499,22 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
range: nil
)
let linkRegex = #"(<a\s+(?:[^>]*?\s+)?href=\"[^"]*\">[^<]*<\/a>)"#
let hrefRegex = #"href=\"([^"]*)\">"#
guard let hrefRegex = try? NSRegularExpression(pattern: hrefRegex) else { return description }
description = description.replacingMatches(regex: linkRegex) { matchingGroup in
let results = hrefRegex.matches(in: matchingGroup, range: NSRange(matchingGroup.startIndex..., in: matchingGroup))
if let result = results.first {
if let swiftRange = Range(result.range(at: 1), in: matchingGroup) {
return String(matchingGroup[swiftRange])
}
}
return matchingGroup
}
description = description.replacingOccurrences(
of: "<[^>]+>",
with: "",