gitbay/Views/Repos/FormattedBodyView.swift

v1.4.0
gitbay-ios/gitbay/Views/Repos/FormattedBodyView.swift history · blame · raw

28 lines · 894 bytes

 1import OrgSwiftUI
 2import SwiftUI
 3
 4/// Renders an issue/MR body or comment in whichever format it was stored as.
 5/// Mirrors `ReadmeView`'s dispatch, keyed on the stored `body_format` rather
 6/// than a file name. A missing format renders as markdown, matching every
 7/// body written before org support existed.
 8struct FormattedBodyView: View {
 9    let text: String
10    var format: String?
11
12    @Environment(\.colorScheme) private var colorScheme
13
14    var isOrg: Bool { format == "org" }
15
16    var body: some View {
17        if isOrg {
18            // Qualified: `OrgView` here is org-mode, not the organization view.
19            OrgSwiftUI.OrgView(
20                text,
21                styler: OrgSyntaxStyler(colorScheme: colorScheme),
22                keywords: OrgKeywordStyle(todo: .gbOK, done: .gbDone)
23            )
24        } else {
25            MarkdownView(markdown: text)
26        }
27    }
28}