How to make custom Markdown attributes rainbow color text?

WWDC21 What's new in Foundation shows how to make rainbow color text custom Markdown attribute. It only shows the setup but I don't see how to actually color the text, this ends at 37:35.

It only show this setup part:

enum RainbowAttribute: CodableAttributedStringKey, MarkdownDecodableAttributedStringKey {
    enum Value: String, Codable {
        case plain, fun, extreme
    }

    public static var name = "rainbow"
}

extension AttributeScopes {
    struct CaffeAppAttributes: AttributeScope {
        let rainbow: RainbowAttribute
        let swiftUI: SwiftUIAttributes
    }

    var caffeApp: CaffeAppAttributes.Type { CaffeAppAttributes.self }
}

// define a AttributedString with "rainbow: 'extreme'"
let header = AttributedString(localized: "^[Fast & Delicious](rainbow: 'extreme') Food", including: \.caffeApp)

// ?? how to make the rainbow color text?

Anyone know how to actually make the text change color? @Tony_Parker

Hi @young -- the full sample is available here.

2 Likes
Terms of Service

Privacy Policy

Cookie Policy