Type Editor / @type-editor/model / content-parser/ContentParser / ContentParser
Class: ContentParser
Defined in: packages/model/src/content-parser/ContentParser.ts:23
Parser for ProseMirror content expressions.
Content expressions use a regular-expression-like syntax to describe what content is allowed in a node. For example:
- "paragraph+" means one or more paragraphs
- "heading | paragraph" means a heading or paragraph
- "block{2,4}" means 2 to 4 block elements
The parser converts these expressions into a ContentMatch automaton that can efficiently validate and match node sequences.
Constructors
Constructor
new ContentParser(): ContentParser;Returns
ContentParser
Methods
parse()
parse(string, nodeTypes): ContentMatch;Defined in: packages/model/src/content-parser/ContentParser.ts:52
Parses a content expression string into a ContentMatch automaton.
Parameters
| Parameter | Type | Description |
|---|---|---|
string | string | The content expression to parse |
nodeTypes | Readonly<Record<string, NodeType>> | Map of available node type names to NodeType objects |
Returns
A ContentMatch representing the valid content patterns
Throws
If the content expression is invalid
parse()
static parse(string, nodeTypes): ContentMatch;Defined in: packages/model/src/content-parser/ContentParser.ts:39
Parses a content expression string into a ContentMatch automaton.
Parameters
| Parameter | Type | Description | | ----------- | ------------------------------------------------------------------------------------------------------ | ---------------------------------------------------- | --------- | | string | string | The content expression to parse (e.g., "paragraph+ | heading") | | nodeTypes | Readonly<Record<string, NodeType>> | Map of available node type names to NodeType objects |
Returns
A ContentMatch representing the valid content patterns
Throws
If the content expression is invalid