aboutsummaryrefslogtreecommitdiff
path: root/Sources/NorgUI/Views/Blocks/BlockView.swift
blob: 9889fe9797788ca64b2a74ea4ea8150ff62a72ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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: "✳", showsMarkerWithTask: false, status: status, content: content, line: line,
        onSetStatus: onSetStatus)

    case .orderedListItem(_, let status, let content, let line):
      ListItemView(
        marker: "\(ordinal ?? 1).", showsMarkerWithTask: true, 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()
    }
  }
}