Skip to content

Instantly share code, notes, and snippets.

@mattyoung
Last active May 26, 2023 13:21
Show Gist options
  • Save mattyoung/5be253f8dc7ac924f23362472c5e3344 to your computer and use it in GitHub Desktop.
Save mattyoung/5be253f8dc7ac924f23362472c5e3344 to your computer and use it in GitHub Desktop.
import SwiftUI
extension AttributedString {
// call this init to make all the `code` block highlighted in specific way:
init(codeHightlighted key: String.LocalizationValue) {
var result = AttributedString(localized: key)
let highlight = AttributeContainer.foregroundColor(.red).backgroundColor(.mint)
result.replaceAttributes(AttributeContainer.inlinePresentationIntent(.code), with: highlight)
self = result
}
}
struct MarkdownBacktickHighlight: View {
var body: some View {
VStack {
Text("From this:").underline().padding()
Text(verbatim: "\"This is `back tick enclosed` here\"")
Text("To this:").underline().padding()
Text(AttributedString(codeHightlighted: "This is `back tick enclosed` here"))
}
}
}
struct MarkdownBacktickHighlight_Previews: PreviewProvider {
static var previews: some View {
MarkdownBacktickHighlight()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment