GFM: tables, strikethrough, task list items, and autolink literals
Footnotes([^1] and [^1]: note) and inline notes(^[note])
Front matter: YAML(---), TOML(+++), JSON(;;; or {)
The parser follows CommonMark for everything CommonMark defines, and GFM for the extensions GFM defines.
The node of each syntax, its properties, and its range are defined in the Markdown parsing requirements.
Front matter and footnotes are not part of CommonMark/GFM, so their nodes are extension nodes with lowercase type names: yaml, toml, json, footnoteReference, footnoteDefinition, and footnote.
The AST consists of TxtNodes.
A TxtNode of the AST has following properties:
loc - Nodes have line and column-based location info.
range - Nodes have an index-based location range (array).
raw - Node have a raw text.
value - Node have a value of text.
raw, range, and loc of a node always describe the same span of the text.
If you need a general-purpose Markdown parser (mdast, HTML output, plugins), please use remark directly.
Design
The parser is written with data-oriented design for performance.
See the Markdown parsing design for details.
Nodes are stored in flat typed arrays (struct of arrays) and refer to each other by index while parsing
Strings are not copied while parsing. raw and value are sliced from the source text when the AST is emitted
TxtNode objects are created only once at the end. There is no intermediate AST such as mdast
Working buffers are reused between parse() calls
Parsing time is proportional to the size of the text, including for inputs that repeat unclosed syntax
Nesting limit
The parser does not overflow the call stack for deeply nested inputs.
The nesting depth is limited to 100 for block containers (BlockQuote, List, ListItem, footnoteDefinition) and 100 for inline nodes (Emphasis, Strong, Delete, Link, LinkReference, footnote)
The markers beyond the limit are not parsed as syntax. They are kept as text
The tree is built and emitted with loops and explicit stacks instead of recursion
parse(text, options) takes these options. All of them are false by default.
cjkFriendlyEmphasis: Recognize emphasis, strong emphasis, and strikethrough next to CJK punctuation, as the CommonMark CJK-friendly Amendments define. **強調。**この文 becomes Strong and Str.