Swiftpack.co -  gonzalezreal/MarkdownUI as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Render Markdown text in SwiftUI
.package(url: "https://github.com/gonzalezreal/MarkdownUI.git", from: "0.5.1")


CI contact: @gonzalezreal

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

Supported Platforms

You can use the Markdown SwiftUI view in the following platforms:

  • macOS 11.0+
  • iOS 14.0+
  • tvOS 14.0+

The NSAttributedString extension is available in:

  • macOS 10.12+
  • iOS 11.0+
  • tvOS 11.0+
  • watchOS 3.0+


You can create a Markdown view in SwiftUI by providing a CommonMark document.

    It's very easy to make some words **bold** and other words *italic* with Markdown.

    **Want to experiment with Markdown?** Play with the [reference CommonMark

Markdown text

From Swift 5.4 onwards, you can create a Markdown view using an embedded DSL for the contents.

Markdown {
    Heading(level: 2) {
        "Markdown lists"
    "Sometimes you want numbered lists:"
    List(start: 1) {
    "Sometimes you want bullet points:"
    List {
        "Start a line with a star"
        Item {
            "And you can have sub points:"
            List {
                "Like this"
                "And this"

A Markdown view renders text using a body font appropriate for the current platform. You can choose a different font or customize other properties like the foreground color, code font, or heading font sizes using the markdownStyle(_:) view modifier.

    ## Inline code
    If you have inline code blocks, wrap them in backticks: `var example = true`.
        font: .system(.body, design: .serif),
        codeFontName: "Menlo",
        codeFontSizeMultiple: 0.88

Markdown style

A Markdown view always uses all the available width and adjusts its height to fit its rendered text.

Use the accentColor(_:) view modifier to configure the link color.

Markdown("Play with the [reference CommonMark implementation](https://spec.commonmark.org/dingus/).")

Use modifiers like lineLimit(_:) and truncationMode(_:) to configure how the view handles space constraints.

Markdown("> Knowledge is power, Francis Bacon.")

You can set the alignment of the text by using the multilineTextAlignment(_:) view modifier.

    There are many different ways to style code with CommonMark. If you
    have inline code blocks, wrap them in backticks: `var example = true`.

Text alignment

Using the NSAttributedString Extension

If you are not yet using SwiftUI, you can use the NSAttributedString extension to render Markdown in your app.

let attributedString = NSAttributedString(
    document: #"""
    It's very easy to make some words **bold** and other words *italic* with Markdown.
    style: DefaultMarkdownStyle(font: .system(.body))

Supported Markdown Elements

MarkdownUI uses the CommonMark reference parser and it is fully compliant with the CommonMark Spec.

You can explore all the capabilities of this package in the companion demo project.



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

  1. From the File menu, select Swift Packages › Add Package Dependency…
  2. Enter https://github.com/gonzalezreal/MarkdownUI into the package repository URL text field
  3. Link MarkdownUI to your application target

Other Libraries


Stars: 377
Last commit: 5 hours ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

MarkdownUI 0.5.1
11 weeks ago
  • Fix #39

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API