aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 9819fd08c08047c776cf5328a57437fba486bd56 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Norg Keyboard Toolbar

This package provides a toolbar you can use whenever you need to edit norg
files in SwiftUI or UIKit apps. The toolbar provides the following buttons:

The heading button creates a new heading, or increases the heading of the
current level. See this table for examples.

| Starting State | Resulting State |
|----------------|-----------------|
| * ⏐            | ** ⏐            |
| * ⏐ Hello      | ** ⏐ Hello      |
| * Hello ⏐      | * Hello\n* ⏐    |
| Hello ⏐        | Hello\n* ⏐      |

The task button creates a task on a new line, unless it's at the beginning of
a heading or list, in which case it adds the task to the list.

| Starting State | Resulting State |
|----------------|-----------------|
| * ⏐            | * ( ) ⏐         |
| * ⏐ Hello      | * ( ) ⏐ Hello   |
| * Hello ⏐      | * Hello\n- ( )⏐ |
| Hello ⏐        | Hello\n- ( ) ⏐  |
| ~ ⏐            | ~ ( ) ⏐         |

The reverse heading buttons add `---` or `===` in a new line.

The code button adds a `@code` and `@end` block.

## Usage

### SwiftUI

Add the package to your project by including the repo URL with Xcode's package
manager, and import it:

```swift
import SwiftUI
import NorgKeyboardToolbar

struct EditorView: View {
    @State private var draft = ""
    @State private var selection: TextSelection?

    var body: some View {
        TextEditor(text: $draft, selection: $selection)
            .toolbar {
                NorgKeyboardToolbar(text: $draft, selection: $selection)
            }
    }
}
```

`NorgKeyboardToolbar` then places a toolbar above the keyboard (or the bottom
of the screen if a hardware keyboard is connected.) with the buttons described
above.

### UIKit

Add the package to your project by including the repo URL with Xcode's package
manager, and import it:

```swift
import UIKit
import NorgKeyboardToolbar

...

let textView = UITextView()
textView.installNorgKeyboardAccessory()
```

`installNorgKeyboardAccessory` then attaches a toolbar above the keyboard with
the buttons described above.

## Development

A `Justfile` is provided to run common tasks:

- `just build`, build the code.
- `just test`, run tests.
- `just coverage`, view coverage information.
- `just format`, format and apply lint fixes.
- `just lint`, lint the code.