67 lines
2.1 KiB
Swift
67 lines
2.1 KiB
Swift
//
|
|
// RenderingBlockView.swift
|
|
// GeminiRenderer
|
|
//
|
|
// Created by Shadowfacts on 7/13/20.
|
|
//
|
|
|
|
import SwiftUI
|
|
import GeminiFormat
|
|
|
|
struct RenderingBlockView: View {
|
|
let block: RenderingBlock
|
|
|
|
@ViewBuilder
|
|
var body: some View {
|
|
switch block {
|
|
case let .text(text):
|
|
Text(verbatim: text)
|
|
.font(.documentBody)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
case let .link(url, text: linkText):
|
|
let text = linkText ?? url.absoluteString
|
|
Text(verbatim: text)
|
|
.font(.documentBody)
|
|
.foregroundColor(.blue)
|
|
.underline()
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
case let .preformatted(text, alt: _):
|
|
ScrollView(.horizontal) {
|
|
Text(verbatim: text)
|
|
.font(.documentBodyPreformatted)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
case let .heading(text, level: level):
|
|
Text(verbatim: text)
|
|
.font(level.font)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
case let .unorderedListItem(text):
|
|
// todo: should this be .firstTextBaseline?
|
|
HStack(alignment: .top, spacing: 4) {
|
|
Text(verbatim: "\u{2022}")
|
|
Text(verbatim: text)
|
|
.font(.documentBody)
|
|
Spacer()
|
|
}.frame(maxWidth: .infinity, alignment: .leading)
|
|
case let .quote(text):
|
|
HStack(spacing: 4) {
|
|
Color.gray
|
|
.frame(width: 4)
|
|
Text(verbatim: text)
|
|
.font(Font.documentBody.italic())
|
|
.foregroundColor(.gray)
|
|
Spacer()
|
|
}.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct RenderingBlockView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
Group {
|
|
RenderingBlockView(block: .text("Some Text"))
|
|
RenderingBlockView(block: .quote("A Quote"))
|
|
}
|
|
}
|
|
}
|