gitbay/Views/Repos/FormattedBodyView.swift
36 lines · 1416 bytes
1 symbol in this file
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 @Environment(\.dynamicTypeSize) private var dynamicTypeSize
17 @State private var allowance = MathAllowance()
18
19 var isOrg: Bool { format == "org" }
20
21 var body: some View {
22 if isOrg {
23 let _ = allowance.reset(for: text)
24 // Qualified: `OrgView` here is org-mode, not the organization view.
25 OrgSwiftUI.OrgView(
26 text,
27 styler: OrgSyntaxStyler(colorScheme: colorScheme),
28 keywords: OrgKeywordStyle(todo: .gbOK, done: .gbDone),
29 textTransform: repo.map { repo in { linkReferences(in: &$0, repo: repo) } },
30 math: MathRenderer.org(dynamicTypeSize: dynamicTypeSize, allowance: allowance)
31 )
32 } else {
33 MarkdownView(markdown: text, referenceRepo: repo)
34 }
35 }
36}