Code blocks

When you want to drop in some code - a snippet of Python, a shell command, a chunk of JSON - put it in a code block. EtherPK highlights it in the right colours for the language and keeps it tidy as you type.

The same three backticks also give you maths and diagrams, which are drawn rather than highlighted - jump to Blocks that draw instead of highlighting if that is what you are after.

Making a code block

Type three backticks ``` and press Enter. EtherPK finishes the block for you: it adds the closing backticks below and drops your cursor on the empty line between them. Once you are out of the block it shows as a tidy shaded panel, with the backticks dimmed back so the code stands out - click back in any time and they brighten for editing.

To get colours, give it a language: type it right after the backticks before you press Enter - ```python , ```ts , ```sql . A new block has no language by default (so no colours until you add one); you can set a default language for the graph in its settings.

You can also type / and choose Code block from the menu.

Need backticks inside your code (say you are writing about markdown)? Open the block with four backticks instead of three. EtherPK matches whatever you use, so the closing fence balances and a three-backtick line sits happily inside.

Choosing the language

The word straight after the opening backticks is the language. Change it any time and the highlighting follows. A wide range of languages and markups are supported; if EtherPK does not recognise one, the code simply shows as plain text on the panel - nothing breaks.

Two words are the exception, and do something else entirely - see Blocks that draw instead of highlighting below.

You can set a default language for new blocks in a graph's settings (the cog on the graphs list). Leave it blank and new blocks start with no language until you pick one.

Blocks that draw instead of highlighting

Two words after the backticks are not languages at all. Instead of colouring the text, they draw it: the block turns into a diagram or a set of equations once your cursor leaves it.

Type this You get
```math Typeset maths (KaTeX)
```mermaid A diagram (Mermaid)

Everything else after the backticks is treated as a language and highlighted as code.

Maths

Open a block with ```math and write LaTeX inside it:

```math
\int_0^\infty e^{-x^2}\,dx = \frac{\sqrt{\pi}}{2}
```

Move your cursor out and the block becomes the typeset equation. Click it - anywhere on it, or on either fence - and you get the LaTeX straight back to edit. Nothing is stored but the text you typed, so the block is still ordinary markdown in your file.

A few things worth knowing:

Maths inside a sentence

For a formula in the middle of a line, wrap it in single dollar signs instead:

The area of a circle of radius $r$ is $\pi r^2$.

The same click-to-edit rule applies: the formula becomes editable text whenever your cursor touches it.

Diagrams

```mermaid works the same way - write Mermaid syntax inside and the block draws itself once your cursor leaves. If the diagram cannot be drawn at all, the block says so rather than disappearing, and your text is untouched.

Code blocks inside a list

Code blocks work inside outliner bullets too. The block lines up neatly one space to the right of the bullet, and everything inside stays aligned there - the opening and closing fences sit in the same column so it all looks balanced. You cannot accidentally push the code further left than its fence, so a block in a list stays valid.

Maths and diagram blocks behave exactly the same way - the bullet stays visible and the block sits to the right of it:

- Gaussian integral
  ```math
  \int_0^\infty e^{-x^2}\,dx = \frac{\sqrt{\pi}}{2}
  ```

The keys, briefly

A note on the editor keys generally

While we are talking about keys, two outliner behaviours changed alongside code blocks:

You can also choose how far each level indents - 2 or 4 spaces - in a graph's settings.