blob: 5020ad8ebc507e23dd98b66e2eb3d0bd3f518902 (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# NorgEditor
NorgEditor provides a syntax-highlighting and indentation aware SwiftUI source
editor for `.norg` / [Neorg](https://github.com/nvim-neorg/neorg) documents, built on
[NorgKit](https://git.sr.ht/~rbdr/norgkit)'s lexer and the [NorgKeyboardToolbar](https://git.sr.ht/~rbdr/norg-keyboard-toolbar) input accessory.
## Installation
Add the package with Xcode package manager: `https://git.r.bdr.sh/norg-editor`,
and depend on `NorgUI` from your target.
## Usage
Bind `NorgEditor` to a `String` of source. It highlights on every keystroke; on
iOS/iPadOS it also installs the Norg keyboard toolbar and keeps the caret above
the keyboard.
```swift
import SwiftUI
import NorgEditor
struct NoteEditor: View {
@Binding var source: String
var body: some View {
NorgEditor(text: $source)
.padding(.horizontal)
}
}
```
## Theming
Highlighting colours and the base font can be changed by creating an
`EditorTheme` aund using the `.norgEditorTheme(_:)` modifier.
```swift
var theme = EditorTheme.default
theme.font = UIFont(name: "IBMPlexMono-Light", size: 14) ?? theme.font
theme.headingColor = { _ in .systemTeal }
theme.linkColor = .systemBlue
NorgEditor(text: $source)
.norgEditorTheme(theme)
```
### EditorTheme API
`PlatformFont` and `PlatformColor` are aliases for `UIFont`/`UIColor` on UIKit
platforms and `NSFont`/`NSColor` on macOS.
| Property | Type | Styles |
| --- | --- | --- |
| `font` | `PlatformFont` | Base font; `bold`/`italic` runs derive traited variants |
| `textColor` | `PlatformColor` | Plain, unstyled source |
| `headingColor` | `(Int) -> PlatformColor` | Heading marker runs (`*`…), per level |
| `markerColor` | `PlatformColor` | List/quote/definition/footnote/table markers, delimiting lines, rules, inline-modifier delimiters, link brackets, escapes |
| `taskStatusColor` | `(TaskStatus) -> PlatformColor` | Task status markers, e.g. `(x)` |
| `tagColor` | `PlatformColor` | Ranged-tag header (`@code …`) and `@end` |
| `verbatimColor` | `PlatformColor` | Inline `` `verbatim` `` and ranged-tag body lines |
| `commentColor` | `PlatformColor` | Inline comments (`%…%`) |
| `linkColor` | `PlatformColor` | Link/anchor locations and descriptions |
| `spoilerColor` | `PlatformColor` | `spoiler` inline runs |
## Requirements
- Swift 6 tools
- iOS 18 / iPadOS 18 / visionOS 2 (UIKit) or macOS 15 (AppKit)
|