Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI

on: pull_request

jobs:
test:
runs-on: macos-15
steps:
- uses: actions/checkout@v4
- run: swift build --build-tests
lint:
runs-on: ubuntu-24.04-arm
container: swift:latest
steps:
- uses: actions/checkout@v4
- run: swift format lint -r -p -s .
18 changes: 18 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Release

on:
push:
tags:
- "*"

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: gh release create ${{ github.ref_name }} --generate-notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ let package = Package(
.macOS(.v13),
.watchOS(.v9),
.tvOS(.v16),
.macCatalyst(.v16)
.macCatalyst(.v16),
],
products: [
.library(
name: "AttributedText",
targets: ["AttributedText"]
),
)
],
targets: [
.target(
name: "AttributedText"
),
)
]
)
10 changes: 8 additions & 2 deletions Sources/AttributedText/AttributedString++.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ import Foundation
import RegexBuilder

extension AttributedStringProtocol {
func range(_ pattern: String, options: String.CompareOptions? = nil) -> Range<AttributedString.Index>? {
func range(
_ pattern: String,
options: String.CompareOptions? = nil
) -> Range<AttributedString.Index>? {
let options = options?.union(.regularExpression) ?? .regularExpression
return self.range(of: pattern, options: options)
}

func ranges(_ pattern: String, options: String.CompareOptions? = nil) -> [Range<AttributedString.Index>] {
func ranges(
_ pattern: String,
options: String.CompareOptions? = nil
) -> [Range<AttributedString.Index>] {
guard let range = range(pattern, options: options) else {
return []
}
Expand Down
19 changes: 10 additions & 9 deletions Sources/AttributedText/AttributedText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct AttributedText: View {

let prefixAction: (String, String) -> Void
let urlAction: ((URL) -> Void)?

public init(
text: String,
prefixes: [AttributedPrefix],
Expand Down Expand Up @@ -63,12 +63,14 @@ public struct AttributedText: View {
}

#Preview {
Preview(text: """
url https://swift.org/
hashtag #Swift
mention @Swift
and &swift
""")
Preview(
text: """
url https://swift.org/
hashtag #Swift
mention @Swift
and &swift
"""
)
.frame(maxWidth: 500, maxHeight: 500)
}

Expand Down Expand Up @@ -116,7 +118,6 @@ public struct Preview: View {
}
}


struct HashtagView: View {
let hashtag: String

Expand Down Expand Up @@ -176,7 +177,7 @@ struct ViewData: Codable, Hashable {

struct WebView: View {
let url: URL

var body: some View {
Text(url.absoluteString)
}
Expand Down