Site icon TechHype.io

MarkdownUI – Render Markdown text in SwiftUI

MarkdownUI is a Swift package for rendering Markdown in SwiftUI, fully compliant with the CommonMark Spec.

Supported Platforms

You can use MarkdownUI in the following platforms:

Usage

You can create a Markdown view by providing a Markdown-formatted string.

Markdown("You can try **CommonMark** [here](https://spec.commonmark.org/dingus/).")

If you have already parsed a Markdown-formatted string into a CommonMark document, you can initialize a Markdown view with it.

let document = try! Document(
  markdown: "You can try **CommonMark** [here](https://spec.commonmark.org/dingus/)."
)

var body: some View {
  Markdown(document)
}

Alternatively, you can use an embedded DSL to describe the content of a Markdown view.

Markdown {
  Heading(level: 2) {
    "Markdown lists"
  }
  OrderedList {
    "One"
    "Two"
    "Three"
  }
  BulletList {
    "Start a line with a star"
    "Profit!"
  }
}

MarkdownUI installation

You can add MarkdownUI to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Add Packages…
  2. Enter https://github.com/gonzalezreal/MarkdownUI into the Search or Enter Package URL search field
  3. Link MarkdownUI to your application target
MarkdownUI on GitHub: https://github.com/gonzalezreal/MarkdownUI
Platform: iOS
⭐️: 766
Exit mobile version