Markdown Abstract Syntax Tree.
mdast is a specification for representing markdown in a syntax
tree.
It implements unist.
It can represent several flavours of markdown,
such as CommonMark and GitHub Flavored Markdown.
This document may not be released.
See releases for released documents.
The latest released version is 5.0.0.
Contents
Introduction
This document defines a format for representing markdown as an abstract
syntax tree.
Development of mdast started in July 2014,
in remark,
before unist existed.
This specification is written in a Web IDL-like grammar.
Where this specification fits
mdast extends unist,
a format for syntax trees,
to benefit from its ecosystem of utilities.
mdast relates to JavaScript in that it has a rich ecosystem of
utilities for working with compliant syntax trees in
JavaScript.
However,
mdast is not limited to JavaScript and can be used in other programming
languages.
mdast relates to the unified and remark projects in that mdast syntax
trees are used throughout their ecosystems.
Types
If you are using TypeScript,
you can use the unist types by installing them with npm:
Nodes (abstract)
Literal
interface Literal <: UnistLiteral {
value: string
}
Literal (UnistLiteral) represents an abstract
interface in mdast containing a value.
Its value field is a string.
Parent
interface Parent <: UnistParent {
children: [MdastContent]
}
Parent (UnistParent) represents an abstract
interface in mdast containing other nodes (said to be children).
Its content is limited to only other mdast content.
Nodes
Blockquote
interface Blockquote <: Parent {
type: 'blockquote'
children: [FlowContent]
}
Blockquote (Parent) represents a section quoted from
somewhere else.
Blockquote can be used where flow content is
expected.
Its content model is also flow content.
For example,
the following markdown:
Yields:
{
type: 'blockquote',
children: [{
type: 'paragraph',
children: [{type: 'text', value: 'Alpha bravo charlie.'}]
}]
}
Break
interface Break <: Node {
type: 'break'
}
Break (Node) represents a line break,
such as in poems or addresses.
Break can be used where phrasing content is
expected.
It has no content model.
For example,
the following markdown:
Yields:
{
type: 'paragraph',
children: [
{type: 'text', value: 'foo'},
{type: 'break'},
{type: 'text', value: 'bar'}
]
}
Code
interface Code <: Literal {
type: 'code'
lang: string?
meta: string?
}
Code (Literal) represents a block of preformatted text,
such as ASCII art or computer code.
Code can be used where flow content is expected.
Its content is represented by its value field.
This node relates to the phrasing content concept
InlineCode.
A lang field can be present.
It represents the language of computer code being marked up.
If the lang field is present,
a meta field can be present.
It represents custom information relating to the node.
For example,
the following markdown:
Yields:
{
type: 'code',
lang: null,
meta: null,
value: 'foo()'
}
And the following markdown:
```js highlight-line="2"
foo()
bar()
baz()
```
Yields:
{
type: 'code',
lang: 'js',
meta: 'highlight-line="2"',
value: 'foo()\nbar()\nbaz()'
}
Definition
interface Definition <: Node {
type: 'definition'
}
Definition includes Association
Definition includes Resource
Definition (Node) represents a resource.
Definition can be used where content is expected.
It has no content model.
Definition includes the mixins Association and
Resource.
Definition should be associated with
LinkReferences and
ImageReferences.
For example,
the following markdown:
[Alpha]: https://example.com
Yields:
{
type: 'definition',
identifier: 'alpha',
label: 'Alpha',
url: 'https://example.com',
title: null
}
Emphasis
interface Emphasis <: Parent {
type: 'emphasis'
children: [PhrasingContent]
}
Emphasis (Parent) represents stress emphasis of its
contents.
Emphasis can be used where phrasing content is
expected.
Its content model is phrasing content.
For example,
the following markdown:
Yields:
{
type: 'paragraph',
children: [
{
type: 'emphasis',
children: [{type: 'text', value: 'alpha'}]
},
{type: 'text', value: ' '},
{
type: 'emphasis',
children: [{type: 'text', value: 'bravo'}]
}
]
}
Heading
interface Heading <: Parent {
type: 'heading'
depth: 1 <= number <= 6
children: [PhrasingContent]
}
Heading (Parent) represents a heading of a section.
Heading can be used where flow content is expected.
Its content model is phrasing content.
A depth field must be present.
A value of 1 is said to be the highest rank and 6 the lowest.
For example,
the following markdown:
Yields:
{
type: 'heading',
depth: 1,
children: [{type: 'text', value: 'Alpha'}]
}
Html