@lexical/markdown
Type Aliases
ElementTransformer
ElementTransformer =
object
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:54
Properties
dependencies
dependencies:
Klass<LexicalNode>[]
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:55
export()
export: (
node,traverseChildren) =>string|null
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:61
export is called when the $convertToMarkdownString is called to convert the editor state into markdown.
Parameters
node
traverseChildren
(node) => string
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:66
replace()
replace: (
parentNode,children,match,isImport) =>boolean|void
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:72
replace is called when markdown is imported or typed in the editor
Parameters
parentNode
children
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.
type
type:
"element"
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:81
MultilineElementTransformer
MultilineElementTransformer =
object
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:84
Properties
dependencies
dependencies:
Klass<LexicalNode>[]
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:98
export()?
optionalexport: (node,traverseChildren) =>string|null
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:104
export is called when the $convertToMarkdownString is called to convert the editor state into markdown.
Parameters
node
traverseChildren
(node) => string
Returns
string | null
return null to cancel the export, even though the regex matched. Lexical will then search for the next transformer.
handleImportAfterStartMatch()?
optionalhandleImportAfterStartMatch: (args) => [boolean,number] |null|undefined
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:91
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
startLineIndex
number
startMatch
RegExpMatchArray
transformer
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?
optionalregExpEnd:RegExp| {optional?:true;regExp:RegExp; }
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:116
This regex determines when to stop matching. Anything in between regExpStart and regExpEnd will be matched
Type Declaration
RegExp
{ optional?: true; regExp: RegExp; }
optional?
optionaloptional: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:112
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:131
replace is called only when markdown is imported in the editor, not when it's typed
Parameters
rootNode
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:150
TextFormatTransformer
TextFormatTransformer =
Readonly<{format:ReadonlyArray<TextFormatType>;intraword?:boolean;tag:string;type:"text-format"; }>
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:153
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:160
Transformer
Transformer =
ElementTransformer|MultilineElementTransformer|TextFormatTransformer|TextMatchTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:48
Variables
BOLD_ITALIC_STAR
constBOLD_ITALIC_STAR:TextFormatTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:528
BOLD_ITALIC_UNDERSCORE
constBOLD_ITALIC_UNDERSCORE:TextFormatTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:534
BOLD_STAR
constBOLD_STAR:TextFormatTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:541
BOLD_UNDERSCORE
constBOLD_UNDERSCORE:TextFormatTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:547
CHECK_LIST
constCHECK_LIST:ElementTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:496
CODE
constCODE:MultilineElementTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:403
ELEMENT_TRANSFORMERS
constELEMENT_TRANSFORMERS:ElementTransformer[]
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:625
HEADING
constHEADING:ElementTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:348
HIGHLIGHT
constHIGHLIGHT:TextFormatTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:522
INLINE_CODE
constINLINE_CODE:TextFormatTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:516
ITALIC_STAR
constITALIC_STAR:TextFormatTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:560
ITALIC_UNDERSCORE
constITALIC_UNDERSCORE:TextFormatTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:566
LINK
constLINK:TextMatchTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:577
MULTILINE_ELEMENT_TRANSFORMERS
constMULTILINE_ELEMENT_TRANSFORMERS:MultilineElementTransformer[]
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:632
ORDERED_LIST
constORDERED_LIST:ElementTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:506
QUOTE
constQUOTE:ElementTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:365
STRIKETHROUGH
constSTRIKETHROUGH:TextFormatTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:554
TEXT_FORMAT_TRANSFORMERS
constTEXT_FORMAT_TRANSFORMERS:TextFormatTransformer[]
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:639
TEXT_MATCH_TRANSFORMERS
constTEXT_MATCH_TRANSFORMERS:TextMatchTransformer[]
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:651
TRANSFORMERS
constTRANSFORMERS:Transformer[]
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:653
UNORDERED_LIST
constUNORDERED_LIST:ElementTransformer
Defined in: packages/lexical-markdown/src/MarkdownTransformers.ts:486
Functions
$convertFromMarkdownString()
$convertFromMarkdownString(
markdown,transformers,node?,shouldPreserveNewLines?,shouldMergeAdjacentLines?):void
Defined in: packages/lexical-markdown/src/index.ts:52
Renders markdown from a string. The selection is moved to the start after the operation.
Parameters
markdown
string
transformers
Transformer[] = TRANSFORMERS
node?
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
$convertToMarkdownString()
$convertToMarkdownString(
transformers,node?,shouldPreserveNewLines?):string
Defined in: packages/lexical-markdown/src/index.ts:72
Renders string from markdown. The selection is moved to the start after the operation.
Parameters
transformers
Transformer[] = TRANSFORMERS
node?
shouldPreserveNewLines?
boolean = false
Returns
string
registerMarkdownShortcuts()
registerMarkdownShortcuts(
editor,transformers): () =>void
Defined in: packages/lexical-markdown/src/MarkdownShortcuts.ts:396
Parameters
editor
transformers
Transformer[] = TRANSFORMERS
Returns
():
void
Returns
void