v2.0.1

AST Nodes

Last updated


The AST returned by Parse() is an array of BlockNodes (it extends Array); this page lists every node type, its fields and the syntax that produces it.

Block Nodes (BlockNode)


typeFieldsSyntax
textchildren: InlineNode[]Paragraph; adjacent lines are joined by a text node whose value is "\n"
headinglevel, children# to ######, Setext
blockquotetag?, children: BlockNode[]>; tag is note / tip / important / warning / caution
listordered, children: ListItem[]-, *, 1.
tablealign, children: TableRow[]GFM tables; each align entry is left / center / right / null
codeBlocklang?, value``` / ~~~ fences; no lang when the fence is unclosed
htmlvalueLines that start with an HTML tag (original text, sanitized at output)
hr—Horizontal rule
break—Blank lines
footnoteschildren: Footnote[]Footnote section at the end

Inline Nodes (InlineNode)


typeFieldsSyntax
textvaluePlain text
b, em, del, mark, sub, supchildrenBold, italic, strikethrough, highlight, subscript, superscript
codevalueCode span
mathvalue$...$
linkhref, tag?, title?, width?, height?, childrenLinks, images, videos, bare URLs, file paths; tag is image / video / youtube / vimeo / file
footnoteRefid, index[^id]; index is its number

Child Nodes


TypeFields
ListItemtype: "listItem", checked? (task lists), children: BlockNode[]
TableRowtype: "tableRow", header, children: TableCell[]
TableCelltype: "tableCell", children: InlineNode[]
Footnotetype: "footnote", id, index, children: BlockNode[]

html() lives on the AST prototype, so JSON.stringify(ast) outputs only the nodes and can be handed to renderers on other platforms. The type definitions ship with the package in dist/types/types.d.ts.
  1. <script>
  2. const ast = MDParser.Parse("## Hi\n\n- [x] done\n\nE = $mc^2$ [link](https://nanomd.pardn.io)");
  3. console.log(JSON.stringify(ast, null, 2));
  4. </script>
Live preview · @pardnchiu/nanomd@2.0.1
中文