Skip to main content

@lexical/code-shiki

Interfaces​

CodeShikiConfig​

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

Properties​

disabled​

disabled: boolean

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

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.

tokenizer​

tokenizer: Tokenizer

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


Tokenizer​

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

Properties​

$tokenize​

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

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

Parameters​
this​

Tokenizer

codeNode​

CodeNode

language?​

string

Returns​

LexicalNode[]

defaultLanguage​

defaultLanguage: string | null

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

Language to fall back to when a CodeNode doesn't carry one. Set to null to opt out of the implicit fallback — code blocks without a language stay untouched (no data-language attribute, no syntax highlighting) so a markdown round-trip can preserve ``` with no info string.

defaultTheme​

defaultTheme: string

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

Type Aliases​

CodeHighlighterShikiConfig​

CodeHighlighterShikiConfig = Tokenizer

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

Deprecated​

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

Variables​

CodeHighlighterShikiExtension​

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

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

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:483

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:66

Functions​

getCodeLanguageOptions()​

getCodeLanguageOptions(): [string, string][]

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

Returns​

[string, string][]


getCodeThemeOptions()​

getCodeThemeOptions(): [string, string][]

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

Returns​

[string, string][]


isCodeLanguageLoaded()​

isCodeLanguageLoaded(language): boolean

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

Parameters​

language​

string

Returns​

boolean


loadCodeLanguage()​

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

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

Loads a syntax highlighting grammar for the given language via Shiki. If the language is already loaded or is not supported, the call is a no-op.

When both editor and codeNodeKey are passed, the corresponding CodeNode is updated to enable syntax highlighting once the language becomes available

Parameters​

language​

string

language identifier (e.g. "typescript", "diff-js")

editor?​

LexicalEditor

Lexical editor instance to update after the language loads.

codeNodeKey?​

string

Key of the CodeNode to mark as syntax-highlight-supported.

Returns​

Promise<void> | undefined

A Promise that resolves when the language is ready, or undefined if the language was already loaded or is not supported.


loadCodeTheme()​

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

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

Parameters​

theme​

string

editor?​

LexicalEditor

codeNodeKey?​

string

Returns​

Promise<void> | undefined


normalizeCodeLanguage()​

normalizeCodeLanguage(language): string

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

Parameters​

language​

string

Returns​

string


registerCodeHighlighting()​

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

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

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