mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
code formatting
This commit is contained in:
parent
ed69780d52
commit
5a5f5a8696
@ -81,29 +81,29 @@ struct VideoDescription: View {
|
|||||||
|
|
||||||
// If possibe convert URLs to clickable links
|
// If possibe convert URLs to clickable links
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
@available(macOS 12, *)
|
@available(macOS 12, *)
|
||||||
struct DescriptionWithLinks: View {
|
struct DescriptionWithLinks: View {
|
||||||
let description: String
|
let description: String
|
||||||
let detailsSize: CGSize?
|
let detailsSize: CGSize?
|
||||||
let separators = CharacterSet(charactersIn: " \n")
|
let separators = CharacterSet(charactersIn: " \n")
|
||||||
|
|
||||||
var formattedString: AttributedString {
|
var formattedString: AttributedString {
|
||||||
var attrString = AttributedString(description)
|
var attrString = AttributedString(description)
|
||||||
let words = description.unicodeScalars.split(whereSeparator: separators.contains).map(String.init)
|
let words = description.unicodeScalars.split(whereSeparator: separators.contains).map(String.init)
|
||||||
words.forEach { word in
|
words.forEach { word in
|
||||||
if word.hasPrefix("https://") || word.hasPrefix("http://"), let url = URL(string: String(word)) {
|
if word.hasPrefix("https://") || word.hasPrefix("http://"), let url = URL(string: String(word)) {
|
||||||
if let range = attrString.range(of: word) {
|
if let range = attrString.range(of: word) {
|
||||||
attrString[range].link = url
|
attrString[range].link = url
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return attrString
|
||||||
}
|
}
|
||||||
return attrString
|
|
||||||
}
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Text(formattedString)
|
Text(formattedString)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ViewBuilder var keywords: some View {
|
@ViewBuilder var keywords: some View {
|
||||||
|
Loading…
Reference in New Issue
Block a user