import OrgSwiftUI import SwiftUI /// Renders an issue/MR body or comment in whichever format it was stored as. /// Mirrors `ReadmeView`'s dispatch, keyed on the stored `body_format` rather /// than a file name. A missing format renders as markdown, matching every /// body written before org support existed. struct FormattedBodyView: View { let text: String var format: String? /// The repository `#N` and `!N` refer to; nil links no references. /// The links open through `referenceNavigation()`. var repo: String? @Environment(\.colorScheme) private var colorScheme @Environment(\.dynamicTypeSize) private var dynamicTypeSize @State private var allowance = MathAllowance() var isOrg: Bool { format == "org" } var body: some View { if isOrg { let _ = allowance.reset(for: text) // Qualified: `OrgView` here is org-mode, not the organization view. OrgSwiftUI.OrgView( text, styler: OrgSyntaxStyler(colorScheme: colorScheme), keywords: OrgKeywordStyle(todo: .gbOK, done: .gbDone), textTransform: repo.map { repo in { linkReferences(in: &$0, repo: repo) } }, math: MathRenderer.org(dynamicTypeSize: dynamicTypeSize, allowance: allowance) ) } else { MarkdownView(markdown: text, referenceRepo: repo) } } }