Last active
May 26, 2023 13:21
-
-
Save mattyoung/5be253f8dc7ac924f23362472c5e3344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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