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
new MarkdownParseState(schema, tokenHandlers): MarkdownParseState;Defined in: from-markdown/MarkdownParseState.ts:25
Creates a new markdown parse state.
Parameters
| Parameter | Type | Description |
|---|---|---|
schema | Schema | The ProseMirror schema to use for creating nodes and marks. |
tokenHandlers | Record<string, TokenHandler> | A map of token types to handler functions that process those tokens. |
Returns
MarkdownParseState
Accessors
stack
Get Signature
get stack(): StackElement[];Defined in: from-markdown/MarkdownParseState.ts:39
Gets the current parsing stack.
Returns
The array of stack elements representing the current parsing context.
Methods
addNode()
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
| Parameter | Type | Description |
|---|---|---|
type | NodeType | The type of node to create. |
attrs | Readonly<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()
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
| Parameter | Type | Description |
|---|---|---|
text | string | The text content to add. If empty or falsy, no action is taken. |
Returns
void
closeMark()
closeMark(mark): void;Defined in: from-markdown/MarkdownParseState.ts:91
Removes the given mark from the set of active marks.
Parameters
| Parameter | Type | Description |
|---|---|---|
mark | MarkType | The mark type to remove from the active set. |
Returns
void
closeNode()
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()
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
| Parameter | Type | Description |
|---|---|---|
mark | Mark | The mark instance to add to the active set. |
Returns
void
openNode()
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
| Parameter | Type | Description |
|---|---|---|
type | NodeType | The type of node to open. |
attrs | Readonly<Record<string, any>> | The attributes for the node. |
Returns
void
parseTokens()
parseTokens(tokens): void;Defined in: from-markdown/MarkdownParseState.ts:102
Parses an array of markdown-it tokens and processes them using registered handlers.
Parameters
| Parameter | Type | Description |
|---|---|---|
tokens | Token[] | The array of tokens to parse. |
Returns
void
Throws
If a token type has no registered handler.