Code blocks
A code block is a note whose text is code. Its line breaks are kept, the text is set in a monospaced face and coloured by language. It is still a note, so it can have children, fields, a supertag and its own page.
- Make or remove
- Format ▸ Code Block, ⌥⌘C
- Language
- Format ▸ Code Language…, or the language label on the block
- Typed
- three backticks, a language name, then Space
- Languages
- 17 are coloured, plus Plain text
- Markdown copy
- a fenced block that names the language
Make a code block
Put the caret in a note, or select it, and press ⌥⌘C. The note keeps its text and becomes a code block in Plain text. Press the same keys again, or choose Format ▸ Code Block again, to turn it back into an ordinary note.
Start from any note
Put the caret in the note, or select it. The note can have children and fields.
Make the block
Press ⌥⌘C or choose Format ▸ Code Block. A note with a heading cannot become a code block, so remove the heading first.
Pick the language
Choose Format ▸ Code Language…, or click the language label on the block, and type part of a name. Choose a language to set it.
Choose a language
The language picker is headed “Find a language” and lists every language. Type to narrow it. Each language matches on its name, its identifier and the short names in the table below, so typing “py” finds Python. The language in use has a checkmark. Choosing a language on a note that is not a code block makes it one.
| Language | Also found by typing |
|---|---|
| Plain text | text, txt, plaintext (not coloured) |
| Bash | sh, shell, zsh |
| C | h |
| C++ | c++, cc, cxx, hpp |
| CSS | none |
| Go | golang |
| HTML | htm |
| Java | none |
| JavaScript | js, node, mjs |
| JSON | none |
| Markdown | md |
| Python | py |
| Ruby | rb |
| Rust | rs |
| SQL | none |
| Swift | none |
| TypeScript | ts |
| YAML | yml |
The 17 coloured languages are every row except Plain text.
Type in a code block
Typing works as it does in any note. The keys below change only what a code block needs: Return, Tab and Backspace.
- Return
- Starts a new line inside the block. On an empty last line it ends the block and starts a note below it.
- Tab
- Inserts two spaces. With several lines selected, indents each of them.
- Shift-Tab
- Removes a tab or up to two spaces from the start of each selected line.
- Backspace
- At the very start of the block, turns it back into an ordinary note. The text stays.
- ⌘Return
- Adds a checkbox to the note, or checks and unchecks it. It works in a code block as well.
- Esc
- Selects the note as a block, as it does for any note.
Start a code block by typing
Type three backticks and a language name, such as swift, as the whole text of a note. Then press Space or Return. The fence text goes and the note becomes a code block in that language. One Undo brings the fence text back. A name Superliner does not know makes the block Plain text.
Copy the code
A code block has a Copy button. It copies the code as plain text, without colours, marks or links, and the button reads Copied for a moment.
Combine it
- A code block from the / listType
/where a note can take a command, then choose Code block. It makes the same block as Format ▸ Code Block. - Pasted codePaste several lines into a code block and every line stays. ⌥⇧⌘V pastes the lines as one note.
- Snippets you can findGive a code block the #snippet supertag and a language field, then find it with the palette.
- Code in other toolsThe Markdown copy writes the code between a fence that names its language, so other tools read it as code.
Limits
- A note longer than 45,000 characters, or with more than 1,000 lines, is shown in the code face but not coloured. Its language label says “Too long to colour”.
- A language saved by a newer build shows its name as stored and draws as plain text.
- A note with a heading cannot become a code block.
- Links inside a code block are not clickable.