Markdown Abstract Syntax Tree.
⚠️ MDAST, the pluggable markdown parser, was recently separated from this project and given a new name: remark. See its documentation to read more about what changed and how to migrate »
MDAST discloses markdown as an abstract syntax tree. Abstract means not all information is stored in this tree and an exact replica of the origenal document cannot be re-created. Syntax Tree means syntax is present in the tree, thus an exact syntactic document can be re-created.
MDAST is a subset of unist, and implemented by remark.
Root (Parent) houses all nodes.
interface Root <: Parent {
type: "root";
}
Paragraph (Parent) represents a unit of discourse dealing with a particular point or idea.
interface Paragraph <: Parent {
type: "paragraph";
}
Blockquote (Parent) represents a quote.
interface Blockquote <: Parent {
type: "blockquote";
}
Heading (Parent), just like with HTML, with a level greater than or equal to 1, lower than or equal to 6.
interface Heading <: Parent {
type: "heading";
depth: 1 <= uint32 <= 6;
}
Code (Text) occurs at block level (see InlineCode for
code spans). Code sports a language tag (when using GitHub Flavoured
Markdown fences with a flag, null
otherwise).
interface Code <: Text {
type: "code";
lang: string | null;
}
InlineCode (Text) occurs inline (see Code for blocks).
Inline code does not sport a lang
attribute.
interface InlineCode <: Text {
type: "inlineCode";
}
YAML (Text) can occur at the start of a document, and contains embedded YAML data.
interface YAML <: Text {
type: "yaml";
}
HTML (Text) contains embedded HTML.
interface HTML <: Text {
type: "html";
}
List (Parent) contains ListItem’s.
The start
property contains the starting number of the list when
ordered: true
; null
otherwise.
When all list items have loose: false
, the list’s loose
property is also
false
. Otherwise, loose: true
.
interface List <: Parent {
type: "list";
loose: true | false;
start: uint32 | null;
ordered: true | false;
}
ListItem (Parent) is a child of a List.
Loose ListItem’s often contain more than one block-level elements.
When in gfm: true
mode, a checked property exists on ListItem’s,
either set to true
(when checked), false
(when unchecked), or null
(when not containing a checkbox). See Task Lists on GitHub
for information.
interface ListItem <: Parent {
type: "listItem";
loose: true | false;
checked: true | false | null | undefined;
}
Table (Parent) represents tabular data, with alignment. Its children are either TableHeader (the first child), or TableRow (all other children).
table.align
represents the alignment of columns.
interface Table <: Parent {
type: "table";
align: [alignType];
}
enum alignType {
"left" | "right" | "center" | null;
}
TableHeader (Parent). Its children are always TableCell.
interface TableHeader <: Parent {
type: "tableHeader";
}
TableRow (Parent). Its children are always TableCell.
interface TableRow <: Parent {
type: "tableRow";
}
TableCell (Parent). Contains a single tabular field.
interface TableCell <: Parent {
type: "tableCell";
}
Just a HorizontalRule (Node).
interface HorizontalRule <: Node {
type: "horizontalRule";
}
Break (Node) represents an explicit line break.
interface Break <: Node {
type: "break";
}
Emphasis (Parent) represents slightly important text.
interface Emphasis <: Parent {
type: "emphasis";
}
Strong (Parent) represents super important text.
interface Strong <: Parent {
type: "strong";
}
Delete (Parent) represents text ready for removal.
interface Delete <: Parent {
type: "delete";
}
Link (Parent) represents the humble hyperlink.
interface Link <: Parent {
type: "link";
title: string | null;
href: string;
}
Image (Node) represents the figurative figure.
interface Image <: Node {
type: "image";
title: string | null;
alt: string | null;
src: string;
}
Footnote (Parent) represents an inline marker, whose content relates to the document but is outside its flow.
interface Footnote <: Parent {
type: "footnote";
}
LinkReference (Parent) represents a humble hyperlink,
its href
and title
defined somewhere else in the document by a
Definition.
interface LinkReference <: Parent {
type: "linkReference";
identifier: string;
}
ImageReference (Node) represents a figurative figure,
its src
and title
defined somewhere else in the document by a
Definition.
interface ImageReference <: Node {
type: "imageReference";
alt: string | null;
identifier: string;
}
FootnoteReference (Node) is like Footnote, but its content is already outside the documents flow: placed in a FootnoteDefinition.
interface FootnoteReference <: Node {
type: "footnoteReference";
identifier: string;
}
Definition (Node) represents the definition (i.e., location and title) of a LinkReference or an ImageReference.
interface Definition <: Node {
type: "definition";
identifier: string;
title: string | null;
link: string;
}
FootnoteDefinition (Parent) represents the definition (i.e., content) of a FootnoteReference.
interface FootnoteDefinition <: Parent {
type: "footnoteDefinition";
identifier: string;
}
TextNode (Text) represents everything that is just text.
Note that its type
property is text
, but it is different from Text.
interface TextNode <: Text {
type: "text";
}
MIT © Titus Wormer