Overview
The Code plugin provides syntax-highlighted code blocks powered by Shiki. It supports multiple programming languages and themes, making it perfect for technical documentation and tutorials.Installation
Basic Usage
Features
- Syntax Highlighting: Powered by Shiki with accurate highlighting
- 200+ Languages: Support for all major programming languages
- Multiple Themes: Choose from various color themes
- Code Copying: Easy code copying functionality
- Line Numbers: Optional line number display
- Keyboard Shortcuts: Type
```,code, orjsto insert
Configuration
Options
Shiki theme for syntax highlighting. Popular options: -
github-dark - github-light - draculamonokai-nord-tokyo-night
Default programming language. Supported languages include: - JavaScript, TypeScript - Python,
Java, C++, Go, Rust - HTML, CSS, SCSS - JSON, YAML, XML - And 190+ more
Keyboard shortcuts to trigger the plugin
Element Props
Each code block has the following properties:Programming language for syntax highlighting
Color theme for the code block
Commands
Access code commands viaeditor.blocks:
Custom Rendering
Keyboard Behavior
The Code plugin has special keyboard handling:- Enter: Inserts a newline within the code block (not a new block)
- Shift+Enter: Also inserts a newline
- Tab: Inserts tab character (doesn’t switch focus)
Parsers
HTML Serialization
Markdown Serialization
Email Serialization
The plugin provides email-compatible HTML with inline styles for proper rendering in email clients.Extending the Plugin
Custom Theme
With Line Numbers
Use Cases
Documentation
Technical documentation with code examples
Tutorials
Step-by-step coding tutorials
API Reference
API endpoints and code samples
Blog Posts
Technical blog posts with code snippets
Best Practices
Choose Appropriate Theme
Choose Appropriate Theme
Select a theme that matches your site’s design and provides good contrast
Specify Language
Specify Language
Always specify the language for accurate syntax highlighting
Keep Code Concise
Keep Code Concise
Break long code examples into smaller, focused snippets
Add Comments
Add Comments
Include comments in code to explain complex logic
Related Plugins
- CodeGroup Plugin - For tabbed code blocks
- Paragraph Plugin - For text content