Skip to main content

@lexical/mdast

Interfaces​

Blockquote​

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:514

Markdown block quote.

Extends​

Properties​

children​

children: (BlockContent | DefinitionContent)[]

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:522

Children of block quote.

Overrides​

MdastParent.children

data?​

optional data?: BlockquoteData

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:526

Data associated with the mdast block quote.

Overrides​

MdastParent.data

position?​

optional position?: Position

Defined in: node_modules/.pnpm/@types+unist@3.0.3/node_modules/@types/unist/index.d.ts:103

Position of a node in a source document.

Nodes that are generated (not in the original source document) must not have a position.

Inherited from​

MdastParent.position

type​

type: "blockquote"

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:518

Node type of mdast block quote.

Overrides​

MdastParent.type


CompiledMdast​

Defined in: packages/lexical-mdast/src/types.ts:192

Experimental

The compiled registry produced from MdastConfig at editor build time and consumed by the importer, exporter, and shortcut scanner.

Properties​

exportHandlers​

exportHandlers: Map<string, MdastExportHandler<LexicalNode>>

Defined in: packages/lexical-mdast/src/types.ts:194

Experimental

importHandlers​

importHandlers: Map<string, MdastImportHandler<MdastNode>>

Defined in: packages/lexical-mdast/src/types.ts:193

Experimental

inlineShortcutTriggers​

inlineShortcutTriggers: Set<string>

Defined in: packages/lexical-mdast/src/types.ts:201

Experimental

Characters that can close an inline construct and trigger a re-scan.

inlineShortcutTypes​

inlineShortcutTypes: Set<string>

Defined in: packages/lexical-mdast/src/types.ts:199

Experimental

mdast inline types eligible for streaming shortcut materialization.

mdastExtensions​

mdastExtensions: Extension[]

Defined in: packages/lexical-mdast/src/types.ts:196

Experimental

micromarkExtensions​

micromarkExtensions: Extension[]

Defined in: packages/lexical-mdast/src/types.ts:195

Experimental

toMarkdownExtensions​

toMarkdownExtensions: Options[]

Defined in: packages/lexical-mdast/src/types.ts:197

Experimental


FootnoteDefinition​

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:650

Markdown GFM footnote definition.

Extends​

Properties​

children​

children: (BlockContent | DefinitionContent)[]

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:658

Children of GFM footnote definition.

Overrides​

MdastParent.children

data?​

optional data?: FootnoteDefinitionData

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:662

Data associated with the mdast GFM footnote definition.

Overrides​

MdastParent.data

identifier​

identifier: string

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:71

Relation of association.

identifier is a source value: character escapes and character references are not parsed.

It can match another node.

Its value must be normalized. To normalize a value, collapse markdown whitespace ([\t\n\r ]+) to a space, trim the optional initial and/or final space, and perform Unicode-aware case-folding.

Inherited from​

Association.identifier

label?​

optional label?: string | null

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:82

Relation of association, in parsed form.

label is a string value: it works just like title on Link or a lang on Code: character escapes and character references are parsed.

It can match another node.

Inherited from​

Association.label

position?​

optional position?: Position

Defined in: node_modules/.pnpm/@types+unist@3.0.3/node_modules/@types/unist/index.d.ts:103

Position of a node in a source document.

Nodes that are generated (not in the original source document) must not have a position.

Inherited from​

MdastParent.position

type​

type: "footnoteDefinition"

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:654

Node type of mdast GFM footnote definition.

Overrides​

MdastParent.type


FootnoteReference​

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:673

Markdown GFM footnote reference.

Extends​

  • Association.Node

Properties​

data?​

optional data?: FootnoteReferenceData

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:681

Data associated with the mdast GFM footnote reference.

Overrides​

Node.data

identifier​

identifier: string

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:71

Relation of association.

identifier is a source value: character escapes and character references are not parsed.

It can match another node.

Its value must be normalized. To normalize a value, collapse markdown whitespace ([\t\n\r ]+) to a space, trim the optional initial and/or final space, and perform Unicode-aware case-folding.

Inherited from​

Association.identifier

label?​

optional label?: string | null

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:82

Relation of association, in parsed form.

label is a string value: it works just like title on Link or a lang on Code: character escapes and character references are parsed.

It can match another node.

Inherited from​

Association.label

position?​

optional position?: Position

Defined in: node_modules/.pnpm/@types+unist@3.0.3/node_modules/@types/unist/index.d.ts:103

Position of a node in a source document.

Nodes that are generated (not in the original source document) must not have a position.

Inherited from​

Node.position

type​

type: "footnoteReference"

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:677

Node type of mdast GFM footnote reference.

Overrides​

Node.type


Html​

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:721

Markdown HTML.

Extends​

  • Literal

Properties​

data?​

optional data?: HtmlData

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:729

Data associated with the mdast HTML.

Overrides​

Literal.data

position?​

optional position?: Position

Defined in: node_modules/.pnpm/@types+unist@3.0.3/node_modules/@types/unist/index.d.ts:103

Position of a node in a source document.

Nodes that are generated (not in the original source document) must not have a position.

Inherited from​

Literal.position

type​

type: "html"

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:725

Node type of mdast HTML.

Overrides​

Literal.type

value​

value: string

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:472

Plain-text value.

Inherited from​

Literal.value


MdastConfig​

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:100

Experimental

Configuration for the core MdastImportExtension registry. Feature extensions contribute to these arrays via configExtension(MdastImportExtension, …); you rarely need to set them by hand. The shape mirrors @lexical/html's DOMImportExtension config: raw contribution arrays that mergeConfig concatenates and build compiles.

Properties​

exportRules​

readonly exportRules: readonly MdastExportRule[]

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:104

Experimental

Lexical getType() -> mdast mapping rules used while exporting.

importRules​

readonly importRules: readonly MdastImportRule[]

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:102

Experimental

mdast type -> Lexical mapping rules used while importing.

inlineShortcutTriggers​

readonly inlineShortcutTriggers: readonly string[]

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:123

Experimental

Characters that can close an inline construct; typing one triggers an inline re-scan. Extensions add their construct's closing character here (e.g. '=' for ==highlight==).

inlineShortcutTypes​

readonly inlineShortcutTypes: readonly string[]

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:117

Experimental

mdast inline types that the streaming shortcuts may materialize when their closing delimiter is typed. Extensions that contribute a new inline construct add its type here (with a matching import rule) so shortcuts stay in lock-step with the parser.

mdastExtensions​

readonly mdastExtensions: readonly Extension[]

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:108

Experimental

mdast-util-from-markdown extensions (tokens -> mdast).

micromarkExtensions​

readonly micromarkExtensions: readonly Extension[]

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:106

Experimental

micromark syntax extensions (the tokenizer layer).

toMarkdownExtensions​

readonly toMarkdownExtensions: readonly Options[]

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:110

Experimental

mdast-util-to-markdown extensions (mdast -> Markdown string).


MdastExportContext​

Defined in: packages/lexical-mdast/src/types.ts:119

Experimental

The context passed to MdastExportHandlers while a Lexical tree is converted back into an mdast tree.

Methods​

exportBlocks()​

exportBlocks(source): BlockContent[]

Defined in: packages/lexical-mdast/src/types.ts:141

Experimental

Convert the inline children of source (an element or an explicit node list, as in MdastExportContext.exportChildren) into one or more mdast block nodes (paragraphs), splitting on hard line breaks. Used by containers such as block quotes and list items whose Lexical children are inline but whose mdast children must be block-level.

Parameters​
source​

ElementNode | readonly LexicalNode[]

Returns​

BlockContent[]

exportChildren()​

exportChildren(source): MdastNode[]

Defined in: packages/lexical-mdast/src/types.ts:127

Experimental

Convert the children of source into mdast nodes by dispatching each child through the registered export handlers. source is an element (its getChildren() are exported) or an explicit list of nodes — e.g. a DOMExportOutput.$getChildNodes() override, which is defined as replacing node.getChildren() for export.

Parameters​
source​

ElementNode | readonly LexicalNode[]

Returns​

MdastNode[]

exportInline()​

exportInline(source): PhrasingContent[]

Defined in: packages/lexical-mdast/src/types.ts:133

Experimental

Convert the inline children of source (an element or an explicit node list, as in MdastExportContext.exportChildren) into mdast phrasing content, grouping bare line breaks as mdast break nodes.

Parameters​
source​

ElementNode | readonly LexicalNode[]

Returns​

PhrasingContent[]

isIncluded()​

isIncluded(node): boolean

Defined in: packages/lexical-mdast/src/types.ts:150

Experimental

Whether node belongs in the current export: always true for a whole-document export; during a selection export, true when the node or any descendant is selected. The exportChildren/exportInline/ exportBlocks walks apply this automatically — handlers only need it when they iterate children manually (e.g. list items, table rows) to skip structural children the selection does not reach.

Parameters​
node​

LexicalNode

Returns​

boolean


MdastExportExtensionOutput​

Defined in: packages/lexical-mdast/src/MdastExportExtension.ts:24

Experimental

The runtime API exposed by MdastExportExtension. Obtain it inside a read/update with $getExtensionOutput(MdastExportExtension), or use the $convertToMarkdownString shorthand.

Methods​

$convertSelectionToMarkdownString()​

$convertSelectionToMarkdownString(selection?): string

Defined in: packages/lexical-mdast/src/MdastExportExtension.ts:50

Experimental

Serializes only the selected content (defaulting to the current selection) to a Markdown string: leaves outside the selection are skipped, partially selected text nodes are sliced to the selected range, and elements are kept when they or any descendant are selected. Returns '' for a null or collapsed selection. Must be called inside an editor.read() or editor.update(). The export runs under RenderContextMarkdownSelection carrying the selection, so contributed export rules and to-markdown handlers can scope their output to a selection export.

Parameters​
selection?​

BaseSelection | null

Returns​

string

$convertToMarkdownString()​

$convertToMarkdownString(node?): string

Defined in: packages/lexical-mdast/src/MdastExportExtension.ts:29

Experimental

Serializes the editor root (or node) to a Markdown string. Must be called inside an editor.read() or editor.update().

Parameters​
node?​

ElementNode

Returns​

string

$convertToMdast()​

$convertToMdast(node?): Root

Defined in: packages/lexical-mdast/src/MdastExportExtension.ts:38

Experimental

Exports the editor root (or node) to an mdast Root tree without serializing it, for interop with the unified/remark ecosystem (remark plugins, remark-rehype, tree diffing, ...). Must be called inside an editor.read() or editor.update(). Syntax preserved from import rides along as data fields on the nodes, mdast's sanctioned extension point.

Parameters​
node?​

ElementNode

Returns​

Root


MdastExportRule​

Defined in: packages/lexical-mdast/src/types.ts:180

Experimental

A single export mapping: which Lexical node getType() it handles and how.

Properties​

$export​

$export: MdastExportHandler<any>

Defined in: packages/lexical-mdast/src/types.ts:184

Experimental

type​

type: string

Defined in: packages/lexical-mdast/src/types.ts:182

Experimental

The Lexical node getType() this rule handles (e.g. 'heading').


MdastImportContext​

Defined in: packages/lexical-mdast/src/types.ts:66

Experimental

The context passed to MdastImportHandlers while an mdast tree is being walked and converted into Lexical nodes.

Properties​

format​

readonly format: number

Defined in: packages/lexical-mdast/src/types.ts:73

Experimental

The accumulated text-format bitmask for the current inline position (e.g. inside strong > emphasis this carries the bold + italic bits). Block handlers can ignore this; inline handlers should pass it along to createText and the recursion helpers.

source​

readonly source: string

Defined in: packages/lexical-mdast/src/types.ts:80

Experimental

The original Markdown source being imported, or '' when importing a pre-parsed mdast tree. Handlers slice this by node.position to recover the literal syntax (list marker, code fence, hard-break style) for round-trip preservation.

Methods​

createText()​

createText(value, format?): LexicalNode[]

Defined in: packages/lexical-mdast/src/types.ts:94

Experimental

Create text nodes for value with the current (or supplied) format bitmask; \n becomes a LineBreakNode and \t a TabNode.

Parameters​
value​

string

format?​

number

Returns​

LexicalNode[]

getDefinition()​

getDefinition(identifier): { title?: string | null; url: string; } | undefined

Defined in: packages/lexical-mdast/src/types.ts:99

Experimental

Resolves a link/image reference identifier (already normalized by mdast) against the document's definitions ([id]: url "title").

Parameters​
identifier​

string

Returns​

{ title?: string | null; url: string; } | undefined

importChildren()​

importChildren(parent, format?): LexicalNode[]

Defined in: packages/lexical-mdast/src/types.ts:85

Experimental

Convert every child of parent into Lexical nodes, optionally layering an additional text-format bitmask on top of the current format.

Parameters​
parent​

MdastParent

format?​

number

Returns​

LexicalNode[]

importNode()​

importNode(node, format?): LexicalNode[]

Defined in: packages/lexical-mdast/src/types.ts:89

Experimental

Convert a single mdast node (and its descendants) into Lexical nodes.

Parameters​
node​

MdastNode

format?​

number

Returns​

LexicalNode[]


MdastImportExtensionOutput​

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:134

Experimental

The runtime API exposed by MdastImportExtension. Obtain it inside a read/update with $getExtensionOutput(MdastImportExtension), or use the $convertFromMarkdownString shorthand. Serialization lives in MdastExportExtension so import-only editors don't bundle the serializer (mdast-util-to-markdown).

Methods​

$convertFromMarkdownString()​

$convertFromMarkdownString(markdown, node?): void

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:139

Experimental

Parses markdown with micromark/mdast and replaces the contents of the editor root (or node). Must be called inside an editor.update().

Parameters​
markdown​

string

node?​

ElementNode

Returns​

void

$convertFromMdast()​

$convertFromMdast(tree, node?): void

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:147

Experimental

Imports an already-parsed mdast Root tree (e.g. produced or transformed by unified/remark tooling) and replaces the contents of the editor root (or node). Must be called inside an editor.update(). Source-based syntax preservation does not apply (there is no source text to recover literal markers from).

Parameters​
tree​

Root

node?​

ElementNode

Returns​

void

$generateNodesFromMarkdownString()​

$generateNodesFromMarkdownString(markdown): LexicalNode[]

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:154

Experimental

Parses markdown and returns the resulting block-level nodes as a detached array, without modifying the document or the selection — e.g. for insertion at an arbitrary position via selection.insertNodes(). Must be called inside an editor.update().

Parameters​
markdown​

string

Returns​

LexicalNode[]

$generateNodesFromMdast()​

$generateNodesFromMdast(tree): LexicalNode[]

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:162

Experimental

Walks an already-parsed mdast Root tree and returns the resulting block-level nodes as a detached array, without modifying the document or the selection. Must be called inside an editor.update(). As with MdastImportExtensionOutput.$convertFromMdast, source-based syntax preservation does not apply.

Parameters​
tree​

Root

Returns​

LexicalNode[]


MdastImportRule​

Defined in: packages/lexical-mdast/src/types.ts:169

Experimental

A single import mapping: which mdast node type it handles and how. The unit an extension contributes (alongside the micromark/mdast extensions that tokenize the construct) to MdastImportExtension's importRules config.

Properties​

$import​

$import: MdastImportHandler<any>

Defined in: packages/lexical-mdast/src/types.ts:173

Experimental

type​

type: string

Defined in: packages/lexical-mdast/src/types.ts:171

Experimental

The mdast node type this rule handles (e.g. 'heading').


MdastParent​

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:502

Abstract mdast node that contains other mdast nodes (children).

This interface is supposed to be extended if you make custom mdast nodes.

For a union of all registered mdast parents, see Parents.

Extends​

  • Node

Extended by​

Properties​

children​

children: RootContent[]

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:506

List of children.

data?​

optional data?: Data

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:492

Info from the ecosystem.

Inherited from​

Node.data

position?​

optional position?: Position

Defined in: node_modules/.pnpm/@types+unist@3.0.3/node_modules/@types/unist/index.d.ts:103

Position of a node in a source document.

Nodes that are generated (not in the original source document) must not have a position.

Inherited from​

Node.position

type​

type: string

Defined in: node_modules/.pnpm/@types+unist@3.0.3/node_modules/@types/unist/index.d.ts:90

Node type.

Inherited from​

Node.type


MdastShortcutsConfig​

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:542

Properties​

disabled​

disabled: boolean

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:544

Disable the streaming shortcuts without removing the extension.


Paragraph​

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:923

Markdown paragraph.

Extends​

Properties​

children​

children: PhrasingContent[]

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:931

Children of paragraph.

Overrides​

MdastParent.children

data?​

optional data?: ParagraphData

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:935

Data associated with the mdast paragraph.

Overrides​

MdastParent.data

position?​

optional position?: Position

Defined in: node_modules/.pnpm/@types+unist@3.0.3/node_modules/@types/unist/index.d.ts:103

Position of a node in a source document.

Nodes that are generated (not in the original source document) must not have a position.

Inherited from​

MdastParent.position

type​

type: "paragraph"

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:927

Node type of mdast paragraph.

Overrides​

MdastParent.type

Type Aliases​

BlockContent​

BlockContent = BlockContentMap[keyof BlockContentMap]

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:141

Union of registered mdast nodes that can occur where block content is expected.

To register custom mdast nodes, add them to BlockContentMap. They will be automatically added here.


MdastExportHandler​

MdastExportHandler<T> = (node, context) => MdastNode | MdastNode[] | null

Defined in: packages/lexical-mdast/src/types.ts:158

Experimental

Converts a Lexical node into one or more mdast nodes. Returning null defers to the next registered handler.

Type Parameters​

T​

T extends LexicalNode = LexicalNode

Parameters​

node​

T

context​

MdastExportContext

Returns​

MdastNode | MdastNode[] | null


MdastImportHandler​

MdastImportHandler<T> = (node, context) => LexicalNode | LexicalNode[] | null

Defined in: packages/lexical-mdast/src/types.ts:109

Experimental

Converts an mdast node of a particular type into one or more Lexical nodes. Returning null defers to the next registered handler.

Type Parameters​

T​

T extends MdastNode = MdastNode

Parameters​

node​

T

context​

MdastImportContext

Returns​

LexicalNode | LexicalNode[] | null


MdastNode​

MdastNode = Root | RootContent

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:439

Union of registered mdast nodes.

To register custom mdast nodes, add them to RootContentMap and other places where relevant. They will be automatically added here.


PhrasingContent​

PhrasingContent = PhrasingContentMap[keyof PhrasingContentMap]

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:267

Union of registered mdast nodes that can occur where phrasing content is expected.

To register custom mdast nodes, add them to PhrasingContentMap. They will be automatically added here.


RawHtmlBlockPart​

RawHtmlBlockPart = string | PhrasingContent[] | { flow: BlockContent[]; }

Defined in: packages/lexical-mdast/src/MdastHtmlExtension.ts:650

Experimental

One piece of a rawHtmlBlock:

  • a string is raw HTML, emitted verbatim,
  • a PhrasingContent[] is Markdown phrasing embedded in the raw stream (a <summary> line),
  • {flow} is a run of Markdown blocks, joined with blank lines.

RootContent​

RootContent = RootContentMap[keyof RootContentMap]

Defined in: node_modules/.pnpm/@types+mdast@4.0.4/node_modules/@types/mdast/index.d.ts:307

Union of registered mdast nodes that can occur in Root.

To register custom mdast nodes, add them to RootContentMap. They will be automatically added here.

Variables​

$exportViaDOM​

const $exportViaDOM: MdastExportHandler

Defined in: packages/lexical-mdast/src/MdastHtmlExtension.ts:801

Experimental

A fully generic Markdown export for an HTML-encoded construct: renders the node's own exportDOM shell through the editor's @lexical/html render config, substitutes the node's children (at the shell's children position) and its named slots (at their data-lexical-slot wrappers — the same convention exportDOM implementations already use for HTML) with embedded Markdown, and serializes via rawHtmlBlock. Register it directly:

configExtension(MdastImportExtension, {
exportRules: [{$export: $exportViaDOM, type: 'collapsible'}],
})

exportDOM is then the single source of truth for the HTML encoding — whatever slot content the shell serialized for the HTML clipboard is replaced with Markdown here, and the data-lexical-slot markers are removed. Children and shadow-root slot values embed as flow blocks (blank-line separated); inline children and bare-block slot values embed as phrasing on their own line, the GitHub <summary> idiom.


ImportContextMarkdown​

const ImportContextMarkdown: ImportStateConfig<boolean>

Defined in: packages/lexical-mdast/src/MdastImport.ts:45

Experimental

Import context state that is true for the whole of a Markdown/mdast import: inside every MdastImportHandler and inside any DOM-rule session it opens (raw HTML routed through the DOM import rules inherits the surrounding import context), so a DOM rule can distinguish a Markdown import from an HTML paste of the same markup (read it with ctx.get, or $getImportContextValue from an mdast handler).


MdastAutolinkLiteralExtension​

const MdastAutolinkLiteralExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/AutolinkLiteral", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:422

Experimental

Opt-in: GFM literal autolinks — bare https://… / www.… URLs and email addresses in prose become links, the way GitHub renders them. This is a GFM extension rather than CommonMark, so it is not part of MdastCommonMarkExtension; add it alongside to opt in:

dependencies: [MdastCommonMarkExtension, MdastAutolinkLiteralExtension]

MdastBlockquoteExtension​

const MdastBlockquoteExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/Blockquote", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:310

Experimental

Block quotes (> …), shipping QuoteNode. For blockquotes that hold block-level children (nested lists, code, quotes) with full fidelity, add MdastShadowRootQuoteExtension.


MdastCodeExtension​

const MdastCodeExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/Code", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:376

Experimental

Fenced and indented code blocks, shipping CodeNode.


MdastCommonMarkExtension​

const MdastCommonMarkExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/CommonMark", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:531

Experimental

Convenience bundle of every CommonMark construct: headings, block quotes, lists, code blocks, links, and thematic breaks. GFM features (strikethrough, task lists, literal autolinks, tables) are bundled separately as MdastGfmExtension, and MdastExportExtension (or the MdastExtension bundle) adds serialization back to Markdown.


MdastExportExtension​

const MdastExportExtension: LexicalExtension<Record<never, never>, "@lexical/mdast/Export", MdastExportExtensionOutput, void>

Defined in: packages/lexical-mdast/src/MdastExportExtension.ts:67

Experimental

Markdown serialization for @lexical/mdast. Import (MdastImportExtension and the feature extensions that contribute to it) and export are separate extensions so that editors which only parse Markdown — never serialize back — don't bundle mdast-util-to-markdown.

The export rules themselves are contributed by the same feature extensions that contribute import rules; this extension compiles the shared registry into a serializer:

dependencies: [MdastCommonMarkExtension, MdastExportExtension]

MdastExtension​

const MdastExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/Mdast", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastExtension.ts:27

Experimental

Convenience bundle of MdastImportExtension and MdastExportExtension: Markdown parsing and serialization.

Depend on this when you want both directions without thinking about it:

dependencies: [MdastCommonMarkExtension, MdastExtension]

Editors that never serialize back to Markdown can skip it (feature extensions already pull in MdastImportExtension) and avoid bundling the serializer (mdast-util-to-markdown).


MdastGfmExtension​

const MdastGfmExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/Gfm", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastGfmExtension.ts:30

Experimental

Convenience bundle of every GFM extension — strikethrough, task lists, literal autolinks, and tables — mirroring the scope of micromark-extension-gfm. Combine with MdastCommonMarkExtension for GitHub-flavored Markdown:

dependencies: [MdastCommonMarkExtension, MdastGfmExtension]

Each member is also usable individually when you only want some of GFM (e.g. task lists without tables).


MdastHeadingExtension​

const MdastHeadingExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/Heading", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:293

Experimental

ATX (# …) and setext headings, shipping HeadingNode.


MdastHorizontalRuleExtension​

const MdastHorizontalRuleExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/HorizontalRule", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:493

Experimental

Thematic breaks (---, ***, ___), mapped to HorizontalRuleExtension's HorizontalRuleNode. The original marker character is preserved on round-trip.


MdastHtmlExtension​

const MdastHtmlExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/Html", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastHtmlExtension.ts:1015

Experimental

Opt-in: connects raw HTML in Markdown to the editor's @lexical/html machinery in both directions, instead of treating it as literal text.

Import routes through the DOMImportExtension rule registry:

  • a from-markdown transform reassembles raw HTML into single nodes — block tag sequences (CommonMark splits them on blank lines) become htmlBlock, inline tag runs inside a paragraph (a <u>b</u> c) become htmlInline — tag-balance counting so nesting and interleaved Markdown work, and unclosed tags stay literal text,
  • the import rules parse the HTML with DOMParser and hand it to $generateNodesFromDOM, substituting the pre-imported Markdown — including the Markdown text embedded between block tags, GitHub-style — back in via placeholder elements that inherit the surrounding formatting context (<strong>, style="color: …").

Export handlers build the same shape with rawHtmlBlock: raw tags around embedded Markdown phrasing and blocks, serialized by the handler this extension registers.

Anything with a registered DOM import rule then works from Markdown with no separate mdast importer — a custom node contributes its DOM rule (serving Markdown import and HTML paste alike) and a one-template export.

Not part of MdastCommonMarkExtension because it pulls in the @lexical/html import machinery (and DOMParser, so it requires a DOM); add it alongside to opt in:

dependencies: [MdastCommonMarkExtension, MdastHtmlExtension]

MdastImportExtension​

const MdastImportExtension: LexicalExtension<MdastConfig, "@lexical/mdast/Import", MdastImportExtensionOutput, void>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:216

Experimental

The core Markdown registry for @lexical/mdast, modeled on @lexical/html's DOMImportExtension. It assembles the import/export rules and micromark/mdast extensions contributed by feature extensions into a compiled registry, and exposes Markdown import through its MdastImportExtensionOutput. Markdown export is provided separately by MdastExportExtension, so editors that never serialize back to Markdown don't bundle the serializer.

You normally do not depend on this directly — depend on a feature extension (e.g. MdastCommonMarkExtension) which contributes its rules here and ships the nodes those rules need.

Example​

import {$convertFromMarkdownString, MdastCommonMarkExtension}
from '@lexical/mdast';
import {buildEditorFromExtensions} from '@lexical/extension';
import {defineExtension} from 'lexical';

const editor = buildEditorFromExtensions(
defineExtension({dependencies: [MdastCommonMarkExtension], name: '[root]'}),
);
editor.update(() => $convertFromMarkdownString('# Hi'));

MdastLinkExtension​

const MdastLinkExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/Link", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:395

Experimental

Inline links, CommonMark autolinks (<https://…>), and CommonMark reference links ([text][id] resolved against [id]: url definitions), shipping LinkNode. Reference links are resolved to their target on import and serialize back as inline links. For GFM literal autolinks (bare https://… in prose) add MdastAutolinkLiteralExtension.


MdastListExtension​

const MdastListExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/List", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:338

Experimental

Ordered and unordered lists, shipping ListNode and ListItemNode. For GFM task lists (- [x] …) add MdastTaskListExtension.


MdastRichTextExtension​

const MdastRichTextExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/RichText", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:327

Experimental

Convenience bundle of MdastHeadingExtension and MdastBlockquoteExtension — the constructs backed by @lexical/rich-text nodes.


MdastShadowRootQuoteExtension​

const MdastShadowRootQuoteExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/ShadowRootQuote", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:449

Experimental

Opt-in: import Markdown blockquotes as shadow root QuoteNodes ($createQuoteNode({shadowRoot: true})), which hold block-level children like a table cell. Structured blockquotes — multiple paragraphs, nested lists, code blocks, nested quotes — then round-trip with full fidelity instead of being reassembled from inline content.

Not part of MdastCommonMarkExtension; add it alongside to opt in:

dependencies: [MdastCommonMarkExtension, MdastShadowRootQuoteExtension]

The quote export handler supports both forms per node, so legacy quotes (e.g. created by the > shortcut) and shadow root quotes can coexist.


MdastShortcutsExtension​

const MdastShortcutsExtension: LexicalExtension<MdastShortcutsConfig, "@lexical/mdast/Shortcuts", NamedSignalsOutput<MdastShortcutsConfig>, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:557

Experimental

Streaming Markdown shortcuts (block markers convert on space, fenced code on Enter, inline constructs on their closing delimiter). Each keystroke is fed back through micromark, so shortcut recognition uses the same grammar and the same enabled extensions as import: shortcuts exist for exactly the feature extensions in the editor and no others. Combine with MdastCommonMarkExtension (and MdastGfmExtension) — this extension only wires up the behavior, it does not pull in any grammar of its own.


MdastStrikethroughExtension​

const MdastStrikethroughExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/Strikethrough", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:509

Experimental

GFM ~~strikethrough~~, mapped to the Lexical strikethrough text format. Needs no extra nodes (the core text handlers carry the format bit).


MdastTableExtension​

const MdastTableExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/Table", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastTableExtension.ts:132

Experimental

GFM tables, mapped to @lexical/table nodes. Opt-in (not part of MdastCommonMarkExtension) because it pulls in the @lexical/table nodes it ships. The first table row is treated as the header row in both directions.

Example​

import {MdastShortcutsExtension, MdastTableExtension} from '@lexical/mdast';
import {buildEditorFromExtensions} from '@lexical/extension';
import {defineExtension} from 'lexical';

const editor = buildEditorFromExtensions(
defineExtension({
dependencies: [MdastShortcutsExtension, MdastTableExtension],
name: '[root]',
}),
);

MdastTaskListExtension​

const MdastTaskListExtension: LexicalExtension<ExtensionConfigBase, "@lexical/mdast/TaskList", unknown, unknown>

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:360

Experimental

Opt-in: GFM task lists (- [x] done), layered on MdastListExtension. Contributes the gfmTaskListItem grammar; the list import/export handlers already understand checked, and the typing shortcut ([ ] / [x] in a list item) is enabled by the grammar's presence in the registry.


RenderContextMarkdownExport​

const RenderContextMarkdownExport: RenderStateConfig<boolean>

Defined in: packages/lexical-mdast/src/MdastHtmlExtension.ts:447

Experimental

Render context state that is true while $exportViaDOM renders a node's exportDOM shell for Markdown serialization — the Markdown analog of RenderContextExport from @lexical/html (which is set as well). exportDOM implementations read it with $getRenderContextValue to diverge, e.g. to leave a data-lexical-slot wrapper empty rather than serializing slot HTML that the Markdown embedding replaces anyway.


RenderContextMarkdownSelection​

const RenderContextMarkdownSelection: RenderStateConfig<BaseSelection | null>

Defined in: packages/lexical-mdast/src/MdastExport.ts:509

Render context state carrying the BaseSelection being serialized during a selection export ($convertSelectionToMarkdownString); null during whole-document exports. The export runs synchronously inside the editor read, so registered export rules and contributed to-markdown handlers can read it with $getRenderContextValue — e.g. a root handler that appends end-of-document data (footnote definitions, comments) can emit everything for a document export but only the selection-referenced subset for a clipboard copy.

Functions​

$convertFromMarkdownString()​

$convertFromMarkdownString(markdown, node?): void

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:583

Experimental

Shorthand for $getExtensionOutput(MdastImportExtension).$convertFromMarkdownString. Must be called inside an editor.update(). Throws if the editor was not built with MdastImportExtension (or an extension that depends on it).

Parameters​

markdown​

string

node?​

ElementNode

Returns​

void


$convertFromMdast()​

$convertFromMdast(tree, node?): void

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:600

Experimental

Shorthand for $getExtensionOutput(MdastImportExtension).$convertFromMdast. Must be called inside an editor.update(). Throws if the editor was not built with MdastImportExtension (or an extension that depends on it).

Parameters​

tree​

Root

node?​

ElementNode

Returns​

void


$convertSelectionToMarkdownString()​

$convertSelectionToMarkdownString(selection?): string

Defined in: packages/lexical-mdast/src/MdastExportExtension.ts:119

Experimental

Shorthand for $getExtensionOutput(MdastExportExtension).$convertSelectionToMarkdownString. Serializes only the selected content (defaulting to the current selection) to a Markdown string; returns '' for a null or collapsed selection. Must be called inside an editor.read() or editor.update(). Throws if the editor was not built with MdastExportExtension.

Parameters​

selection?​

BaseSelection | null

Returns​

string


$convertToMarkdownString()​

$convertToMarkdownString(node?): string

Defined in: packages/lexical-mdast/src/MdastExportExtension.ts:94

Experimental

Shorthand for $getExtensionOutput(MdastExportExtension).$convertToMarkdownString. Must be called inside an editor.read() or editor.update(). Throws if the editor was not built with MdastExportExtension.

Parameters​

node?​

ElementNode

Returns​

string


$convertToMdast()​

$convertToMdast(node?): Root

Defined in: packages/lexical-mdast/src/MdastExportExtension.ts:106

Experimental

Shorthand for $getExtensionOutput(MdastExportExtension).$convertToMdast. Must be called inside an editor.read() or editor.update(). Throws if the editor was not built with MdastExportExtension.

Parameters​

node?​

ElementNode

Returns​

Root


$generateNodesFromMarkdownString()​

$generateNodesFromMarkdownString(markdown): LexicalNode[]

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:613

Experimental

Shorthand for $getExtensionOutput(MdastImportExtension).$generateNodesFromMarkdownString. Parses markdown and returns the resulting block-level nodes as a detached array, without modifying the document or the selection. Must be called inside an editor.update(). Throws if the editor was not built with MdastImportExtension (or an extension that depends on it).

Parameters​

markdown​

string

Returns​

LexicalNode[]


$generateNodesFromMdast()​

$generateNodesFromMdast(tree): LexicalNode[]

Defined in: packages/lexical-mdast/src/MdastImportExtension.ts:631

Experimental

Shorthand for $getExtensionOutput(MdastImportExtension).$generateNodesFromMdast. Walks an already-parsed mdast Root tree and returns the resulting block-level nodes as a detached array, without modifying the document or the selection. Must be called inside an editor.update(). Throws if the editor was not built with MdastImportExtension (or an extension that depends on it).

Parameters​

tree​

Root

Returns​

LexicalNode[]


rawHtmlBlock()​

rawHtmlBlock(...parts): HtmlBlock

Defined in: packages/lexical-mdast/src/MdastHtmlExtension.ts:679

Experimental

Builds an mdast node that serializes as raw HTML with Markdown embedded between the tags — the export counterpart of this extension's import side, so what it produces re-imports through the same rules. An export handler for an HTML-encoded construct is just a template:

const $exportCollapsible: MdastExportHandler = (node, ctx) =>
$isCollapsibleNode(node)
? rawHtmlBlock(
'<details><summary>\n',
ctx.exportInline($getSlot(node, 'summary')),
'\n</summary>\n\n',
{flow: ctx.exportChildren(node) as BlockContent[]},
'\n</details>',
)
: null;

The embedded Markdown goes through the regular to-markdown machinery (escaping, nested constructs); only the strings are emitted raw. Requires MdastHtmlExtension, which registers the serializer.

Parameters​

parts​

...RawHtmlBlockPart[]

Returns​

HtmlBlock