Skip to main content

@lexical/code-highlights

Interfaces​

CodeHighlightsConfig​

Defined in: packages/lexical-code-highlights/src/CodeHighlighterHighlights.ts:173

Properties​

disabled​

disabled: boolean

Defined in: packages/lexical-code-highlights/src/CodeHighlighterHighlights.ts:180

When true, the Highlights 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, Shiki and Highlights highlighters without rebuilding the editor.

tokenizer​

tokenizer: Tokenizer

Defined in: packages/lexical-code-highlights/src/CodeHighlighterHighlights.ts:181


Tokenizer​

Defined in: packages/lexical-code-highlights/src/CodeHighlighterHighlights.ts:40

Properties​

$tokenize​

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

Defined in: packages/lexical-code-highlights/src/CodeHighlighterHighlights.ts:54

Parameters​
this​

Tokenizer

codeNode​

CodeNode

language?​

string

Returns​

LexicalNode[]

defaultLanguage​

defaultLanguage: string | null

Defined in: packages/lexical-code-highlights/src/CodeHighlighterHighlights.ts:48

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-highlights/src/CodeHighlighterHighlights.ts:53

Theme for code blocks that don't carry one, and for those whose theme is not bundled with Highlights.

Variables​

CodeHighlightsExtension​

const CodeHighlightsExtension: LexicalExtension<CodeHighlightsConfig, "@lexical/code-highlights", NamedSignalsOutput<CodeHighlightsConfig>, unknown>

Defined in: packages/lexical-code-highlights/src/CodeHighlighterHighlights.ts:194

Add code highlighting support for code blocks with Highlights.

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.


HighlightsTokenizer​

const HighlightsTokenizer: Tokenizer

Defined in: packages/lexical-code-highlights/src/CodeHighlighterHighlights.ts:68

Functions​

getCodeLanguageOptions()​

getCodeLanguageOptions(): [string, string][]

Defined in: packages/lexical-code-highlights/src/FacadeHighlights.ts:284

Returns​

[string, string][]


getCodeThemeOptions()​

getCodeThemeOptions(): [string, string][]

Defined in: packages/lexical-code-highlights/src/FacadeHighlights.ts:288

Returns​

[string, string][]


isCodeLanguageLoaded()​

isCodeLanguageLoaded(language): boolean

Defined in: packages/lexical-code-highlights/src/FacadeHighlights.ts:188

Whether Highlights has a lexer for language (or for xxx in a diff-xxx language) and its engine has loaded. Every language is built into the engine.

Parameters​

language​

string

Returns​

boolean


isCodeThemeLoaded()​

isCodeThemeLoaded(theme): boolean

Defined in: packages/lexical-code-highlights/src/FacadeHighlights.ts:243

Whether loading theme has finished, successfully or not.

Parameters​

theme​

string

Returns​

boolean


loadCodeLanguage()​

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

Defined in: packages/lexical-code-highlights/src/FacadeHighlights.ts:221

Loads the Highlights engine, which has every language built in. If it is already loaded, failed to load, or language is not supported, the call is a no-op.

When both editor and codeNodeKey are passed, the corresponding CodeNode is marked dirty once the engine has loaded, so that it is highlighted.

Parameters​

language​

string

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

editor?​

LexicalEditor

Lexical editor instance to update after the engine loads.

codeNodeKey?​

string

Key of the CodeNode to re-highlight.

Returns​

Promise<void> | undefined

A Promise that resolves when the engine has loaded (or failed to), or undefined if there was nothing to load.


loadCodeTheme()​

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

Defined in: packages/lexical-code-highlights/src/FacadeHighlights.ts:261

Loads one of the themes bundled with Highlights. If the theme is already loaded or is not bundled, the call is a no-op.

When both editor and codeNodeKey are passed, the corresponding CodeNode is marked dirty once the theme has loaded, so that it is highlighted with it.

Parameters​

theme​

string

theme identifier (e.g. "one-light")

editor?​

LexicalEditor

Lexical editor instance to update after the theme loads.

codeNodeKey?​

string

Key of the CodeNode to re-highlight.

Returns​

Promise<void> | undefined

A Promise that resolves when the theme has loaded (or failed to), or undefined if the theme was already loaded or is not bundled.


normalizeCodeLanguage()​

normalizeCodeLanguage(language): string

Defined in: packages/lexical-code-highlights/src/FacadeHighlights.ts:310

Parameters​

language​

string

Returns​

string


registerCodeHighlighting()​

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

Defined in: packages/lexical-code-highlights/src/CodeHighlighterHighlights.ts:159

Register the Highlights tokenizer-driven highlighting on the editor along with the indent / Tab / arrow-key keyboard handlers. This function is provided for code that does not use extensions; prefer CodeHighlightsExtension.

Parameters​

editor​

LexicalEditor

tokenizer?​

Tokenizer = HighlightsTokenizer

Returns​

() => void