Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example of custom styles using Markdown support in SwiftUI Text.
import SwiftUI
import PlaygroundSupport
import Foundation
struct MarkdownView: View {
var body: some View {
Text(try! AttributedString(markdown: "This is a **basic** _string_. Italic bits are red. All the **bold** bits are _coloured_ **green**! And [this is a link!](", customBoldColor: .green, customItalicColor: .red))
extension AttributedString {
init(markdown: String, customBoldColor: Color, customItalicColor: Color) throws {
try self.init(markdown: markdown)
for run in runs {
// Apply different styles for bold and italic text
switch run.inlinePresentationIntent {
case InlinePresentationIntent.stronglyEmphasized:
self[run.range].foregroundColor = customBoldColor
case InlinePresentationIntent.emphasized:
self[run.range].foregroundColor = customItalicColor
// Add underline to links
if != nil {
self[run.range].underlineStyle = .single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment