FREE TRIAL: Accelerate your app development career with Hacking with Swift+! >>

How to render Markdown content in text

Paul Hudson    @twostraws   

Updated for Xcode 13.0 beta 5

New in iOS 15

SwiftUI has built-in support for rendering Markdown, including bold, italic, links, and more. I feel almost stupid writing this because honestly it takes no work to do – it’s literally built right into SwiftUI’s Text view, so you can write code like this:

VStack {
    Text("This is regular text.")
    Text("* This is **bold** text, this is *italic* text, and this is ***bold, italic*** text.")
    Text("~~A strikethrough example~~")
    Text("`Monospaced works too`")
    Text("Visit Apple: [click here](https://apple.com)")
}

Download this as an Xcode project

Several lines of text appropriately formatted with Markdown styling.

And yes, that link is automatically tappable.

Note: Images aren’t supported.

Hacking with Swift is sponsored by Raycast

SPONSORED Get stuff done faster with Raycast. The Mac app combines the Spotlight experience with third-party services. Create issues in Jira, search pull requests on GitHub, join video calls in Zoom and more. It's accessible via keyboard shortcuts and extendable with scripts. Built for macOS with Swift.

Download for free

Sponsor Hacking with Swift and reach the world's largest Swift community!

Similar solutions…

BUY OUR BOOKS
Buy Pro Swift Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift (Vapor Edition) Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Server-Side Swift (Kitura Edition) Buy Beyond Code

Was this page useful? Let us know!

Average rating: 4.0/5

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.