Skip to main content

@lexical/code-shiki

Interfaces​

CodeShikiConfig​

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:560

Properties​

$tokenize​

$tokenize: TokenizeFn

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:594

Tokenize function. Receives a code node, the resolved language, and a ShikiThemeContext. The default implementation reads the per-node theme via themeContext.resolveTheme(codeNode) and dispatches: a string spec renders inline (single theme), a {light, dark} spec renders as CSS variables (multi-theme, vars-only).

Top-level wins over the deprecated tokenizer's $tokenize; the legacy implementation is consulted only when this field is the exact $defaultShikiTokenize reference. Replacing the reference with a structurally identical function disables the BC fallback.

defaultLanguage​

defaultLanguage: string

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:580

The default language for code blocks that have no explicit language set. Applied via CodeNode.setLanguage on first transform.

Top-level wins over the deprecated tokenizer's defaultLanguage; the legacy value is consulted only when this field equals the framework default (@lexical/code-core's DEFAULT_CODE_LANGUAGE). Setting this field to the framework default value alongside a legacy tokenizer with a custom defaultLanguage will silently route through the tokenizer's value — prefer setting this field directly to avoid the footgun.

defaultTheme​

defaultTheme: string

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:611

Default registry key. Used when a code node's per-node __theme is unset. Should be a key of themes; unknown keys fall back to being treated as a raw Shiki theme id with a development warning.

disabled​

disabled: boolean

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:567

When true, the Shiki code highlighter is not registered on the editor. This signal can be flipped at runtime to enable or disable the highlighter, for example to switch between the Prism and Shiki highlighters without rebuilding the editor.

themes​

themes: Record<string, ShikiThemeSpec>

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:605

Registry of theme specs keyed by string. Per-node __theme and the top-level defaultTheme are looked up here.

Static entries are either a single Shiki theme id (rendered inline) or a {light, dark} pair (rendered as --shiki-light / --shiki-dark CSS variables, no inline color). Function entries (codeNode) => ShikiThemeDef resolve at tokenize time, allowing per-node decisions.

tokenizer​

tokenizer: Tokenizer | null

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:617

Deprecated​

Provide defaultLanguage and $tokenize directly on the config. Kept for backward compatibility with the legacy CodeHighlighterShikiExtension wrapper.


ShikiThemeContext​

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:70

The theme context handed to CodeShikiConfig.$tokenize. Holds the registry, the active default key, and a resolveTheme helper that picks the right entry for a given code node (per-node __theme first, defaultTheme fallback, raw Shiki id with a dev warning for keys missing from the registry).

Properties​

defaultTheme​

defaultTheme: string

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:72

themes​

themes: Record<string, ShikiThemeSpec>

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:71

Methods​

resolveTheme()​

resolveTheme(codeNode): ShikiThemeDef

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:73

Parameters​
codeNode​

CodeNode

Returns​

ShikiThemeDef


Tokenizer​

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:82

Deprecated​

Provide CodeShikiConfig.defaultLanguage and CodeShikiConfig.$tokenize directly. Kept exported for backward compatibility with CodeHighlighterShikiExtension and existing direct callers of registerCodeHighlighting.

Properties​

$tokenize​

$tokenize: (this, codeNode, language?) => LexicalNode[]

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:85

Parameters​
this​

Tokenizer

codeNode​

CodeNode

language?​

string

Returns​

LexicalNode[]

defaultLanguage​

defaultLanguage: string

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:83

defaultTheme​

defaultTheme: string

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:84

Type Aliases​

CodeHighlighterShikiConfig​

CodeHighlighterShikiConfig = Tokenizer

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:704

Deprecated​

Use CodeShikiExtension instead. This type is a flat alias for Tokenizer kept for backward compatibility with CodeHighlighterShikiExtension.


ShikiThemeDef​

ShikiThemeDef = string | { dark: string; light: string; }

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:52

A Shiki theme. A bare string is a single theme id and renders inline as the color / background-color style. A {light, dark} pair renders as --shiki-light / --shiki-dark CSS variables with no inline color, so the consuming page's CSS picks the active scheme.


ShikiThemeSpec​

ShikiThemeSpec = ShikiThemeDef | ((codeNode) => ShikiThemeDef)

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:59

A registry entry. Either a static ShikiThemeDef or a function that resolves to one for a given code node, allowing per-node theme decisions at runtime.

Variables​

CodeHighlighterShikiExtension​

const CodeHighlighterShikiExtension: LexicalExtension<Tokenizer, "@lexical/code-shiki/legacy", unknown, void>

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:717

Deprecated​

Use CodeShikiExtension instead.

This is a thin backward-compatibility shim that preserves the original flat Tokenizer config API. It depends on CodeShikiExtension and routes its configured tokenizer to the underlying extension during init (before CodeShikiExtension builds), so consumers using configExtension(CodeHighlighterShikiExtension, customTokenizer) continue to work without modification.


CodeShikiExtension​

const CodeShikiExtension: LexicalExtension<CodeShikiConfig, "@lexical/code-shiki", NamedSignalsOutput<CodeShikiConfig>, unknown>

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:643

Add code highlighting support for code blocks with Shiki.

CodeExtension is a dependency, so the required CodeNode and CodeHighlightNode nodes are registered automatically. CodeIndentExtension is also a dependency, so Tab / Shift+Tab and the related keyboard handlers are activated automatically. Set tabSize on CodeIndentExtension to enable space-indent outdent.


ShikiTokenizer​

const ShikiTokenizer: Tokenizer

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:95

Functions​

getCodeLanguageOptions()​

getCodeLanguageOptions(): [string, string][]

Defined in: packages/lexical-code-shiki/src/FacadeShiki.ts:120

Returns​

[string, string][]


getCodeThemeOptions()​

getCodeThemeOptions(): [string, string][]

Defined in: packages/lexical-code-shiki/src/FacadeShiki.ts:123

Returns​

[string, string][]


isCodeLanguageLoaded()​

isCodeLanguageLoaded(language): boolean

Defined in: packages/lexical-code-shiki/src/FacadeShiki.ts:39

Parameters​

language​

string

Returns​

boolean


loadCodeLanguage()​

loadCodeLanguage(language, editor?, codeNodeKey?): Promise<void> | undefined

Defined in: packages/lexical-code-shiki/src/FacadeShiki.ts:52

Parameters​

language​

string

editor?​

LexicalEditor

codeNodeKey?​

string

Returns​

Promise<void> | undefined


loadCodeTheme()​

loadCodeTheme(theme, editor?, codeNodeKey?): Promise<void> | undefined

Defined in: packages/lexical-code-shiki/src/FacadeShiki.ts:98

Parameters​

theme​

string

editor?​

LexicalEditor

codeNodeKey?​

string

Returns​

Promise<void> | undefined


normalizeCodeLanguage()​

normalizeCodeLanguage(language): string

Defined in: packages/lexical-code-shiki/src/FacadeShiki.ts:127

Parameters​

language​

string

Returns​

string


registerCodeHighlighting()​

registerCodeHighlighting(editor, tokenizer?): () => void

Defined in: packages/lexical-code-shiki/src/CodeHighlighterShiki.ts:531

Register the Shiki tokenizer-driven highlighting on the editor along with the indent / Tab / arrow-key keyboard handlers. This function is provided for legacy code that has not upgraded to using CodeShikiExtension.

Parameters​

editor​

LexicalEditor

tokenizer?​

Tokenizer = ShikiTokenizer

Returns​

() => void