Search code examples
htmlswifttextmarkdownswiftui

How to show HTML or Markdown in a SwiftUI Text?


How can I set a SwiftUI Text to display rendered HTML or Markdown?

Something like this:

Text(HtmlRenderedString(fromString: "<b>Hi!</b>"))

or for MD:

Text(MarkdownRenderedString(fromString: "**Bold**"))

Perhaps I need a different View?


Solution

  • Text can just display Strings. You can use a UIViewRepresentable with an UILabel and attributedText.

    Probably attributedText text support will come later for SwiftUI.Text.