gemenon

[ACTIVE] The Safari of the Gemini ecosystem
git clone git://git.figbert.com/gemenon.git
Log | Files | Refs

commit 1eea6c24404a9fa58188dffc4d3f6edcef06d328
parent f8b32b7d0b4fb001571c37d89f4b03e6a186bbb1
Author: FIGBERT <figbert@figbert.com>
Date:   Sat,  3 Sep 2022 16:22:39 -0700

Add rudimentary gemtext rendering

Diffstat:
MGemenon.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 2+-
MShared/ContentView.swift | 43++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/Gemenon.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Gemenon.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -15,7 +15,7 @@ "location" : "git://git.figbert.com/swiftgemtext.git", "state" : { "branch" : "main", - "revision" : "51dea98544e75035f72b38a800f0f2caddc96d87" + "revision" : "a76f8784f2764d17cfd8f6ea31361f4465a39a7f" } } ], diff --git a/Shared/ContentView.swift b/Shared/ContentView.swift @@ -14,6 +14,7 @@ struct ContentView: View { @State private var columnVisibility = NavigationSplitViewVisibility.detailOnly @State private var engine = SwiftGemini.GeminiRequestor() + @State private var parser = SwiftGemtext.Gemtext() @State private var response: SwiftGemini.GeminiResponse? var body: some View { @@ -23,9 +24,16 @@ struct ContentView: View { ScrollView { HStack { Spacer() - Text(response?.body?.gemtext ?? "oops") + if response?.body?.gemtext != nil { + VStack(alignment: .leading, spacing: 10) { + renderGemtext() + } + } else { + Text("foo") + } Spacer() } + .padding(.vertical) } } .toolbar { @@ -41,6 +49,39 @@ struct ContentView: View { } } } + + func renderGemtext() -> some View { + ForEach(parser.parse(response!.body!.gemtext!), id: \.self) { line in + switch line { + case .Text(let str): + Text(str) + case .Link(let url, let str): + Link(destination: url) { + if str != nil { + Text(str!) + } else { + Text(url.absoluteString) + } + } + case .PreformattedText(let code, _): + Text(code).monospaced(true) + case .Heading(let level, let str): + if level == 1 { + Text(str).font(.title) + } else if level == 2 { + Text(str).font(.title2) + } else if level == 3 { + Text(str).font(.title3) + } + case .UnorderedList(let str): + Text("ยท \(str)") + case .Quote(let str): + Text("\"\(str)\"") + case .EmptyLine: + EmptyView() + } + } + } } struct ContentView_Previews: PreviewProvider {