Skip to content

Type Editor


Type Editor / @type-editor/markdown / from-markdown/MarkdownParseState / MarkdownParseState

Class: MarkdownParseState

Defined in: from-markdown/MarkdownParseState.ts:13

Manages the state during markdown parsing, maintaining a stack of nodes being constructed and tracking active marks. This class handles the incremental building of a ProseMirror document tree from markdown-it tokens.

Constructors

Constructor

ts
new MarkdownParseState(schema, tokenHandlers): MarkdownParseState;

Defined in: from-markdown/MarkdownParseState.ts:25

Creates a new markdown parse state.

Parameters

ParameterTypeDescription
schemaSchemaThe ProseMirror schema to use for creating nodes and marks.
tokenHandlersRecord<string, TokenHandler>A map of token types to handler functions that process those tokens.

Returns

MarkdownParseState

Accessors

stack

Get Signature

ts
get stack(): StackElement[];

Defined in: from-markdown/MarkdownParseState.ts:39

Gets the current parsing stack.

Returns

StackElement[]

The array of stack elements representing the current parsing context.

Methods

addNode()

ts
addNode(
   type,
   attrs,
   content?): Node_2;

Defined in: from-markdown/MarkdownParseState.ts:125

Adds a node at the current position in the document tree.

Parameters

ParameterTypeDescription
typeNodeTypeThe type of node to create.
attrsReadonly<Record<string, any>>The attributes for the node.
content?readonly Node_2[]Optional child nodes for the node.

Returns

Node_2

The created node, or null if creation failed.


addText()

ts
addText(text): void;

Defined in: from-markdown/MarkdownParseState.ts:50

Adds the given text to the current position in the document, using the current marks as styling. Attempts to merge with the previous text node if they share the same marks.

Parameters

ParameterTypeDescription
textstringThe text content to add. If empty or falsy, no action is taken.

Returns

void


closeMark()

ts
closeMark(mark): void;

Defined in: from-markdown/MarkdownParseState.ts:91

Removes the given mark from the set of active marks.

Parameters

ParameterTypeDescription
markMarkTypeThe mark type to remove from the active set.

Returns

void


closeNode()

ts
closeNode(): Node_2;

Defined in: from-markdown/MarkdownParseState.ts:160

Closes the node currently on top of the stack and adds it to its parent.

Returns

Node_2

The closed node.


openMark()

ts
openMark(mark): void;

Defined in: from-markdown/MarkdownParseState.ts:81

Adds the given mark to the set of active marks. Active marks are applied to all text nodes added until the mark is closed.

Parameters

ParameterTypeDescription
markMarkThe mark instance to add to the active set.

Returns

void


openNode()

ts
openNode(type, attrs): void;

Defined in: from-markdown/MarkdownParseState.ts:146

Opens a new node context on the stack. Subsequent content will be added as children to this node until closeNode is called.

Parameters

ParameterTypeDescription
typeNodeTypeThe type of node to open.
attrsReadonly<Record<string, any>>The attributes for the node.

Returns

void


parseTokens()

ts
parseTokens(tokens): void;

Defined in: from-markdown/MarkdownParseState.ts:102

Parses an array of markdown-it tokens and processes them using registered handlers.

Parameters

ParameterTypeDescription
tokensToken[]The array of tokens to parse.

Returns

void

Throws

If a token type has no registered handler.