Created
April 25, 2023 22:28
-
-
Save jamesporter/7cb191717af52e45b455de0150f8a7d6 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 String { | |
var asAttributedMarkdown: AttributedString { | |
do { | |
return try AttributedString(markdown: self, options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace)) | |
} catch { | |
return AttributedString(stringLiteral: self) | |
} | |
} | |
} | |
struct AttributedText: View { | |
var text: String | |
init(_ text: String) { | |
self.text = text | |
} | |
var body: some View { | |
Text(text.asAttributedMarkdown) | |
} | |
} | |
struct AttributedText_Previews: PreviewProvider { | |
static var previews: some View { | |
AttributedText("**test** that this *is* \n```var code```") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment