Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Customizing the styling attributes of the bold text in a Markdown attributed string in Swift.
import SwiftUI
import Foundation
struct MarkdownView: View {
var body: some View {
Text(try! AttributedString(markdown: "This is a **basic** _string_.", customBoldColor: .green))
.font(.title)
}
}
extension AttributedString {
init(markdown: String, customBoldColor: Color) throws {
try self.init(markdown: markdown)
for run in runs {
if run.inlinePresentationIntent == .stronglyEmphasized {
self[run.range].foregroundColor = customBoldColor
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment