@lexical/html
Interfaces
AttrMatchOptions
Defined in: packages/lexical-html/src/import/types.ts:71
Experimental
Options bag for ElementSelectorBuilder.attr when the value is a regex. Future options will be added here without breaking existing call-sites.
Type Parameters
K
K extends string = string
Properties
capture?
readonlyoptionalcapture?:K
Defined in: packages/lexical-html/src/import/types.ts:77
Experimental
If provided, the RegExpMatchArray from the successful match is
stored on ctx.captures[capture] for the importer to consume — saving
a second regex execution.
ChildSchema
Defined in: packages/lexical-html/src/import/types.ts:290
Experimental
A ChildSchema encodes which lexical nodes a parent accepts as
children and how to package or reject the rest. The legacy
wrapContinuousInlines / ArtificialNode__DO_NOT_USE logic is the
BlockSchema and NestedBlockSchema cases of this primitive.
Properties
name?
readonlyoptionalname?:string
Defined in: packages/lexical-html/src/import/types.ts:292
Experimental
Optional name for debug output.
onReject?
readonlyoptionalonReject?:"drop"|"hoist"
Defined in: packages/lexical-html/src/import/types.ts:310
Experimental
Strategy for non-accepted children when packageRun is missing or
returns an empty array. 'hoist' lifts them up as siblings of the
parent; 'drop' silently removes them.
Methods
accepts()
accepts(
child,parent):boolean
Defined in: packages/lexical-html/src/import/types.ts:294
Experimental
Returns true if child is a valid child of parent in this position.
Parameters
child
parent
LexicalNode | null
Returns
boolean
finalize()?
optionalfinalize(children,parent):LexicalNode[]
Defined in: packages/lexical-html/src/import/types.ts:316
Experimental
Final pass over the assembled child list (after packageRun). Returns
the children to actually attach. Use to enforce structural invariants
(e.g. drop empty runs, pad short table rows).
Parameters
children
parent
LexicalNode | null
Returns
packageRun()?
optionalpackageRun(rejected,parent,domParent):LexicalNode[]
Defined in: packages/lexical-html/src/import/types.ts:300
Experimental
Package a maximal run of non-accepted siblings into zero or more accepted nodes. If omitted, ChildSchema.onReject is consulted instead.
Parameters
rejected
parent
LexicalNode | null
domParent
Node | null
Returns
CompiledSelector
Defined in: packages/lexical-html/src/import/types.ts:37
Experimental
An opaque, compiled selector used as the match field of a
DOMImportRule. The two phantom type parameters carry the matched
Node subtype (N) and a record of named regex captures (C) so the
importer body gets correctly-typed ctx and node arguments without
casts.
Extended by
Type Parameters
N
N extends Node = Node
C
C extends Record<string, RegExpMatchArray> = Record<string, RegExpMatchArray>
Properties
[CaptureBrand]?
readonlyoptional[CaptureBrand]?:C
Defined in: packages/lexical-html/src/import/types.ts:42
Experimental
[NodeBrand]?
readonlyoptional[NodeBrand]?:N
Defined in: packages/lexical-html/src/import/types.ts:41
Experimental
DOMImportConfig
Defined in: packages/lexical-html/src/import/DOMImportExtension.ts:41
Experimental
Configuration for DOMImportExtension.
Properties
contextDefaults
readonlycontextDefaults: readonlyImportContextPairOrUpdater[]
Defined in: packages/lexical-html/src/import/DOMImportExtension.ts:57
Experimental
Default context pairs applied to every $generateNodesFromDOM call.
Per-call overrides can be supplied via
GenerateNodesFromDOMOptions.context.
preprocess
readonlypreprocess: readonlyDOMPreprocessFn[]
Defined in: packages/lexical-html/src/import/DOMImportExtension.ts:70
Experimental
Functions run in order on the DOM before walking begins, mutating in
place. The default config registers
inlineStylesFromStyleSheets (resolves <style> rules to
inline styles so the rules' style-driven matchers see them); apps
append additional preprocessors (e.g. strip unsafe elements,
normalize attributes, resolve relative URLs).
mergeConfig appends, so each contributing extension's preprocessors
run in dependency order. Per-call preprocessors registered via
GenerateNodesFromDOMOptions.preprocess run AFTER these.
rules
readonlyrules: readonlyAnyDOMImportRule[]
Defined in: packages/lexical-html/src/import/DOMImportExtension.ts:51
Experimental
The set of DOMImportRules contributed by this extension and its
dependencies. Rules are dispatched in priority order: rules contributed
by extensions merged later (i.e. closer to the editor root) run first
and may call $next() to delegate to lower-priority rules.
mergeConfig prepends partial.rules to existing rules, so later
configuration carries higher priority.
DOMImportContext
Defined in: packages/lexical-html/src/import/types.ts:199
Experimental
Context exposed to a rule's $import function. Mirrors the existing render
context (see RenderContext) but is import-scoped.
Type Parameters
C
C extends Record<string, RegExpMatchArray> = Record<string, never>
Properties
captures
readonlycaptures:Readonly<C>
Defined in: packages/lexical-html/src/import/types.ts:205
Experimental
Captures from this rule's selector. Fresh per rule invocation.
editor
readonlyeditor:LexicalEditor
Defined in: packages/lexical-html/src/import/types.ts:203
Experimental
The editor driving this import.
session
readonlysession:ImportSession
Defined in: packages/lexical-html/src/import/types.ts:214
Experimental
Mutable, document-order-shared store. Use to make information from
earlier-visited nodes available to later-visited ones (e.g. a
<style> or <meta> at the top of the document influencing how
later elements are interpreted). One ImportSession instance
is created per top-level $generateNodesFromDOM call and is shared
across all recursive $importChildren / $importOne invocations.
Methods
$importChildren()
$importChildren(
parent,opts?):LexicalNode[]
Defined in: packages/lexical-html/src/import/types.ts:225
Experimental
Recursively import every child of parent and return the produced
lexical nodes, optionally enforcing a ChildSchema and/or
branching the import context for the duration of the call (via
opts.context).
Parameters
parent
ParentNode
opts?
Returns
$importOne()
$importOne(
node,opts?):LexicalNode[]
Defined in: packages/lexical-html/src/import/types.ts:230
Experimental
Recursively import a single DOM node.
Parameters
node
Node
opts?
Returns
get()
get<
V>(cfg):V
Defined in: packages/lexical-html/src/import/types.ts:217
Experimental
Read a typed context value.
Type Parameters
V
V
Parameters
cfg
Returns
V
DOMImportExtensionOutput
Defined in: packages/lexical-html/src/import/types.ts:437
Experimental
Output of DOMImportExtension.
Methods
$generateNodesFromDOM()
$generateNodesFromDOM(
dom,options?):LexicalNode[]
Defined in: packages/lexical-html/src/import/types.ts:446
Experimental
Convert a Document or ParentNode into lexical nodes, using the dispatcher compiled from this extension's configured DOMImportRules.
Must be called within an editor.update() or editor.read() because
the importers may invoke $create... helpers.
Parameters
dom
Document | ParentNode
options?
Returns
DOMImportRule
Defined in: packages/lexical-html/src/import/types.ts:341
Experimental
An importer for a DOM node, dispatched by match and implemented by
$import.
Type Parameters
S
S extends CompiledSelector = CompiledSelector
Properties
$import
readonly$import:DOMImportFn<NodeOfSelector<S>,CapturesOfSelector<S>>
Defined in: packages/lexical-html/src/import/types.ts:351
Experimental
Middleware that converts the matched DOM node into lexical nodes.
match
readonlymatch:S
Defined in: packages/lexical-html/src/import/types.ts:349
Experimental
A CompiledSelector produced by the sel builder.
name?
readonlyoptionalname?:string
Defined in: packages/lexical-html/src/import/types.ts:347
Experimental
Optional identifier surfaced in dev-mode logs, error messages, and
introspection devtools. Convention: '@scope/package/rule-id' for
library rules.
DOMPreprocessContext
Defined in: packages/lexical-html/src/import/types.ts:369
Experimental
Context exposed to a DOMPreprocessFn. Lets the preprocessor:
- Read editor state via DOMPreprocessContext.editor.
- Write to the per-import ImportSession (the same
ctx.sessionrules see during the walk). - Layer context pairs that become visible to the entire walk via DOMPreprocessContext.setContext.
Properties
editor
readonlyeditor:LexicalEditor
Defined in: packages/lexical-html/src/import/types.ts:371
Experimental
The editor driving this import.
session
readonlysession:ImportSession
Defined in: packages/lexical-html/src/import/types.ts:378
Experimental
Document-order-shared store, same instance as ctx.session in
rules. Use to pass info from the DOM preprocess phase (e.g.
inspected <meta> tags, collected <style> text) to the
importer rules.
Methods
setContext()
setContext<
V>(cfg,value):void
Defined in: packages/lexical-html/src/import/types.ts:385
Experimental
Layer a context pair into the import context for the rest of the
import (i.e. visible to rule $import functions and child
$importChildren calls). Later calls override earlier ones for
the same ImportStateConfig.
Type Parameters
V
V
Parameters
cfg
value
V
Returns
void
DOMRenderConfig
Defined in: packages/lexical-html/src/types.ts:128
Experimental
Configuration for DOMRenderExtension
Properties
contextDefaults
contextDefaults:
AnyRenderStateConfigPairOrUpdater[]
Defined in: packages/lexical-html/src/types.ts:149
Experimental
Default context to provide in all exports, the configurations are created with createRenderState and should be created at the module-level.
Only specify these if overriding the default value globally, since each configuration has a built-in default value that will be used if not already present in the context.
overrides
overrides:
AnyDOMRenderMatch[]
Defined in: packages/lexical-html/src/types.ts:140
Experimental
DOMRenderMatch overrides to customize node behavior, the final priority of these will be based on the following criteria:
- Wildcards (
'*') have highest priority - Predicates (
$isParagraphNode) have next priority - Subclasses have higher priority (e.g.
ParagraphNodebeforeElementNode) - Extensions closer to the root have higher priority
- Extensions depended on later have higher priority
- Overrides defined later have higher priority
DOMRenderExtensionOutput
Defined in: packages/lexical-html/src/types.ts:91
Experimental
DOMRenderMatch
Defined in: packages/lexical-html/src/types.ts:186
Experimental
Used to define overrides for the render and export
behavior for nodes matching the nodes predicate.
All of these overrides are in a middleware style where you may use the
result of $next() to enhance the result of the default implementation
(or a lower priority override) by calling it and manipulating the result,
or you may choose not to call $next() to entirely replace the behavior.
It is not permitted to update the lexical editor state during any of these calls, you should only be doing read-only operations.
Type Parameters
T
T extends LexicalNode
Properties
$createDOM?
optional$createDOM?: (node,$next,editor) =>HTMLElement
Defined in: packages/lexical-html/src/types.ts:230
Experimental
Called during the reconciliation process to determine which nodes
to insert into the DOM for this Lexical Node. This is also the default
implementation of $exportDOM for most nodes.
This method must return exactly one HTMLElement.
Nested elements are not supported except with DecoratorNode
(which have unmanaged contents) or ElementNode using an appropriate
$getDOMSlot return value.
Parameters
node
T
The LexicalNode
$next
() => HTMLElement
Call the next implementation
editor
The editor
Returns
HTMLElement
The HTMLElement for this node to be rendered in the editor
$decorateDOM?
optional$decorateDOM?: (nextNode,prevNode,dom,editor) =>void
Defined in: packages/lexical-html/src/types.ts:281
Experimental
Called after a node is created or updated and should make any in-place
updates to the DOM in whatever way is necessary to make it align with
any changes that might have happened during the $createDOM or
$updateDOM. This also runs after any children have been reconciled.
Use this when you have code that you would need to duplicate in both methods, or if there is a need to ensure that the children are also reconciled before performing this in-place update.
Unlike other overrides, all applicable $decorateDOM functions are
called unconditionally. There is no $next argument, because there
are no known use cases for avoiding the next implementation and due
to the void return value it would be error-prone and add boilerplate
to require calling it.
The ordering here is equivalent to an implicit $next call first.
Parameters
nextNode
T
The current version of this node
prevNode
T | null
The previous version of this node if $updateDOM returned false, or null if $createDOM was just called
dom
HTMLElement
The previously rendered HTMLElement for this node
editor
The editor
Returns
void
$exportDOM?
optional$exportDOM?: (node,$next,editor) =>DOMExportOutput
Defined in: packages/lexical-html/src/types.ts:300
Experimental
Controls how the this node is serialized to HTML. This is important for copy and paste between Lexical and non-Lexical editors, or Lexical editors with different namespaces, in which case the primary transfer format is HTML. It's also important if you're serializing to HTML for any other reason via $generateHtmlFromNodes.
Parameters
node
T
The LexicalNode
$next
() => DOMExportOutput
Call the next implementation
editor
The editor
Returns
A DOMExportOutput structure that defines how the node should be exported to HTML
$extractWithChild?
optional$extractWithChild?: (node,childNode,selection,destination,$next,editor) =>boolean
Defined in: packages/lexical-html/src/types.ts:366
Experimental
Return true if this node should be included in the export based on
childNode, even if it would not otherwise be included based on its
$shouldInclude result.
Typically used to ensure that required wrapping nodes are always present with its children, e.g. a ListNode when some of its ListItemNode children are selected.
This has higher precedence than $extractWithChild and lower precedence
than $shouldExclude.
Parameters
node
T
The lexical node
childNode
A child of this lexical node
selection
BaseSelection | null
The current selection
destination
"clone" | "html"
Currently always 'html'
$next
() => boolean
The next implementation
editor
The editor
Returns
boolean
true if this
$getDOMSlot?
optional$getDOMSlot?: <N>(node,dom,$next,editor) =>ElementDOMSlot<HTMLElement>
Defined in: packages/lexical-html/src/types.ts:208
Experimental
Control where an ElementNode's children are inserted into the DOM, this is useful to add a wrapping node or accessory nodes before or after the children. The root of the node returned by createDOM must still be exactly one HTMLElement.
Generally you will call $next() to get an ElementDOMSlot and then use
its methods to create a new one.
Type Parameters
N
N extends LexicalNode
Parameters
node
N
The LexicalNode
dom
HTMLElement
The rendered HTMLElement
$next
() => ElementDOMSlot<HTMLElement>
Call the next implementation
editor
The editor
Returns
ElementDOMSlot<HTMLElement>
The ElementDOMSlot for this node
$shouldExclude?
optional$shouldExclude?: (node,selection,$next,editor) =>boolean
Defined in: packages/lexical-html/src/types.ts:318
Experimental
Equivalent to ElementNode.excludeFromCopy, if it returns true this
lexical node will not be exported to DOM (but if it's an ElementNode
its children may still be inserted in its place).
Has higher precedence than $shouldInclude and $extractWithChild.
Parameters
node
T
The LexicalNode
selection
BaseSelection | null
The current selection
$next
() => boolean
The next implementation
editor
The editor
Returns
boolean
true to exclude this node, false otherwise
$shouldInclude?
optional$shouldInclude?: (node,selection,$next,editor) =>boolean
Defined in: packages/lexical-html/src/types.ts:340
Experimental
Return true if this node should be included in the export, typically based
on the current selection (all nodes by default are included when there
is no selection).
The default implementation is equivalent to
selection ? node.isSelected(selection) : true.
This has lower precedence than $extractWithChild and $shouldExclude.
Parameters
node
T
The current node
selection
BaseSelection | null
The current selection
$next
() => boolean
The next implementation
editor
The editor
Returns
boolean
true if this node should be included in the export, false otherwise
$updateDOM?
optional$updateDOM?: (nextNode,prevNode,dom,$next,editor) =>boolean
Defined in: packages/lexical-html/src/types.ts:251
Experimental
Called when a node changes and should update the DOM in whatever way is necessary to make it align with any changes that might have happened during the update.
Returning true here will cause lexical to unmount and recreate the DOM
node (by calling $createDOM). You would need to do this if the element
tag changes, for instance.
Parameters
nextNode
T
The current version of this node
prevNode
T
The previous version of this node
dom
HTMLElement
The previously rendered HTMLElement for this node
$next
() => boolean
Call the next implementation
editor
The editor
Returns
boolean
false if no update needed or was performed in-place, true if $createDOM should be called to re-create the node
nodes
readonlynodes:"*"| readonlyNodeMatch<T>[]
Defined in: packages/lexical-html/src/types.ts:192
Experimental
'*' for all nodes, or an array of NodeClass | $isNodeGuard to match
nodes more specifically. Using classes is more efficient, but will
also target subclasses.
ElementSelectorBuilder
Defined in: packages/lexical-html/src/import/types.ts:99
Experimental
Fluent builder for an element selector. The two type parameters carry the matched element type and the named-capture map; each call refines them.
The builder itself implements CompiledSelector so it can be used
directly as the match field of a rule — no .build() call needed.
Extends
CompiledSelector<E,C>
Type Parameters
E
E extends HTMLElement
C
C extends Record<string, RegExpMatchArray> = Record<string, never>
Properties
[CaptureBrand]?
readonlyoptional[CaptureBrand]?:C
Defined in: packages/lexical-html/src/import/types.ts:42
Experimental
Inherited from
CompiledSelector.[CaptureBrand]
[NodeBrand]?
readonlyoptional[NodeBrand]?:E
Defined in: packages/lexical-html/src/import/types.ts:41
Experimental
Inherited from
Methods
attr()
Call Signature
attr(
name,value):ElementSelectorBuilder<E,C>
Defined in: packages/lexical-html/src/import/types.ts:108
Experimental
Require the attribute to be present (any value).
Parameters
name
string
value
true
Returns
ElementSelectorBuilder<E, C>
Call Signature
attr(
name,value):ElementSelectorBuilder<E,C>
Defined in: packages/lexical-html/src/import/types.ts:110
Experimental
Require the attribute to equal the given string.
Parameters
name
string
value
string
Returns
ElementSelectorBuilder<E, C>
Call Signature
attr<
O>(name,value,options?):ElementSelectorBuilder<E,Oextendsobject?C&Record<K&string,RegExpMatchArray> :C>
Defined in: packages/lexical-html/src/import/types.ts:116
Experimental
Require the attribute to match the given regex. With
{capture: 'name'} the match result is exposed on
ctx.captures.name.
Type Parameters
O
O extends AttrMatchOptions<string>
Parameters
name
string
value
RegExp
options?
O
Returns
ElementSelectorBuilder<E, O extends object ? C & Record<K & string, RegExpMatchArray> : C>
classAll()
classAll(...
classes):ElementSelectorBuilder<E,C>
Defined in: packages/lexical-html/src/import/types.ts:104
Experimental
Require every listed class to be present on the element.
Parameters
classes
...readonly string[]
Returns
ElementSelectorBuilder<E, C>
classAny()
classAny(...
classes):ElementSelectorBuilder<E,C>
Defined in: packages/lexical-html/src/import/types.ts:106
Experimental
Require at least one of the listed classes to be present.
Parameters
classes
...readonly string[]
Returns
ElementSelectorBuilder<E, C>
styleAny()
Call Signature
styleAny(
prop,value):ElementSelectorBuilder<E,C>
Defined in: packages/lexical-html/src/import/types.ts:125
Experimental
Require the inline-style declaration to equal value.
Parameters
prop
string
value
string
Returns
ElementSelectorBuilder<E, C>
Call Signature
styleAny<
O>(prop,value,options?):ElementSelectorBuilder<E,Oextendsobject?C&Record<K&string,RegExpMatchArray> :C>
Defined in: packages/lexical-html/src/import/types.ts:127
Experimental
Require the inline-style declaration to match value.
Type Parameters
O
O extends StyleMatchOptions<string>
Parameters
prop
string
value
RegExp
options?
O
Returns
ElementSelectorBuilder<E, O extends object ? C & Record<K & string, RegExpMatchArray> : C>
GenerateNodesFromDOMOptions
Defined in: packages/lexical-html/src/import/types.ts:418
Experimental
Per-call options to the extension's $generateNodesFromDOM.
Properties
context?
readonlyoptionalcontext?: readonlyImportContextPairOrUpdater[]
Defined in: packages/lexical-html/src/import/types.ts:423
Experimental
Context pairs/updaters applied for the duration of this import only — use to communicate per-call info such as the ImportSource.
preprocess?
readonlyoptionalpreprocess?: readonlyDOMPreprocessFn[]
Defined in: packages/lexical-html/src/import/types.ts:429
Experimental
Additional preprocessors to run on this call only, on top of the extension's configured DOMImportConfig.preprocess. Per-call preprocessors run AFTER the configured ones.
ImportChildrenOpts
Defined in: packages/lexical-html/src/import/types.ts:241
Experimental
Options accepted by DOMImportContext.$importChildren. The combination
of schema, $onChild, and $after is sufficient to express every
child-handling pattern in the legacy forChild / after / wrap-continuous
machinery.
Properties
$after?
readonlyoptional$after?: (children) =>LexicalNode[]
Defined in: packages/lexical-html/src/import/types.ts:259
Experimental
Called once with the full child array after all DOM children have been
recursively imported but before ChildSchema.packageRun is
applied. Equivalent to the old after hook.
Parameters
children
Returns
$onChild?
readonlyoptional$onChild?: (child) =>LexicalNode|null|undefined
Defined in: packages/lexical-html/src/import/types.ts:253
Experimental
Called for each produced lexical child immediately after its rule
returned, with the chance to substitute or drop it. Equivalent to the
old forChild hook but scoped to one $importChildren call.
Parameters
child
Returns
LexicalNode | null | undefined
context?
readonlyoptionalcontext?: readonlyImportContextPairOrUpdater[]
Defined in: packages/lexical-html/src/import/types.ts:261
Experimental
Context overrides scoped to the children traversal.
rules?
readonlyoptionalrules?: readonlyDOMImportRule<CompiledSelector<Node,Record<string,RegExpMatchArray>>>[]
Defined in: packages/lexical-html/src/import/types.ts:274
Experimental
Additional DOMImportRules active only for this children
traversal (and any nested $importChildren calls that don't push
their own overlay). The overlay is checked BEFORE the main
dispatcher, so its rules take precedence; calling $next() from an
overlay rule falls through to the next overlay-or-main rule.
Use this to scope cost-bearing rules to where they apply. For
example, a GitHub code-table rule installs an overlay that
unwraps <tr> / <td> inside the table, without paying that
predicate cost on every other <tr> / <td> paste.
schema?
readonlyoptionalschema?:ChildSchema
Defined in: packages/lexical-html/src/import/types.ts:247
Experimental
How to validate and (re)package produced children. Defaults to whichever schema the parent's importer passed; the top-level entry uses BlockSchema.
ImportNodeOpts
Defined in: packages/lexical-html/src/import/types.ts:278
Experimental
Properties
context?
readonlyoptionalcontext?: readonlyImportContextPairOrUpdater[]
Defined in: packages/lexical-html/src/import/types.ts:279
Experimental
ImportSession
Defined in: packages/lexical-html/src/import/types.ts:182
Experimental
A mutable, document-order-shared store for the import pipeline. Lets a
rule visited early in the document write information that rules visited
later can read — e.g. parse <style> or <meta> and influence
subsequent matching.
Use sparingly: state that flows from parents to descendants belongs in
ImportStateConfig (via $importChildren({context: [...]})),
which is immutable, scoped, and easier to reason about.
Methods
get()
get<
V>(cfg):V
Defined in: packages/lexical-html/src/import/types.ts:184
Experimental
Read the current value, returning the config's default if unset.
Type Parameters
V
V
Parameters
cfg
Returns
V
has()
has<
V>(cfg):boolean
Defined in: packages/lexical-html/src/import/types.ts:190
Experimental
Returns true if the slot has been written since session creation.
Type Parameters
V
V
Parameters
cfg
Returns
boolean
set()
set<
V>(cfg,value):void
Defined in: packages/lexical-html/src/import/types.ts:186
Experimental
Write value into the slot.
Type Parameters
V
V
Parameters
cfg
value
V
Returns
void
update()
update<
V>(cfg,updater):void
Defined in: packages/lexical-html/src/import/types.ts:188
Experimental
Read-modify-write.
Type Parameters
V
V
Parameters
cfg
updater
(prev) => V
Returns
void
ImportSessionConfig
Defined in: packages/lexical-html/src/import/types.ts:165
Experimental
A typed handle to a slot in ImportSession. Create one at module scope with createImportSessionState. The default value is read lazily the first time a session reads the slot.
Type Parameters
V
V
Properties
getDefault
readonlygetDefault: () =>V
Defined in: packages/lexical-html/src/import/types.ts:167
Experimental
Returns
V
key
readonlykey:symbol
Defined in: packages/lexical-html/src/import/types.ts:166
Experimental
StyleMatchOptions
Defined in: packages/lexical-html/src/import/types.ts:86
Experimental
Options bag for ElementSelectorBuilder.styleAny when the value is a regex. See AttrMatchOptions for capture semantics.
Type Parameters
K
K extends string = string
Properties
capture?
readonlyoptionalcapture?:K
Defined in: packages/lexical-html/src/import/types.ts:87
Experimental
WhitespaceImportConfig
Defined in: packages/lexical-html/src/import/ImportContext.ts:125
Experimental
Configuration for the core text whitespace-collapse logic. Override via
ImportWhitespaceConfig either as a contextDefaults entry on
the DOMImportExtension or per-call on $generateNodesFromDOM's
context option.
Properties
isInline
readonlyisInline:IsInlineForWhitespace
Defined in: packages/lexical-html/src/import/ImportContext.ts:129
Experimental
preservesWhitespace
readonlypreservesWhitespace:IsPreserveWhitespaceDom
Defined in: packages/lexical-html/src/import/ImportContext.ts:127
Experimental
Type Aliases
AnyDOMImportRule
AnyDOMImportRule =
DOMImportRule<any>
Defined in: packages/lexical-html/src/import/types.ts:356
Experimental
AnyDOMRenderMatch
AnyDOMRenderMatch =
DOMRenderMatch<any>
Defined in: packages/lexical-html/src/types.ts:157
Experimental
Any DOMRenderMatch
AnyRenderStateConfig
AnyRenderStateConfig =
RenderStateConfig<any>
Defined in: packages/lexical-html/src/types.ts:121
Experimental
Any RenderStateConfig
AnyRenderStateConfigPairOrUpdater
AnyRenderStateConfigPairOrUpdater =
AnyContextConfigPairOrUpdater<typeofDOMRenderContextSymbol>
Defined in: packages/lexical-html/src/types.ts:111
Experimental
Any setter or updater for RenderStateConfig
CapturesOfSelector
CapturesOfSelector<
S> =SextendsCompiledSelector<Node, infer C> ?C:Record<string,never>
Defined in: packages/lexical-html/src/import/types.ts:61
Experimental
The named-capture map for a selector.
Type Parameters
S
S
ContextPairOrUpdater
ContextPairOrUpdater<
Ctx,V> =ContextConfigPair<Ctx,V> |ContextConfigUpdater<Ctx,V>
Defined in: packages/lexical-html/src/types.ts:81
Experimental
Set or update a context value, constructed with contextValue or contextUpdater
Type Parameters
Ctx
Ctx extends AnyContextSymbol
V
V
DOMImportFn
DOMImportFn<
E,C> = (ctx,node,$next) => readonlyLexicalNode[]
Defined in: packages/lexical-html/src/import/types.ts:326
Experimental
The middleware signature of an import rule. Call $next() to delegate to
the next-matching rule for this node (returning its result, which may then
be inspected or wrapped); return [] to drop the node.
Type Parameters
E
E extends Node
C
C extends Record<string, RegExpMatchArray> = Record<string, never>
Parameters
ctx
node
E
$next
() => readonly LexicalNode[]
Returns
readonly LexicalNode[]
DOMPreprocessFn
DOMPreprocessFn = (
dom,ctx,next) =>void
Defined in: packages/lexical-html/src/import/types.ts:407
Experimental
A middleware step in the DOM-preprocess chain. Runs before walking begins and may:
- Mutate the input DOM in place (e.g. inline stylesheets, strip unsafe elements, normalize attributes).
- Write to DOMPreprocessContext.session for rules to read.
- Call DOMPreprocessContext.setContext to install context values for the upcoming walk.
- Call
next()to defer to the next-lower preprocessor in the stack; omit the call to short-circuit and skip the rest.
Append-style merge applies: an extension's preprocessors are appended
to the existing stack, so later-registered preprocessors run first
and may delegate to earlier (lower-priority) ones via next(). Same
convention as ExportMimeTypeFunction on the export side.
Parameters
dom
Document | ParentNode
ctx
next
() => void
Returns
void
ImportContextPairOrUpdater
ImportContextPairOrUpdater =
AnyContextConfigPairOrUpdater<typeofDOMImportContextSymbol>
Defined in: packages/lexical-html/src/import/types.ts:143
Experimental
Argument to DOMImportContext.branch / $importChildren({context})
— see ContextConfigPair / ContextConfigUpdater.
ImportSourceKind
ImportSourceKind =
"paste"|"drop"|"deserialize"|"headless"|"unknown"
Defined in: packages/lexical-html/src/import/ImportContext.ts:64
Experimental
The kind of operation that produced this import. Lets rules adapt their
behavior (e.g. preserve more whitespace on 'paste', be lenient on
'deserialize', etc.). Defaults to 'unknown'.
ImportStateConfig
ImportStateConfig<
V> =ContextConfig<typeofDOMImportContextSymbol,V>
Defined in: packages/lexical-html/src/import/types.ts:153
Experimental
A typed context-state key for the import pipeline. Create with createImportState.
Type Parameters
V
V
IsInlineForWhitespace
IsInlineForWhitespace = (
node) =>boolean
Defined in: packages/lexical-html/src/import/ImportContext.ts:115
Experimental
Determines whether a given DOM node sits on the same visual line as its
adjacent text siblings, governing whether leading/trailing whitespace in
a #text is collapsed against neighbors. The default consults
isInlineDomNode from lexical (style.display or a fixed inline
tag-name set) and additionally treats elements with an explicit
non-inline display style as block.
Parameters
node
Node
Returns
boolean
IsPreserveWhitespaceDom
IsPreserveWhitespaceDom = (
node) =>boolean
Defined in: packages/lexical-html/src/import/ImportContext.ts:103
Experimental
Determines whether a given DOM element should be treated as preserving
whitespace (i.e. text content under it is not collapsed and is split on
\n / \t into LineBreakNode / TabNode). The default matches the
legacy behavior: the element itself is <pre> or its inline
white-space style begins with 'pre'.
Parameters
node
Node
Returns
boolean
NodeMatch
NodeMatch<
T> =Klass<T> | ((node) =>node is T)
Defined in: packages/lexical-html/src/types.ts:168
Experimental
Match a node (and any subclass of that node) by its LexicalNode class,
or with a guard (e.g. ElementNode or $isElementNode).
Note that using the class compiles to significantly more efficient code than using a guard.
Type Parameters
T
T extends LexicalNode
NodeOfSelector
NodeOfSelector<
S> =SextendsCompiledSelector<infer N,Record<string,RegExpMatchArray>> ?N:Node
Defined in: packages/lexical-html/src/import/types.ts:51
Experimental
The Node subtype matched by a selector (e.g. HTMLAnchorElement for
sel.tag('a'), Text for sel.text()).
Type Parameters
S
S
Variables
$withImportContext
const$withImportContext: (cfg,editor?) => <T>(f) =>T
Defined in: packages/lexical-html/src/import/ImportContext.ts:259
Experimental
Run f with the given context pairs applied on top of the editor's
current import context.
Parameters
cfg
readonly ImportContextPairOrUpdater[]
editor?
Returns
<T>(f) => T
$withRenderContext
const$withRenderContext: (cfg,editor?) => <T>(f) =>T
Defined in: packages/lexical-html/src/RenderContext.ts:93
Experimental
Execute a callback within a render context with the given config pairs.
Parameters
cfg
readonly AnyRenderStateConfigPairOrUpdater[]
editor?
Returns
<T>(f) => T
BlockSchema
constBlockSchema:ChildSchema
Defined in: packages/lexical-html/src/import/schemas.ts:116
Experimental
Default schema for block-level positions (root of the document, the body of a block element node). Accepts block lexical nodes; packages runs of inline children into fresh paragraph nodes.
CoreImportExtension
constCoreImportExtension:LexicalExtension<ExtensionConfigBase,"@lexical/html/CoreImport",unknown,unknown>
Defined in: packages/lexical-html/src/import/CoreImportExtension.ts:23
Experimental
Bundles CoreImportRules into a DOMImportExtension-aware
extension. Depend on this from your editor (directly or via richer
extensions like RichTextImportExtension) to get the equivalent of the
legacy core importDOM behavior for <p>, <span>, <b>,
<strong>, <em>, <i>, <code>, <mark>, <s>, <sub>, <sup>,
<u>, <br>, and #text.
CoreImportRules
constCoreImportRules: (DOMImportRule<CompiledSelector<Text,Record<string,RegExpMatchArray>>> |DOMImportRule<ElementSelectorBuilder<HTMLElement|HTMLSpanElement,Record<string,never>>>)[]
Defined in: packages/lexical-html/src/import/coreImportRules.ts:435
Experimental
Rules covering the ParagraphNode, TextNode,
LineBreakNode, and TabNode cases that the legacy
importDOM machinery in @lexical/lexical handled. Intended to be
registered as a dependency of every editor that uses
DOMImportExtension.
DOMImportExtension
constDOMImportExtension:LexicalExtension<DOMImportConfig,"@lexical/html/DOMImport",DOMImportExtensionOutput,void>
Defined in: packages/lexical-html/src/import/DOMImportExtension.ts:123
Experimental
Extension-based replacement for the legacy importDOM / DOMConversion
machinery. Rules are contributed via configuration (see
DOMImportConfig.rules), compiled into a tag-bucketed dispatcher at
editor build time, and consumed via the extension's
DOMImportExtensionOutput.$generateNodesFromDOM output.
The legacy $generateNodesFromDOM continues to work in parallel; the
intent is to migrate node packages over to this extension incrementally.
DOMRenderExtension
constDOMRenderExtension:LexicalExtension<DOMRenderConfig,"@lexical/html/DOM",DOMRenderExtensionOutput,void>
Defined in: packages/lexical-html/src/DOMRenderExtension.ts:23
Experimental
An extension that allows overriding the render and export behavior for an editor. This is highly experimental and subject to change from one version to the next.
HorizontalRuleImportExtension
constHorizontalRuleImportExtension:LexicalExtension<ExtensionConfigBase,"@lexical/html/HorizontalRuleImport",unknown,unknown>
Defined in: packages/lexical-html/src/import/HorizontalRuleImportExtension.ts:46
Experimental
Bundles HorizontalRuleImportRules (plus CoreImportExtension) into a single dependency. The legacy HorizontalRuleExtension.importDOM continues to work in parallel; depend on this extension to opt into the new pipeline.
Lives in @lexical/html (not @lexical/extension) because
DOMImportExtension itself is in @lexical/html, and
@lexical/extension is upstream of @lexical/html in the dependency
graph — same arrangement as CoreImportExtension.
HorizontalRuleImportRules
constHorizontalRuleImportRules:DOMImportRule<ElementSelectorBuilder<HTMLHRElement,Record<string,never>>>[]
Defined in: packages/lexical-html/src/import/HorizontalRuleImportExtension.ts:31
Experimental
Import rules for HorizontalRuleNode.
ImportSource
constImportSource:ImportStateConfig<ImportSourceKind>
Defined in: packages/lexical-html/src/import/ImportContext.ts:77
Experimental
Built-in import-context state identifying how this import was initiated.
Callers of $generateNodesFromDOM should set it via the context option.
ImportTextFormat
constImportTextFormat:ImportStateConfig<number>
Defined in: packages/lexical-html/src/import/ImportContext.ts:89
Experimental
Built-in import-context state holding the bit-packed
TextFormatType formats that should apply to TextNodes
produced during the current subtree. Used by inline-format wrappers
(<b>, <i>, <u>, …) to propagate formatting through the context
record instead of via the legacy forChild chain.
ImportWhitespaceConfig
constImportWhitespaceConfig:ImportStateConfig<WhitespaceImportConfig>
Defined in: packages/lexical-html/src/import/ImportContext.ts:182
Experimental
Built-in import-context state controlling text-node whitespace handling (collapse vs. preserve, what counts as an inline sibling). Override per editor via DOMImportConfig.contextDefaults or per call via GenerateNodesFromDOMOptions.context.
InlineSchema
constInlineSchema:ChildSchema
Defined in: packages/lexical-html/src/import/schemas.ts:129
Experimental
Schema for inline-only positions (the body of an inline lexical node such
as a link). Accepts non-block lexical nodes; runs of block children are
dropped (onReject: 'drop' is the default).
inlineStylesFromStyleSheets
constinlineStylesFromStyleSheets:DOMPreprocessFn
Defined in: packages/lexical-html/src/import/inlineStylesFromStyleSheets.ts:34
Experimental
Inlines CSS rules from <style> tags onto matching elements as inline
styles.
Used by apps like Excel that generate HTML where styles live in
class-based <style> rules (e.g. .xl65 { background: #FFFF00; color: blue; }) rather than inline styles. Since Lexical's import converters
read inline styles, we resolve stylesheet rules into inline styles
before conversion.
Mutates the DOM in-place. Original inline styles always take precedence over stylesheet rules (matching CSS specificity behavior).
No-op for ParentNodes that are not Documents — only a
full document carries styleSheets we can iterate.
NestedBlockSchema
constNestedBlockSchema:ChildSchema
Defined in: packages/lexical-html/src/import/schemas.ts:144
Experimental
Schema for nested block positions — the equivalent of the legacy
ArtificialNode__DO_NOT_USE flow used when a block DOM element appears
inside another block lexical ancestor. Accepts block nodes; runs of inline
children are emitted with a line break between consecutive runs (instead
of being wrapped in a paragraph, which would introduce an extra level of
nesting).
RenderContextExport
constRenderContextExport:RenderStateConfig<boolean>
Defined in: packages/lexical-html/src/RenderContext.ts:57
Experimental
Render context state that is true if this is an export operation ($generateHtmlFromNodes).
RenderContextRoot
constRenderContextRoot:RenderStateConfig<boolean>
Defined in: packages/lexical-html/src/RenderContext.ts:51
Experimental
Render context state that is true if the export was initiated from the root of the document.
RootSchema
constRootSchema:ChildSchema
Defined in: packages/lexical-html/src/import/schemas.ts:167
Experimental
Schema for the topmost level of $generateNodesFromDOM. Identical to
BlockSchema; aliased for clarity at the entry point and so it can
be overridden separately in the future (e.g. to synthesize a ListNode
around runs of orphan ListItemNodes).
sel
constsel:object
Defined in: packages/lexical-html/src/import/index.ts:18
Experimental
Combinator-and-parser-based builder for CompiledSelectors. The runtime shape returned by these factory methods is opaque; consumers should never inspect or construct selector objects directly.
Type Declaration
any
any: () =>
ElementSelectorBuilder<HTMLElement> =selBase.any
Match any HTMLElement.
Returns
ElementSelectorBuilder<HTMLElement>
comment
comment: () =>
CompiledSelector<Comment> =selBase.comment
Match DOM Comment nodes.
Returns
CompiledSelector<Comment>
css
css: (
source) =>ElementSelectorBuilder<HTMLElement> =parseSelector
Parse a reduced CSS-selector subset and return a builder you can chain combinator methods off of.
Experimental
Parse a reduced CSS-selector subset and return a CompiledSelector. Supported:
- Tag (
p), wildcard (*). - Tag list (
h1, h2, h3). - Class (
.foo,.foo.bar). - ID (
#foo). - Attribute presence (
[name]). - Attribute equality (
[name="value"],[name=value]).
Anything outside the subset (regex attribute, inline-style match, combinators, pseudo-classes) is intentionally rejected — chain combinator methods off the returned builder instead.
Parameters
source
string
Returns
ElementSelectorBuilder<HTMLElement>
tag
tag: <
Tags>(...tags) =>ElementSelectorBuilder<Tags[number] extends keyofHTMLElementTagNameMap?HTMLElementTagNameMap[any[any]] :HTMLElement> =selBase.tag
Match by tag name(s). With one literal tag the element type is narrowed
(e.g. 'a' → HTMLAnchorElement); with multiple, it is the union of
their HTMLElementTagNameMap entries.
Type Parameters
Tags
Tags extends readonly string[]
Parameters
tags
...Tags
Returns
ElementSelectorBuilder<Tags[number] extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[any[any]] : HTMLElement>
text
text: () =>
CompiledSelector<Text> =selBase.text
Match DOM Text nodes.
Returns
CompiledSelector<Text>
Functions
$generateDOMFromNodes()
$generateDOMFromNodes<
T>(container,selection?,editor?):T
Defined in: packages/lexical-html/src/index.ts:177
Experimental
Generate DOM nodes from the editor state into the given container element, using the editor's EditorDOMRenderConfig.
Type Parameters
T
T extends HTMLElement | DocumentFragment
Parameters
container
T
selection?
BaseSelection | null
editor?
LexicalEditor = ...
Returns
T
$generateDOMFromRoot()
$generateDOMFromRoot<
T>(container,root?):T
Defined in: packages/lexical-html/src/index.ts:208
Experimental
Generate DOM nodes from a root node into the given container element, including the root node itself. Uses the editor's EditorDOMRenderConfig.
Type Parameters
T
T extends HTMLElement | DocumentFragment
Parameters
container
T
root?
LexicalNode = ...
Returns
T
$generateHtmlFromNodes()
$generateHtmlFromNodes(
editor,selection?):string
Defined in: packages/lexical-html/src/index.ts:228
Parameters
editor
selection?
BaseSelection | null
Returns
string
$generateNodesFromDOM()
$generateNodesFromDOM(
editor,dom):LexicalNode[]
Defined in: packages/lexical-html/src/index.ts:131
How you parse your html string to get a document is left up to you. In the browser you can use the native DOMParser API to generate a document (see clipboard.ts), but to use in a headless environment you can use JSDom or an equivalent library and pass in the document here.
Parameters
editor
dom
Document | ParentNode
Returns
$generateNodesFromDOMViaExtension()
$generateNodesFromDOMViaExtension(
editor,dom,options?):LexicalNode[]
Defined in: packages/lexical-html/src/import/DOMImportExtension.ts:211
Experimental
Look up the editor's DOMImportExtension and run its
$generateNodesFromDOM. Designed as a drop-in replacement for the
legacy $generateNodesFromDOM(editor, dom) signature so it can be
supplied to ClipboardImportExtension.$generateNodesFromDOM (or any
other consumer that wants to route through the extension pipeline).
Throws if the editor was not built with DOMImportExtension as a dependency.
Parameters
editor
dom
Document | ParentNode
options?
Returns
$getImportContextValue()
$getImportContextValue<
V>(cfg,editor?):V
Defined in: packages/lexical-html/src/import/ImportContext.ts:246
Experimental
Read an import context value during an import operation.
Type Parameters
V
V
Parameters
cfg
editor?
LexicalEditor = ...
Returns
V
$getRenderContextValue()
$getRenderContextValue<
V>(cfg,editor?):V
Defined in: packages/lexical-html/src/RenderContext.ts:82
Experimental
Get a render context value during a DOM render or export operation.
Type Parameters
V
V
Parameters
cfg
RenderStateConfig<V>
editor?
LexicalEditor = ...
Returns
V
contextUpdater()
contextUpdater<
Ctx,V>(cfg,updater):ContextConfigUpdater<Ctx,V>
Defined in: packages/lexical-html/src/ContextRecord.ts:170
Experimental
Create a context config updater that transforms a value in the render context.
Type Parameters
Ctx
Ctx extends AnyContextSymbol
V
V
Parameters
cfg
ContextConfig<Ctx, V>
updater
(prev) => V
Returns
ContextConfigUpdater<Ctx, V>
contextValue()
contextValue<
Ctx,V>(cfg,value):ContextConfigPair<Ctx,V>
Defined in: packages/lexical-html/src/ContextRecord.ts:159
Experimental
Create a context config pair that sets a value in the render context.
Type Parameters
Ctx
Ctx extends AnyContextSymbol
V
V
Parameters
cfg
ContextConfig<Ctx, V>
value
V
Returns
ContextConfigPair<Ctx, V>
createImportSessionState()
createImportSessionState<
V>(name,getDefault):ImportSessionConfig<V>
Defined in: packages/lexical-html/src/import/ImportContext.ts:196
Experimental
Create a typed slot for the import session (see ImportSession). Like createImportState but for mutable, document-order-shared state.
@NO_SIDE_EFFECTS
Type Parameters
V
V
Parameters
name
string
getDefault
() => V
Returns
createImportState()
createImportState<
V>(name,getDefaultValue,isEqual?):ImportStateConfig<V>
Defined in: packages/lexical-html/src/import/ImportContext.ts:44
Experimental
Create an import context state. The phantom symbol prevents accidental use of a render-context state in an import context (and vice versa).
Note: to support the value-or-updater pattern, V cannot be a function
type; wrap it in an array or object if needed.
@NO_SIDE_EFFECTS
Type Parameters
V
V
Parameters
name
string
getDefaultValue
() => V
isEqual?
(a, b) => boolean
Returns
createRenderState()
createRenderState<
V>(name,getDefaultValue,isEqual?):RenderStateConfig<V>
Defined in: packages/lexical-html/src/RenderContext.ts:34
Experimental
Create a context state to be used during render.
Note that to support the ValueOrUpdater pattern you can not use a function for V (but you may wrap it in an array or object).
@NO_SIDE_EFFECTS
Type Parameters
V
V
Parameters
name
string
getDefaultValue
() => V
isEqual?
(a, b) => boolean
Returns
RenderStateConfig<V>
defaultIsInline()
defaultIsInline(
node):boolean
Defined in: packages/lexical-html/src/import/ImportContext.ts:157
Experimental
Default WhitespaceImportConfig.isInline: treats an element as
inline iff its inline display style is inline* OR (no explicit
non-inline display) its nodeName is a known inline tag (isInlineDomNode).
Text nodes are always inline; comments and other non-elements are not.
Parameters
node
Node
Returns
boolean
defaultPreservesWhitespace()
defaultPreservesWhitespace(
node):boolean
Defined in: packages/lexical-html/src/import/ImportContext.ts:138
Experimental
Default WhitespaceImportConfig.preservesWhitespace: matches
<pre> and any element with white-space: pre*.
Parameters
node
Node
Returns
boolean
defineImportRule()
defineImportRule<
S>(rule):DOMImportRule<S>
Defined in: packages/lexical-html/src/import/defineImportRule.ts:29
Experimental
Identity helper that infers a rule's matched node type and capture map
from its match selector and threads them into the $import signature.
Usage:
defineImportRule({
name: '@lexical/list/li',
match: sel.tag('li'),
$import: (ctx, el, $next) => {
// el: HTMLLIElement
return [$createListItemNode()];
},
});
@NO_SIDE_EFFECTS
Type Parameters
S
S extends CompiledSelector<Node, Record<string, RegExpMatchArray>>
Parameters
rule
$import
DOMImportFn<S extends CompiledSelector<N, Record<string, RegExpMatchArray>> ? N : Node, S extends CompiledSelector<Node, C> ? C : Record<string, never>>
match
S
name?
string
Returns
domOverride()
Call Signature
domOverride(
nodes,config):DOMRenderMatch<LexicalNode>
Defined in: packages/lexical-html/src/domOverride.ts:19
Experimental
A convenience function for type inference when constructing DOM overrides for use with DOMRenderExtension.
@NO_SIDE_EFFECTS
Parameters
nodes
"*"
config
Omit<DOMRenderMatch<LexicalNode>, "nodes">
Returns
Call Signature
domOverride<
T>(nodes,config):DOMRenderMatch<T>
Defined in: packages/lexical-html/src/domOverride.ts:23
Experimental
A convenience function for type inference when constructing DOM overrides for use with DOMRenderExtension.
@NO_SIDE_EFFECTS
Type Parameters
T
T extends LexicalNode
Parameters
nodes
readonly NodeMatch<T>[]
config
Omit<DOMRenderMatch<T>, "nodes">
Returns
isElementOfTag()
isElementOfTag<
T>(node,tag):node is HTMLElementTagNameMap[T]
Defined in: packages/lexical-html/src/import/sel.ts:309
Experimental
Cross-frame-safe replacement for node instanceof HTMLXxxElement. Returns
true when node is an HTMLElement whose nodeName equals tag (compared
case-insensitively).
Type Parameters
T
T extends keyof HTMLElementTagNameMap
Parameters
node
Node
tag
T
Returns
node is HTMLElementTagNameMap[T]
parseSelector()
parseSelector(
source):ElementSelectorBuilder<HTMLElement>
Defined in: packages/lexical-html/src/import/parseCss.ts:160
Experimental
Parse a reduced CSS-selector subset and return a CompiledSelector. Supported:
- Tag (
p), wildcard (*). - Tag list (
h1, h2, h3). - Class (
.foo,.foo.bar). - ID (
#foo). - Attribute presence (
[name]). - Attribute equality (
[name="value"],[name=value]).
Anything outside the subset (regex attribute, inline-style match, combinators, pseudo-classes) is intentionally rejected — chain combinator methods off the returned builder instead.
Parameters
source
string
Returns
ElementSelectorBuilder<HTMLElement>