Skip to main content

@lexical/code-core

Variables

CodeImportExtension

const CodeImportExtension: LexicalExtension<ExtensionConfigBase, "@lexical/code/Import", unknown, unknown>

Defined in: packages/lexical-code-core/src/CodeExtension.ts:78

Experimental

Bundles CodeImportRules together with the runtime CodeExtension.

Deprecated

CodeExtension now registers CodeImportRules (and CoreImportExtension) itself — depend on it directly instead.


CodeImportRules

const CodeImportRules: DOMImportRule<ElementSelectorBuilder<HTMLElement, Record<string, never>>>[]

Defined in: packages/lexical-code-core/src/CodeImportExtension.ts:375

Experimental

Import rules for CodeNode.

Specific class-restricted rules (GitHub raw-file-view detectors) are registered before the generic <table> / <tr> / <td> rules so they win dispatch.

Registered by CodeExtension itself (together with CoreImportExtension and the $installVscodeCodePasteOverlay preprocess), so any editor that uses the code extension can import these shapes through the DOMImportExtension pipeline without further configuration.

Functions

$plainifyCodeContent()

$plainifyCodeContent(text): LexicalNode[]

Defined in: packages/lexical-code-core/src/FlatStructureUtils.ts:245

Plain split of code text into CodeHighlightNodes (with no highlight type) + LineBreakNodes + TabNodes. Used when the tokenizer opts out of a default language so a previously highlighted block still renders its \n / \t as real line breaks / tabs, while staying compatible with the indent / shift-lines handlers that only accept CodeHighlightNode + TabNode + LineBreakNode inside a CodeNode.

Parameters

text

string

Returns

LexicalNode[]


registerCodeGutter()

registerCodeGutter(editor): () => void

Defined in: packages/lexical-code-core/src/CodeGutter.ts:63

Keep the data-gutter attribute of every CodeNode in sync with its line count, so a theme can render line numbers with content: attr(data-gutter).

Both @lexical/code-prism and @lexical/code-shiki register this. In headless mode there is no DOM to write to, so registration is skipped and the returned teardown does nothing.

Parameters

editor

LexicalEditor

The editor whose code blocks should carry a gutter.

Returns

A teardown that removes the listener.

() => void

References

$createCodeHighlightNode

Re-exports $createCodeHighlightNode


$createCodeNode

Re-exports $createCodeNode


$getCodeLineDirection

Re-exports $getCodeLineDirection


$getEndOfCodeInLine

Re-exports $getEndOfCodeInLine


$getFirstCodeNodeOfLine

Re-exports $getFirstCodeNodeOfLine


$getLastCodeNodeOfLine

Re-exports $getLastCodeNodeOfLine


$getStartOfCodeInLine

Re-exports $getStartOfCodeInLine


$isCodeHighlightNode

Re-exports $isCodeHighlightNode


$isCodeNode

Re-exports $isCodeNode


$outdentLeadingSpaces

Re-exports $outdentLeadingSpaces


CodeExtension

Re-exports CodeExtension


CodeHighlightNode

Re-exports CodeHighlightNode


CodeIndentConfig

Re-exports CodeIndentConfig


CodeIndentExtension

Re-exports CodeIndentExtension


CodeNode

Re-exports CodeNode


DEFAULT_CODE_LANGUAGE

Re-exports DEFAULT_CODE_LANGUAGE


SerializedCodeNode

Re-exports SerializedCodeNode