Created
April 25, 2023 22:28
-
-
Save jamesporter/7cb191717af52e45b455de0150f8a7d6 to your computer and use it in GitHub Desktop.
Revisions
-
jamesporter created this gist
Apr 25, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ 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```") } }