Doc Tree Node Types
Complete type reference for the DocDocument tree returned by toDocTree().
Type Hierarchy
DocDocument
└── children: DocBlockNode[]
├── DocHeading { depth: 1-6, children: DocInlineNode[] }
├── DocParagraph { children: DocInlineNode[] }
├── DocBlockquote { children: DocBlockNode[] }
├── DocCodeBlock { lang: string|null, value: string }
├── DocList { ordered: boolean, start: number|null, children: DocListItem[] }
│ └── DocListItem { checked: boolean|null, children: (DocBlockNode|DocInlineNode)[] }
├── DocTable { align: [...], children: DocTableRow[] }
│ └── DocTableRow { isHeader: boolean, children: DocTableCell[] }
│ └── DocTableCell { children: DocInlineNode[] }
├── DocHorizontalRule { type: 'thematicBreak' }
└── DocFootnoteDefinition { identifier: string, label: string|null, children: DocBlockNode[] }
DocInlineNode
├── DocText { value: string, bold: boolean, italic: boolean, strikethrough: boolean }
├── DocInlineCode { value: string }
├── DocLink { url: string, title: string|null, children: DocInlineNode[] }
├── DocImage { url: string, alt: string|null, title: string|null }
├── DocBreak
└── DocFootnoteReference { identifier: string, label: string|null }
Block Node Interfaces
DocDocument
interface DocDocument {
type: 'document'
children: DocBlockNode[]
}
The root of every tree returned by toDocTree().
DocHeading
interface DocHeading {
type: 'heading'
depth: 1 | 2 | 3 | 4 | 5 | 6
children: DocInlineNode[]
}
DocParagraph
interface DocParagraph {
type: 'paragraph'
children: DocInlineNode[]
}
DocBlockquote
interface DocBlockquote {
type: 'blockquote'
children: DocBlockNode[]
}
Blockquotes can contain any block-level content including nested blockquotes.
DocCodeBlock
interface DocCodeBlock {
type: 'code'
lang: string | null
value: string
}
lang is the info string from a fenced code block (e.g., "typescript"), or null for indented or unlabelled blocks.
DocList
interface DocList {
type: 'list'
ordered: boolean
start: number | null
children: DocListItem[]
}
start is the number of the first item of an ordered list (3 for a list that begins 3.) and null for unordered lists. Added in 2.1.0.
DocListItem
interface DocListItem {
type: 'listItem'
checked: boolean | null
children: (DocBlockNode | DocInlineNode)[]
}
checked is true/false for GFM task list items (- [x] / - [ ]) and null for regular list items.
DocTable
interface DocTable {
type: 'table'
align: Array<'left' | 'right' | 'center' | null>
children: DocTableRow[]
}
align contains one entry per column. null means no alignment specified.
DocTableRow
interface DocTableRow {
type: 'tableRow'
isHeader: boolean
children: DocTableCell[]
}
isHeader is true for the first row (the header row) of a GFM table.
DocTableCell
interface DocTableCell {
type: 'tableCell'
children: DocInlineNode[]
}
DocHorizontalRule
interface DocHorizontalRule {
type: 'thematicBreak'
}
DocFootnoteDefinition
interface DocFootnoteDefinition {
type: 'footnoteDefinition'
identifier: string
label: string | null
children: DocBlockNode[]
}
The body of a GFM footnote ([^1]: …). Definitions are moved to the end of the document: referenced ones first, in the order they are first referenced, then any that are never referenced. Footnote numbers aren't stored in the tree; number definitions by their position if you need them. Added in 2.1.0.
Inline Node Interfaces
DocText
interface DocText {
type: 'text'
value: string
bold: boolean
italic: boolean
strikethrough: boolean
}
Nested strong/emphasis/delete marks from the MDAST are flattened into boolean flags. A node that is both bold and italic has bold: true, italic: true.
DocInlineCode
interface DocInlineCode {
type: 'inlineCode'
value: string
}
DocLink
interface DocLink {
type: 'link'
url: string
title: string | null
children: DocInlineNode[]
}
url is sanitised: dangerous protocols such as javascript: are replaced with # (since 2.0.1; see Security).
DocImage
interface DocImage {
type: 'image'
url: string
alt: string | null
title: string | null
}
url is sanitised the same way (since 2.0.1).
DocBreak
interface DocBreak {
type: 'break'
}
Represents a hard line break (two trailing spaces or \ before newline).
DocFootnoteReference
interface DocFootnoteReference {
type: 'footnoteReference'
identifier: string
label: string | null
}
A GFM footnote marker such as [^1]. identifier is the normalised label used to match the definition; label is the label as written. Added in 2.1.0.
Union Type Aliases
type DocInlineNode =
| DocText
| DocInlineCode
| DocLink
| DocImage
| DocBreak
| DocFootnoteReference
type DocBlockNode =
| DocHeading
| DocParagraph
| DocBlockquote
| DocCodeBlock
| DocList
| DocTable
| DocHorizontalRule
| DocFootnoteDefinition
type DocTreeNode =
| DocDocument
| DocBlockNode
| DocListItem
| DocTableRow
| DocTableCell
| DocInlineNode
Full JSON Example
Input Markdown:
# Title
A paragraph with **bold** and *italic*.
> Blockquote
- [x] Task done
- [ ] Task pending
| Name | Age |
|------|-----|
| Alice | 30 |
Output (abbreviated):
{
"type": "document",
"children": [
{ "type": "heading", "depth": 1, "children": [{ "type": "text", "value": "Title", "bold": false, "italic": false, "strikethrough": false }] },
{ "type": "paragraph", "children": [
{ "type": "text", "value": "A paragraph with ", "bold": false, "italic": false, "strikethrough": false },
{ "type": "text", "value": "bold", "bold": true, "italic": false, "strikethrough": false },
{ "type": "text", "value": " and ", "bold": false, "italic": false, "strikethrough": false },
{ "type": "text", "value": "italic", "bold": false, "italic": true, "strikethrough": false },
{ "type": "text", "value": ".", "bold": false, "italic": false, "strikethrough": false }
]
},
{ "type": "blockquote", "children": [{ "type": "paragraph", "children": [{ "type": "text", "value": "Blockquote", "bold": false, "italic": false, "strikethrough": false }] }] },
{ "type": "list", "ordered": false, "children": [
{ "type": "listItem", "checked": true, "children": [{ "type": "paragraph", "children": [{ "type": "text", "value": "Task done", "bold": false, "italic": false, "strikethrough": false }] }] },
{ "type": "listItem", "checked": false, "children": [{ "type": "paragraph", "children": [{ "type": "text", "value": "Task pending", "bold": false, "italic": false, "strikethrough": false }] }] }
]
},
{ "type": "table", "align": [null, null], "children": [
{ "type": "tableRow", "isHeader": true, "children": [
{ "type": "tableCell", "children": [{ "type": "text", "value": "Name", "bold": false, "italic": false, "strikethrough": false }] },
{ "type": "tableCell", "children": [{ "type": "text", "value": "Age", "bold": false, "italic": false, "strikethrough": false }] }
]
},
{ "type": "tableRow", "isHeader": false, "children": [
{ "type": "tableCell", "children": [{ "type": "text", "value": "Alice", "bold": false, "italic": false, "strikethrough": false }] },
{ "type": "tableCell", "children": [{ "type": "text", "value": "30", "bold": false, "italic": false, "strikethrough": false }] }
]
}
]
}
]
}
Related
- toDocTree() API: generate a Doc Tree from Markdown
- Markdown to ProseMirror: a complete ProseMirror adapter
- Markdown to Slate: a complete Slate converter
- Markdown to Quill: build a Quill Delta