Skip to main content

Node

A node in the CommonMark/GFM abstract syntax tree.

Usage

Source

Node(
    ptr,
    owner,
)

Nodes are obtained by calling parse() or Parser.finish(). They should not be instantiated directly.

Provides tree traversal, node property access, and rendering methods.

Attributes

Name Description
children Iterate over direct child nodes.
end_column End column (1-based) in source. 0 if not available.
end_line End line (1-based) in source. 0 if not available.
fence_info Info string for fenced CODE_BLOCK nodes (e.g., 'python').
first_child The first child node, or None.
heading_level Heading level (1–6) for HEADING nodes; 0 otherwise.
last_child The last child node, or None.
list_delim Delimiter type for ordered LIST nodes.
list_start Starting number for ordered LIST nodes; 0 otherwise.
list_tight Whether a LIST node is tight (no blank lines between items).
list_type List type (BULLET or ORDERED) for LIST nodes.
literal Text content for text, code, and HTML nodes. None if not applicable.
math_display Whether a math node is display math ($$...$$).
next The next sibling, or None.
parent The parent node, or None if this is the root.
previous The previous sibling, or None.
start_column Start column (1-based) in source. 0 if not available.
start_line Start line (1-based) in source. 0 if not available.
title Title for link and image nodes. None if not applicable.
type The node type.
type_string Human-readable node type name from cmark (e.g., 'heading').
url URL for link and image nodes. None if not applicable.

Functions

Name Description
append_child() Append child as the last child of this node.
insert_after() Insert sibling as the node immediately after this one.
insert_before() Insert sibling as the node immediately before this one.
new() Create a new detached node of the given type.
prepend_child() Prepend child as the first child of this node.
render_commonmark() Render this subtree as normalized CommonMark.
render_html() Render this subtree as HTML.
render_latex() Render this subtree as LaTeX.
render_man() Render this subtree as a groff man page.
render_plaintext() Render this subtree as plain text using markdown_to_plaintext rules.
render_xml() Render this subtree as XML.
replace() Replace this node in the tree with new_node.
unlink() Remove this node from its parent tree.
walk() Depth-first walk of the subtree rooted at this node.