Overview
The CodeGroup plugin allows you to create tabbed code blocks, perfect for showing the same code in different languages or displaying multiple related files. Each tab can have its own language and syntax highlighting.Installation
Basic Usage
Features
- Multiple Tabs: Display code in multiple tabs
- Syntax Highlighting: Powered by Shiki
- Per-Tab Languages: Each tab can have different language
- Active Tab State: Track which tab is active
- Theme Support: Consistent theming across tabs
Structure
The CodeGroup plugin consists of nested elements:Configuration
Options
Shiki theme for all code blocks in the group
Element Props
code-group-container
ID of the currently active tab
Theme for all code blocks
code-group-content
ID linking content to its tab heading
Programming language for this code block
Commands
addTabItem
Add a new tab to the code group.Keyboard Behavior
- Enter on Tab Heading: Creates a new tab
- Enter in Code Content: Inserts newline (not a new block)
- Backspace: Prevents deletion at content start
- Cmd/Ctrl+A: Selects entire code content
Initial Structure
When created, the plugin initializes with:Custom Rendering
Use Cases
Multi-Language Examples
Show same code in JavaScript, Python, Go, etc.
Related Files
Display multiple files that work together
Before/After
Show code before and after refactoring
API Responses
Different response formats (JSON, XML, etc.)
Best Practices
Clear Tab Names
Clear Tab Names
Use descriptive names for tabs (e.g., “package.json”, “server.ts”)
Consistent Languages
Consistent Languages
Group related code in logical language combinations
Limit Tabs
Limit Tabs
Keep number of tabs reasonable (2-5) for better UX
Match Content
Match Content
Ensure code in different tabs is related or equivalent
Related Plugins
- Code Plugin - For single code blocks
- Tabs Plugin - For general tabbed content