aboutsummaryrefslogtreecommitdiff
path: root/Sources/NorgUI/Views/Blocks/BlockView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Sources/NorgUI/Views/Blocks/BlockView.swift')
-rw-r--r--Sources/NorgUI/Views/Blocks/BlockView.swift49
1 files changed, 49 insertions, 0 deletions
diff --git a/Sources/NorgUI/Views/Blocks/BlockView.swift b/Sources/NorgUI/Views/Blocks/BlockView.swift
new file mode 100644
index 0000000..59fcb78
--- /dev/null
+++ b/Sources/NorgUI/Views/Blocks/BlockView.swift
@@ -0,0 +1,49 @@
+import NorgKit
+import SwiftUI
+
+// General block renderer.
+struct BlockView: View {
+ let block: NorgBlock
+ let ordinal: Int?
+ let onSetStatus: (Int, TaskStatus) -> Void
+
+ var body: some View {
+ switch block {
+ case .heading(let level, let status, let content, let line):
+ HeadingView(
+ level: level, status: status, content: content, line: line, onSetStatus: onSetStatus)
+
+ case .paragraph(let content, _):
+ ParagraphView(content: content)
+
+ case .unorderedListItem(_, let status, let content, let line):
+ ListItemView(
+ marker: "•", status: status, content: content, line: line, onSetStatus: onSetStatus)
+
+ case .orderedListItem(_, let status, let content, let line):
+ ListItemView(
+ marker: "\(ordinal ?? 1).", status: status, content: content,
+ line: line, onSetStatus: onSetStatus)
+
+ case .quote(_, let status, let content, let line):
+ QuoteView(status: status, content: content, line: line, onSetStatus: onSetStatus)
+
+ case .codeBlock(let language, let code, _):
+ CodeBlockView(language: language, code: code)
+
+ case .definition(let title, let status, _, let line),
+ .footnote(let title, let status, _, let line),
+ .tableCell(let title, let status, _, let line):
+ RangeableBlockView(title: title, status: status, line: line, onSetStatus: onSetStatus)
+
+ case .rangedTag(let name, _, let content, _):
+ RangedTagView(name: name, content: content)
+
+ case .horizontalRule:
+ Divider()
+
+ case .weakDelimiter, .strongDelimiter:
+ EmptyView()
+ }
+ }
+}