Code blocks
Code blocks hold plain text and line breaks. Spaces and blank lines are preserved. Unlike ordinary paragraphs, they do not support bold, italic, links, or other inline formatting.
Create a code block
Choose Code Block to turn the current paragraph or heading into a code block. If several blocks are selected, each becomes a separate code block. They are not combined.
Converting text to a code block removes its inline formatting but keeps the text and line breaks. Choose Body or a heading to convert it back. Its lines stay in one paragraph or heading rather than becoming separate paragraphs.
Code blocks cannot be created inside list items yet.
Enter and Shift+Enter
Both Enter and Shift+Enter insert a new line in the same code block. They do not create another block or leave the code block, even on an empty line.
Before: After Enter:
let a = 1;| let a = 1;
|
With text selected inside a code block, Enter replaces the selection with a line break.
Backspace and Delete
Inside a code block, Backspace and Delete remove text normally. Deleting a line break joins the two lines without leaving the block.
At the start or end of a block, the result depends on its neighbor:
| Cursor position | Key | Result |
|---|---|---|
| Start of a code block at the beginning of the document | Backspace | Turn it into a normal paragraph |
| Start of an empty code block | Backspace | Turn it into a normal paragraph without joining the previous block |
| Start of a code block containing text, after a paragraph, heading, or code block | Backspace | Join it to the previous block |
| End of a code block, before a paragraph, heading, or code block | Delete | Join the following block to it |
| Start of a normal paragraph immediately after a code block | Backspace | Join the paragraph to the code block |
Joining blocks keeps the type of the first block and does not insert a space or line break. Text joined into a code block loses its inline formatting. Code joined into a paragraph or heading keeps its line breaks.
For example, pressing Backspace at the start of code after a normal paragraph:
Before: After:
Hello Hello|world
|world
The result is a normal paragraph. With Delete at the end of code followed by a normal paragraph, the result stays a code block.
If a heading follows a code block, Backspace at the heading’s start first turns the heading into a normal paragraph. A second Backspace joins it to the code block.
Word deletion follows the same rules at these boundaries. If text is selected, deletion removes the selection instead.
Paste and input methods
Pasting several lines keeps them in the same code block. Blank lines and a final line break are preserved. Line endings are converted to the editor’s standard newline format.
If you use an input method, you can type several lines of code before confirming. They stay in the same code block as plain text.
You can also select from a paragraph or list item into code. If you delete that selection and the rest of the code joins the paragraph or list item, it keeps its line breaks.
Undo and redo
Use Undo to restore text, formatting, or block types after an edit. Redo reapplies the change. Converting text to a code block can be undone, including the formatting removed during conversion.