gitbay/Views/Repos/FormattedBodyView.swift
32 lines · 1158 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 /// The repository `#N` and `!N` refer to; nil links no references.
12 /// The links open through `referenceNavigation()`.
13 var repo: String?
14
15 @Environment(\.colorScheme) private var colorScheme
16
17 var isOrg: Bool { format == "org" }
18
19 var body: some View {
20 if isOrg {
21 // Qualified: `OrgView` here is org-mode, not the organization view.
22 OrgSwiftUI.OrgView(
23 text,
24 styler: OrgSyntaxStyler(colorScheme: colorScheme),
25 keywords: OrgKeywordStyle(todo: .gbOK, done: .gbDone),
26 textTransform: repo.map { repo in { linkReferences(in: &$0, repo: repo) } }
27 )
28 } else {
29 MarkdownView(markdown: text, referenceRepo: repo)
30 }
31 }
32}