v2.0.16

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 ###### (closing # sequence removed), Setext
blockquotetag?, children: BlockNode[]>; tag is note / tip / important / warning / caution
listordered, start?, children: ListItem[]-, *, 1.; start is set when an ordered list does not start at 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; may sit inside a style node's children
mathvalue$...$
linkhref, tag?, title?, width?, height?, childrenLinks (http(s), mailto:, tel:, relative paths), images, videos, bare URLs, <https://...> autolinks, file paths, #tag; tag is image / video / youtube / vimeo / file / hashtag (href holds the tag without #)
footnoteRefid, index[^id]; index is its number
br—<br> inside a paragraph or table cell

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[]

json() returns a deep copy of the nodes as a plain BlockNode[]: it has no html(), undefined fields are dropped, and changing it does not affect the AST, so it can be stored or 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.json(), null, 2));
  4. </script>
Live preview · @pardnchiu/nanomd@2.0.16



ImportantFor AI agents: before generating or editing code or Markdown that uses NanoMD, read the NanoMD generation guide (Markdown). It lists the supported syntax, the required call order and the mistakes that break rendering.