Skip to main content

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

Pass the plugin to createYooptaEditor; do not pass plugins to <YooptaEditor>.

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, or js to insert

Configuration

Options

string
default:"github-dark"
Shiki theme for syntax highlighting. Popular options: - github-dark - github-light - dracula
  • monokai - nord - tokyo-night
string
default:"javascript"
Default programming language. Supported languages include: - JavaScript, TypeScript - Python, Java, C++, Go, Rust - HTML, CSS, SCSS - JSON, YAML, XML - And 190+ more
object
string[]
default:"['```', 'code', 'js']"
Keyboard shortcuts to trigger the plugin

Element Props

Each code block has the following properties:
string
default:"javascript"
Programming language for syntax highlighting
string
default:"github-dark"
Color theme for the code block

Commands

Use the Blocks namespace for block type changes and CodeCommands (or Elements.updateElement) for code element props:

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

Select a theme that matches your site’s design and provides good contrast
Always specify the language for accurate syntax highlighting
Break long code examples into smaller, focused snippets
Include comments in code to explain complex logic