Installation
Usage
The CodeBlock extension is included in the StarterKit by default:Configuration
languageClassPrefix
Prefix for language classes applied to code tags.Adds a prefix to language classes that are applied to code tags.
exitOnTripleEnter
Defines whether the node should be exited on triple enter.Exit the code block when pressing Enter three times.
exitOnArrowDown
Defines whether the node should be exited on arrow down when at the end.Exit the code block when pressing arrow down at the end if there is no node after it.
defaultLanguage
The default language for code blocks.Set a default language for all code blocks.
enableTabIndentation
Enables tab key for indentation in code blocks.When enabled, pressing Tab will insert spaces for indentation instead of changing focus.
tabSize
The number of spaces to use for tab indentation.Number of spaces to insert when pressing Tab (only when enableTabIndentation is true).
HTMLAttributes
Custom HTML attributes to add to the rendered code block element.Custom HTML attributes that should be added to the rendered HTML tag.
Commands
setCodeBlock
Converts the current node to a code block.toggleCodeBlock
Toggles a code block. If the current node is already a code block, it converts it to a paragraph.Keyboard Shortcuts
- Mod-Alt-C: Toggle code block
- Backspace: Remove code block when empty or at start
- Tab: Insert indentation (when enableTabIndentation is true)
- Shift-Tab: Remove indentation (when enableTabIndentation is true)
- Enter: Exit code block on triple enter (when exitOnTripleEnter is true)
- ArrowDown: Exit code block when at end (when exitOnArrowDown is true)
Input Rules
The CodeBlock extension supports Markdown-style input rules:- Type
```followed by a space to create a code block - Type
```followed by a language name and space to create a code block with that language - Type
~~~followed by a space as an alternative syntax
Features
VS Code Paste Support
The extension automatically detects code pasted from VS Code and creates a code block with the correct language.Tab Indentation
WhenenableTabIndentation is enabled, you can use Tab and Shift-Tab to indent and unindent code:
- Tab on a selection: Indents all selected lines
- Shift-Tab on a selection: Unindents all selected lines
- Tab without selection: Inserts indentation at cursor
- Shift-Tab without selection: Removes indentation at cursor