2aaa8eab7b
SwiftUI app for iPhone that connects to a WebDAV server and lists, searches, reads and edits Denote-format notes (.org). Credentials stored in the iOS Keychain. Server configured via a setup screen on first launch.
67 lines
2.0 KiB
Swift
67 lines
2.0 KiB
Swift
import SwiftUI
|
|
|
|
struct OrgContentView: View {
|
|
let content: String
|
|
|
|
private var bodyLines: [String] {
|
|
var lines = content.components(separatedBy: .newlines)
|
|
while !lines.isEmpty && lines.first!.hasPrefix("#+") {
|
|
lines.removeFirst()
|
|
}
|
|
while !lines.isEmpty && lines.first!.isEmpty {
|
|
lines.removeFirst()
|
|
}
|
|
return lines
|
|
}
|
|
|
|
var body: some View {
|
|
LazyVStack(alignment: .leading, spacing: 0) {
|
|
ForEach(Array(bodyLines.enumerated()), id: \.offset) { _, line in
|
|
orgLine(line)
|
|
}
|
|
}
|
|
.padding(.bottom, 40)
|
|
}
|
|
|
|
@ViewBuilder
|
|
private func orgLine(_ line: String) -> some View {
|
|
if line.hasPrefix("**** ") {
|
|
Text(line.dropFirst(5))
|
|
.font(.subheadline.bold())
|
|
.padding(.top, 12)
|
|
.padding(.bottom, 2)
|
|
} else if line.hasPrefix("*** ") {
|
|
Text(line.dropFirst(4))
|
|
.font(.headline)
|
|
.padding(.top, 14)
|
|
.padding(.bottom, 2)
|
|
} else if line.hasPrefix("** ") {
|
|
Text(line.dropFirst(3))
|
|
.font(.title3.bold())
|
|
.padding(.top, 16)
|
|
.padding(.bottom, 4)
|
|
} else if line.hasPrefix("* ") {
|
|
Text(line.dropFirst(2))
|
|
.font(.title2.bold())
|
|
.padding(.top, 20)
|
|
.padding(.bottom, 4)
|
|
} else if line.hasPrefix("#+") {
|
|
EmptyView()
|
|
} else if line.isEmpty {
|
|
Color.clear.frame(height: 12)
|
|
} else if line.hasPrefix("- ") || line.hasPrefix("+ ") {
|
|
HStack(alignment: .top, spacing: 6) {
|
|
Text("•")
|
|
.foregroundStyle(.secondary)
|
|
Text(line.dropFirst(2))
|
|
}
|
|
.font(.body)
|
|
.padding(.vertical, 1)
|
|
} else {
|
|
Text(line)
|
|
.font(.body)
|
|
.padding(.vertical, 1)
|
|
}
|
|
}
|
|
}
|