Skip to main content

@lexical/markdown

Type Aliases​

ElementTransformer​

ElementTransformer = object

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:60

Properties​

dependencies​

dependencies: Klass<LexicalNode>[]

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:61

export​

export: (node, traverseChildren, selection?) => string | null

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:68

export is called when the $convertToMarkdownString is called to convert the editor state into markdown.

Parameters​
node​

LexicalNode

traverseChildren​

(node) => string

selection?​

BaseSelection | null

Optional selection to filter exported content. When provided, only selected content should be included.

Returns​

string | null

return null to cancel the export, even though the regex matched. Lexical will then search for the next transformer.

regExp​

regExp: RegExp

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:74

replace​

replace: (parentNode, children, match, isImport) => boolean | void

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:80

replace is called when markdown is imported or typed in the editor

Parameters​
parentNode​

ElementNode

children​

LexicalNode[]

match​

string[]

isImport​

boolean

Returns​

boolean | void

return false to cancel the transform, even though the regex matched. Lexical will then search for the next transformer.

triggerOnEnter?​

optional triggerOnEnter?: boolean

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:95

When set, registerMarkdownShortcuts may run this transformer from KEY_ENTER_COMMAND at end-of-line without requiring a trailing space (the update listener still uses the space after the markdown token). Omit or false to disable Enter-triggered shortcuts.

type​

type: "element"

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:89


MultilineElementTransformer​

MultilineElementTransformer = object

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:98

Properties​

dependencies​

dependencies: Klass<LexicalNode>[]

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:112

export?​

optional export?: (node, traverseChildren, selection?) => string | null

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:119

export is called when the $convertToMarkdownString is called to convert the editor state into markdown.

Parameters​
node​

LexicalNode

traverseChildren​

(node) => string

selection?​

BaseSelection | null

Optional selection to filter exported content. When provided, only selected content should be included.

Returns​

string | null

return null to cancel the export, even though the regex matched. Lexical will then search for the next transformer.

handleImportAfterStartMatch?​

optional handleImportAfterStartMatch?: (args) => [boolean, number] | null | undefined

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:105

Use this function to manually handle the import process, once the regExpStart has matched successfully. Without providing this function, the default behavior is to match until regExpEnd is found, or until the end of the document if regExpEnd.optional is true.

Parameters​
args​
lines​

string[]

rootNode​

ElementNode

startLineIndex​

number

startMatch​

RegExpMatchArray

transformer​

MultilineElementTransformer

Returns​

[boolean, number] | null | undefined

a tuple or null. The first element of the returned tuple is a boolean indicating if a multiline element was imported. The second element is the index of the last line that was processed. If null is returned, the next multilineElementTransformer will be tried. If undefined is returned, the default behavior will be used.

regExpEnd?​

optional regExpEnd?: RegExp | { optional?: true; regExp: RegExp; }

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:132

This regex determines when to stop matching. Anything in between regExpStart and regExpEnd will be matched

Union Members​

RegExp


Type Literal​

{ optional?: true; regExp: RegExp; }

optional?​

optional optional?: true

Whether the end match is optional. If true, the end match is not required to match for the transformer to be triggered. The entire text from regexpStart to the end of the document will then be matched.

regExp​

regExp: RegExp

regExpStart​

regExpStart: RegExp

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:128

This regex determines when to start matching

replace​

replace: (rootNode, children, startMatch, endMatch, linesInBetween, isImport) => boolean | void

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:147

replace is called only when markdown is imported in the editor, not when it's typed

Parameters​
rootNode​

ElementNode

children​

LexicalNode[] | null

startMatch​

string[]

endMatch​

string[] | null

linesInBetween​

string[] | null

isImport​

boolean

Returns​

boolean | void

return false to cancel the transform, even though the regex matched. Lexical will then search for the next transformer.

type​

type: "multiline-element"

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:166


TextFormatTransformer​

TextFormatTransformer = Readonly<{ format: readonly TextFormatType[]; intraword?: boolean; tag: string; type: "text-format"; }>

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:169


TextMatchTransformer​

TextMatchTransformer = Readonly<{ dependencies: Klass<LexicalNode>[]; export?: (node, exportChildren, exportFormat) => string | null; getEndIndex?: (node, match) => number | false; importRegExp?: RegExp; regExp: RegExp; replace?: (node, match) => void | TextNode; trigger?: string; type: "text-match"; }>

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:176


Transformer​

Transformer = ElementTransformer | MultilineElementTransformer | TextFormatTransformer | TextMatchTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:54

Variables​

BOLD_ITALIC_STAR​

const BOLD_ITALIC_STAR: TextFormatTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1112


BOLD_ITALIC_UNDERSCORE​

const BOLD_ITALIC_UNDERSCORE: TextFormatTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1118


BOLD_STAR​

const BOLD_STAR: TextFormatTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1125


BOLD_UNDERSCORE​

const BOLD_UNDERSCORE: TextFormatTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1131


CHECK_LIST​

const CHECK_LIST: ElementTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1055


CODE​

const CODE: MultilineElementTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:854


ELEMENT_TRANSFORMERS​

const ELEMENT_TRANSFORMERS: ElementTransformer[]

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1306


HEADING​

const HEADING: ElementTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:795


HIGHLIGHT​

const HIGHLIGHT: TextFormatTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1106


INLINE_CODE​

const INLINE_CODE: TextFormatTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1081


ITALIC_STAR​

const ITALIC_STAR: TextFormatTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1144


ITALIC_UNDERSCORE​

const ITALIC_UNDERSCORE: TextFormatTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1150


const LINK: TextMatchTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1174


MULTILINE_ELEMENT_TRANSFORMERS​

const MULTILINE_ELEMENT_TRANSFORMERS: MultilineElementTransformer[]

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1313


ORDERED_LIST​

const ORDERED_LIST: ElementTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1068


QUOTE​

const QUOTE: ElementTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:815


STRIKETHROUGH​

const STRIKETHROUGH: TextFormatTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1138


TEXT_FORMAT_TRANSFORMERS​

const TEXT_FORMAT_TRANSFORMERS: TextFormatTransformer[]

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1321


TEXT_MATCH_TRANSFORMERS​

const TEXT_MATCH_TRANSFORMERS: TextMatchTransformer[]

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1333


TRANSFORMERS​

const TRANSFORMERS: Transformer[]

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1349


UNORDERED_LIST​

const UNORDERED_LIST: ElementTransformer

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:1042

Functions​

$convertFromMarkdownString()​

$convertFromMarkdownString(markdown, transformers?, node?, shouldPreserveNewLines?, shouldMergeAdjacentLines?): void

Defined in: packages/lexical-markdown/src/index.ts:62

Renders markdown from a string. The selection is moved to the start after the operation.

Parameters​

markdown​

string

transformers?​

Transformer[] = TRANSFORMERS

node?​

ElementNode

shouldPreserveNewLines?​

boolean = false

By setting this to true, new lines will be preserved between conversions

shouldMergeAdjacentLines?​

boolean = false

By setting this to true, adjacent non empty lines will be merged according to commonmark spec: https://spec.commonmark.org/0.24/#example-177. Not applicable if shouldPreserveNewLines = true.

Returns​

void


$convertSelectionToMarkdownString()​

$convertSelectionToMarkdownString(transformers?, selection, shouldPreserveNewLines?): string

Defined in: packages/lexical-markdown/src/index.ts:130

Converts the selected content to a markdown string.

Parameters​

transformers?​

Transformer[] = TRANSFORMERS

selection​

BaseSelection | null

shouldPreserveNewLines?​

boolean = false

Returns​

string


$convertToMarkdownString()​

$convertToMarkdownString(transformers?, node?, shouldPreserveNewLines?): string

Defined in: packages/lexical-markdown/src/index.ts:115

Renders string from markdown. The selection is moved to the start after the operation.

Parameters​

transformers?​

Transformer[] = TRANSFORMERS

node?​

ElementNode

shouldPreserveNewLines?​

boolean = false

Returns​

string


$generateNodesFromMarkdownString()​

$generateNodesFromMarkdownString(markdown, transformers?, shouldPreserveNewLines?, shouldMergeAdjacentLines?): LexicalNode[]

Defined in: packages/lexical-markdown/src/index.ts:93

Parses a markdown string and returns the resulting nodes as an array, without modifying the document tree or selection. The returned nodes can be inserted at an arbitrary position via selection.insertNodes().

Parameters​

markdown​

string

transformers?​

Transformer[] = TRANSFORMERS

shouldPreserveNewLines?​

boolean = false

By setting this to true, new lines will be preserved between conversions

shouldMergeAdjacentLines?​

boolean = false

By setting this to true, adjacent non empty lines will be merged according to commonmark spec: https://spec.commonmark.org/0.24/#example-177. Not applicable if shouldPreserveNewLines = true.

Returns​

LexicalNode[]


isTableRowDivider()​

isTableRowDivider(line): boolean

Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:239

Whether line is a Markdown table delimiter row such as | --- | :--: |.

This is the linear-time equivalent of /^(\| ?:?-*:? ?)+\|\s?$/. That pattern nests -* inside a (...)+ group, a shape that backtracking regexp engines (e.g. Safari/JavaScriptCore) may run in super-linear time. A manual scan is guaranteed O(n).

Parameters​

line​

string

Returns​

boolean


registerMarkdownShortcuts()​

registerMarkdownShortcuts(editor, transformers?): () => void

Defined in: packages/lexical-markdown/src/MarkdownShortcuts.ts:480

Parameters​

editor​

LexicalEditor

transformers?​

Transformer[] = TRANSFORMERS

Returns​

() => void