Type Editor / @type-editor/markdown / from-markdown/MarkdownParser / MarkdownParser
Class: MarkdownParser
Defined in: from-markdown/MarkdownParser.ts:16
A configuration of a Markdown parser. Such a parser uses markdown-it to tokenize a file, and then runs the custom rules it is given over the tokens to create a ProseMirror document tree.
Constructors
Constructor
new MarkdownParser(
schema,
tokenizer,
tokens): MarkdownParser;Defined in: from-markdown/MarkdownParser.ts:36
Create a parser with the given configuration. You can configure the markdown-it parser to parse the dialect you want, and provide a description of the ProseMirror entities those tokens map to in the tokens object, which maps token names to descriptions of what to do with them. Such a description is an object, and may have the following properties:
Parameters
| Parameter | Type | Description |
|---|---|---|
schema | Schema | The parser's document schema. |
tokenizer | MarkdownIt | This parser's markdown-it tokenizer. |
tokens | Record<string, ParseSpec> | The value of the tokens object used to construct this parser. Can be useful to copy and modify to base other parsers on. |
Returns
MarkdownParser
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
schema | readonly | Schema | from-markdown/MarkdownParser.ts:18 |
tokenizer | readonly | MarkdownIt | from-markdown/MarkdownParser.ts:19 |
tokens | readonly | Record<string, ParseSpec> | from-markdown/MarkdownParser.ts:20 |
Methods
parse()
parse(text, markdownEnv?): Node_2;Defined in: from-markdown/MarkdownParser.ts:59
Parse a string as CommonMark markup, and create a ProseMirror document as prescribed by this parser's rules.
The second argument, when given, is passed through to the Markdown parser.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | string | The markdown text to parse. |
markdownEnv | object | Optional environment object passed to the markdown-it parser. |
Returns
Node_2
The parsed ProseMirror document node.