Skip to content

Type Editor


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

ts
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

ParameterTypeDescription
schemaSchemaThe parser's document schema.
tokenizerMarkdownItThis parser's markdown-it tokenizer.
tokensRecord<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

PropertyModifierTypeDefined in
schemareadonlySchemafrom-markdown/MarkdownParser.ts:18
tokenizerreadonlyMarkdownItfrom-markdown/MarkdownParser.ts:19
tokensreadonlyRecord<string, ParseSpec>from-markdown/MarkdownParser.ts:20

Methods

parse()

ts
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

ParameterTypeDescription
textstringThe markdown text to parse.
markdownEnvobjectOptional environment object passed to the markdown-it parser.

Returns

Node_2

The parsed ProseMirror document node.