https://github.com/zijievv/attribuilder
Swift DSL for constructing Attributed Strings with SwiftUI-like syntax
https://github.com/zijievv/attribuilder
attributedstring resultbuilder swift swiftui
Last synced: 3 months ago
JSON representation
Swift DSL for constructing Attributed Strings with SwiftUI-like syntax
- Host: GitHub
- URL: https://github.com/zijievv/attribuilder
- Owner: zijievv
- Created: 2024-07-28T08:52:42.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-07-28T09:19:46.000Z (10 months ago)
- Last Synced: 2024-07-28T10:38:08.790Z (10 months ago)
- Topics: attributedstring, resultbuilder, swift, swiftui
- Language: Swift
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AttriBuilder
`AttriBuilder` is a Swift domain-specific language for constructing `AttributedString`'s with SwiftUI-like syntax.
## Usage
```swift
var body: some View {
VStack {
Text(nestedText)
article
}
.padding()
}@AttributedStringBuilder
private var nestedText: AttributedString {
Group {
"Hello, "
.color(.green)
.italic()
"world"
.underline(.init(pattern: .dot, color: .brown))
.bold()
"!"
.color(.orange)
}
.color(.blue)
.underline(.init(pattern: .dashDot, color: .yellow))
.fontAttribute(.largeTitle)
}@AttributedStringBuilder
private var article: Text {
Paragraph(prefixBlankLines: 0) {
"Voluptate anim consectetur occaecat. Do sit laborum ad enim cillum consequat. Amet ad consectetur voluptate in do dolor elit dolor cillum cillum in."
}
Group {
Paragraph {
"Title3 ullamco tempor ipsum incididunt."
.bold()
}
.url("https://www.apple.com")
.configuring { attributedString in
attributedString.foregroundColor = .orange
}
.underline()
Paragraph(suffixBlankLines: 0) {
"Footnote "
.bold()
"consectetur in voluptate qui. Nisi culpa nisi nisi. Veniam quis adipisicing voluptate Lorem ullamco adipisicing fugiat non sunt irure aliqua laborum dolor est. "
"Ad aute incididunt non est minim exercitation duis labore ad et occaecat duis eu incididunt culpa. "
.italic()
.color(.teal)
"Commodo velit quis anim commodo do."
.bold()
.fontAttribute(.system(.body, design: .monospaced).bold())
}
.fontAttribute(.footnote)
}
.fontAttribute(.system(.title3, design: .rounded))
}
```