# The editor

Write a page in Edit, where markdown shows formatted as you type and Dunjii saves your changes every 15 seconds.

## View and Edit

Every document has a switch at the bottom of the window. **View** shows the page as it prints. **Edit** opens the same page for writing. A document that prints as pages also has **Layout**, for pictures, washes and page setup: see [Page layout](https://dunjii.com/docs/layout-and-printing/page-layout.md).

![The switch at the bottom of a document, in Edit.](https://dunjii.com/docs-assets/writing/editor-mode-switch.webp)

The switch stays where you leave it: if you are in Edit, the next document you open also opens in Edit. ⌘⇧E on a Mac, Ctrl+Shift+E elsewhere, switches between View and Edit, and ⌘⇧L opens Layout.

In Edit you write markdown, and the editor formats it as you type. Text between `**` shows as bold, a `##` line shows as a heading, a table is a grid you type into, and an image shows the picture. The markdown stays in the file. To see the file as plain text, press ⌥⇧M (Alt+Shift+M); a **Markdown** button appears in the switch to take you back. The syntax is in [Markdown in Dunjii](https://dunjii.com/docs/reference/markdown.md).

Dunjii saves 15 seconds after your first change, and every 15 seconds while you keep typing. It also saves when you switch to View or leave the page, and ⌘S saves at once. While a save runs, the **Edit** button shows a spinner and then a check mark. A crossed-out cloud means you are offline and the change is not saved yet; a warning sign means the save failed.

⌘Z undoes changes made since you opened the document. When there is nothing left to undo, Dunjii shows a message with a link to [version history](https://dunjii.com/docs/your-files/version-history.md), where the earlier versions are.

## Formatting

Select text and a toolbar appears above it: **B** for bold, **I** for italic, **Highlight** and **Link**, plus **Blockquote** and **Callout** where they apply. A button that is already on takes the formatting off.

![The toolbar over two selected words.](https://dunjii.com/docs-assets/writing/editor-selection-toolbar.webp)

The same formatting has keys. On Windows and Linux, use Ctrl for ⌘ and Alt for ⌥.

| Keys            | Does |
| --------------- | ---- |
| ⌘B, ⌘I          | Bold, italic |
| ⌘E              | Inline code |
| ⌘⇧H             | Highlight |
| ⌘⇧X             | Strikethrough |
| ⌘⌥1 to ⌘⌥6      | Heading 1 to 6 |
| ⌘⌥0             | Plain paragraph |
| ⌘⇧8, ⌘⇧7        | Bullet list, numbered list |
| ⌘⇧B             | Blockquote |
| Tab, ⇧Tab       | Indent or outdent a list item |
| ⌥↑, ⌥↓          | Move the line or block up or down |
| ⌘F              | Find and replace in the document |

## Links

Type `[[` and the start of a name. Dunjii lists matching documents in your workspace and pages in your Sourcebooks. Use ↑ and ↓ to pick one, and Enter or Tab to insert it. Type `![[` to pick an image instead.

![Matching pages after typing the start of a name.](https://dunjii.com/docs-assets/writing/editor-link-completion.webp)

```markdown
Owes a favor to [[Eldric Vael]].
Knows [Fireball](https://dunjii.com/sourcebooks/dnd-srd-5.2.1/Spells/Fireball).
```

- `Owes a favor to [[Eldric Vael]].`: A document in your workspace, by name.
- `Knows [Fireball](https://dunjii.com/sourcebooks/dnd-srd-5.2.1/Spells/Fireball).`: A Sourcebook page is written as its full address.

When two of your documents have the same name, Dunjii writes a link to the one you picked by its path, so the link goes to that one.

To make a link from words already on the page, select them and press **Link** in the toolbar. Dunjii wraps them in `[[ ]]` and opens a panel with the words as the page name. Press Enter to keep it. To link to a different page, type that page's name, pick it from the list and press Enter: the words you selected stay as the link text.

```markdown
Owes a favor to [[Eldric Vael|the old scholar]].
```

- `Owes a favor to [[Eldric Vael|the old scholar]].`: Links to Eldric Vael. The page shows "the old scholar".

Every link has a small chain button after it. Press it, or ⌘↵ with the caret inside the link, to open the same panel: change where the link goes, **Open in a new tab**, or **Remove link**. Rest the pointer on a link to see a preview of its page.

## Blocks

A block is a paragraph, heading, list, table, callout or image. Click into one and an icon for it appears in the left margin. Click the icon, or press ⌘/, to open the block's menu. **Block type** turns a paragraph into a heading or a list, or one kind of list into another. Under it are the block's settings: alignment, a drop cap and whether it may split across a page break for a paragraph; width, borders, column widths and scale for a table; a layout for a list.

Dunjii saves these settings in a comment line above the block, which other markdown editors hide:

```markdown
<!-- block: drop-cap keep -->

Takes anyone across the river for two copper and asks no questions after dark.
```

- `<!-- block: drop-cap keep -->`: Drop cap, and Keep together.

On an empty line the icon is a **+**. Click it for the insert menu, or type `/` at the start of the line for the same list from the keyboard: `/table`, `/callout` and so on. The rows under **Insert** add the block at once. The rows under **Choose** open a picker first: **Stat block…** starts from a creature or another NPC ([Stat blocks](https://dunjii.com/docs/writing/stat-blocks.md)), **Image…** adds a picture ([Images](https://dunjii.com/docs/writing/images.md)), and **Random…** draws a line from a table ([Random tables](https://dunjii.com/docs/writing/random-tables.md)).

![The insert menu on an NPC.](https://dunjii.com/docs-assets/writing/editor-insert-menu.webp)

Some document types add rows of their own: a scene adds `/cast`, a card sheet adds `/cards`, and on a shop `/table` writes the stock table.

## Suggested sections

In Edit, a document with a type shows the sections and blocks that type usually has, grayed, at the end of the page. They are not in the file until you add them. A new NPC shows **Stat block**, **Portrait**, **First Impression**, **Voice** and **Secrets**. Each type's sections are listed in [Document types](https://dunjii.com/docs/reference/document-types.md).

![An NPC with First Impression and Voice added, and three suggestions left.](https://dunjii.com/docs-assets/writing/editor-suggested-sections.webp)

Click a row to add it:

- A section adds its heading and a line of sample text, selected, so what you type replaces it.
- A section with no sample text, such as a spell's **Card Description**, opens a box to write in. Press the **Add** button, or leave the box empty to add the heading alone.
- **Stat block** opens a picker: start from a creature in the Sourcebook, from another NPC, or with an empty stat block.
- **Portrait** opens your pictures.

```markdown
## First Impression

- Rope-burned hands, a lantern hooked to her belt

## Voice

"Two copper. Three if it bites."
```

- `- Rope-burned hands, a lantern hooked to her belt`: Click First Impression, then type over the sample line.
- `"Two copper. Three if it bites."`: Voice puts your line in quotes.

A row goes away once the document has that section. To hide the rest, click the arrow in the margin beside the first row (**Hide suggestions**). Click it again (**Show 3 suggestions**) to bring them back. Dunjii remembers this for each document, in this browser.

## Document settings

The **Document settings** button is in the row of buttons at the top right of a document. It lists this document's settings, one line each with the value in use. Click a line to change it.

![Document settings for an NPC, with the Type line open.](https://dunjii.com/docs-assets/writing/document-settings.webp)

**Type** sets what the document is, and writes `type:` in its frontmatter. The first option in the list removes `type:`, and the document then takes its folder's `defaultType`, if the folder has one. While it does, the line reads **NPC (folder)**. A card sheet adds **Cards** ([Card sheets](https://dunjii.com/docs/layout-and-printing/card-sheets.md#settings)), and card and coin sheets add **Paper**, **Margins** and **Footer**. A document that prints as pages sets its paper, margins and footer in **Layout** instead.

In Edit, the **Settings** row at the top of the page shows the same frontmatter. Click **Settings** to open it as text. Properties the type defines, such as an NPC's **Creature Type** and **Category**, appear under it as menus.

```markdown
---
type: npc
creature-type: Humanoid
---
# Orla Fenwick
```

- `type: npc`: Type, in Document settings.
- `creature-type: Humanoid`: Creature Type, in the Settings row.
