Skip to content

Instantly share code, notes, and snippets.

@mortenbekditlevsen
Created June 15, 2019 12:01
Show Gist options
  • Save mortenbekditlevsen/1b8a14224defbaba6b7d9cca572e8910 to your computer and use it in GitHub Desktop.
Save mortenbekditlevsen/1b8a14224defbaba6b7d9cca572e8910 to your computer and use it in GitHub Desktop.
import SwiftUI
struct TextFormatting: ExpressibleByStringLiteral, ExpressibleByStringInterpolation {
struct StringInterpolation: StringInterpolationProtocol {
var output: Text = Text(verbatim: "")
init(literalCapacity: Int, interpolationCount: Int) {
// TODO
}
mutating func appendLiteral(_ literal: String) {
output = output + Text(literal)
}
// append bold text
mutating func appendInterpolation(bold: String) {
output = output + Text(bold).bold()
}
}
var text: Text
init(stringLiteral value: String) {
text = Text(verbatim: value)
}
init(stringInterpolation: StringInterpolation) {
text = stringInterpolation.output
}
}
extension Text {
init(_ html: TextFormatting) {
self = html.text
}
}
let boldly = "boldly"
struct ContentView : View {
var body: some View {
List(0 ..< 5) { item in
Text("To \(bold: boldly) go")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment