# nodes

URL: /patitas/api/nodes/
Section: api
Description: Typed AST nodes for Patitas.

All AST nodes are frozen dataclasses with slots for:
- Type safety: IDE autocomplete, catch errors at dev time
- Immutability: Safe sharing across threads (Python 3.14t ready)
- Memory efficiency: __slots__ reduces memory footprint
- Pattern matching: Python 3.10+ match statements work naturally

Node Hierarchy:
Node (base)
├── Block (block-level elements)
│   ├── Document
│   ├── Heading
│   ├── Paragraph
│   ├── FencedCode
│   ├── IndentedCode
│   ├── BlockQuote
│   ├── List
│   ├── ListItem
│   ├── ThematicBreak
│   ├── HtmlBlock
│   └── Directive
└── Inline (inline elements)
    ├── Text
    ├── Emphasis
    ├── Strong
    ├── Link
    ├── Image
    ├── CodeSpan
    ├── LineBreak
    ├── HtmlInline
    └── Role

Thread Safety:
All nodes are frozen (immutable) and safe to share across threads.

---

> For a complete page index, fetch /patitas/llms.txt.

Open LLM text
(/patitas/api/nodes/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fnodes%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fnodes%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fnodes%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fnodes%2Findex.txt)

Module

#
`nodes`

Typed AST nodes for Patitas.

All AST nodes are frozen dataclasses with slots for:

- Type safety: IDE autocomplete, catch errors at dev time

- Immutability: Safe sharing across threads (Python 3.14t ready)

- Memory efficiency: slots reduces memory footprint

- Pattern matching: Python 3.10+ match statements work naturally

Node Hierarchy:

Node (base)
├── Block (block-level elements)
│ ├── Document
│ ├── Heading
│ ├── Paragraph
│ ├── FencedCode
│ ├── IndentedCode
│ ├── BlockQuote
│ ├── List
│ ├── ListItem
│ ├── ThematicBreak
│ ├── HtmlBlock
│ └── Directive
└── Inline (inline elements)
├── Text
├── Emphasis
├── Strong
├── Link
├── Image
├── CodeSpan
├── LineBreak
├── HtmlInline
└── Role

Thread Safety:

All nodes are frozen (immutable) and safe to share across threads.

30Classes

## Classes

`Node`

1

▼

Base class for all AST nodes.

All nodes track their source location for error messages and debuggi…

Base class for all AST nodes.

All nodes track their source location for error messages and debugging.

#### Attributes

Name
Type
Description

`location`

`SourceLocation (/patitas/api/location/#SourceLocation)`

—

`Text`

1

▼

Plain text content.

The most common inline node, representing literal text.

Bases:

`Node (/patitas/api/nodes/#Node)`

Plain text content.

The most common inline node, representing literal text.

#### Attributes

Name
Type
Description

`content`

`str`

—

`Emphasis`

1

▼

Emphasized (italic) text.

Markdown: *text* or _text_
HTML: <em>text</em>

Bases:

`Node (/patitas/api/nodes/#Node)`

Emphasized (italic) text.

Markdown: text or text
HTML: text

#### Attributes

Name
Type
Description

`children`

`tuple[Inline, ...]`

—

`Strong`

1

▼

Strong (bold) text.

Markdown: **text** or __text__
HTML: <strong>text</strong>

Bases:

`Node (/patitas/api/nodes/#Node)`

Strong (bold) text.

Markdown: text or text
HTML: text

#### Attributes

Name
Type
Description

`children`

`tuple[Inline, ...]`

—

`Link`

3

▼

Hyperlink.

Markdown: [text](url "title") or [text][ref]
HTML: <a href="url" title="title">text</a>

Bases:

`Node (/patitas/api/nodes/#Node)`

Hyperlink.

Markdown: text (url) or [text][ref]
HTML: text (url)

#### Attributes

Name
Type
Description

`url`

`str`

—

`title`

`str | None`

—

`children`

`tuple[Inline, ...]`

—

`Image`

3

▼

Image.

Markdown: ![alt](url "title")
HTML: <img src="url" alt="alt" title="title">

Bases:

`Node (/patitas/api/nodes/#Node)`

Image.

Markdown:
HTML:

#### Attributes

Name
Type
Description

`url`

`str`

—

`alt`

`str`

—

`title`

`str | None`

—

`CodeSpan`

1

▼

Inline code.

Markdown: `code`
HTML: <code>code</code>

Bases:

`Node (/patitas/api/nodes/#Node)`

Inline code.

Markdown:`code`
HTML:`code`

#### Attributes

Name
Type
Description

`code`

`str`

—

`LineBreak`

0

▼

Hard line break.

Markdown: ``\`` at end of line or two trailing spaces
HTML: <br />

Bases:

`Node (/patitas/api/nodes/#Node)`

Hard line break.

Markdown:`\`at end of line or two trailing spaces
HTML:

`SoftBreak`

0

▼

Soft line break (single newline in paragraph).

Typically rendered as a space or newline depending …

Bases:

`Node (/patitas/api/nodes/#Node)`

Soft line break (single newline in paragraph).

Typically rendered as a space or newline depending on renderer settings.

`HtmlInline`

1

▼

Inline raw HTML.

Markdown: <span>text</span>
HTML: passed through unchanged

Bases:

`Node (/patitas/api/nodes/#Node)`

Inline raw HTML.

Markdown: text
HTML: passed through unchanged

#### Attributes

Name
Type
Description

`html`

`str`

—

`Role`

3

▼

Inline role (MyST syntax).

Markdown: \{role}`content`
Example: \{ref}`target`, \{kbd}`Ctrl+C`

Bases:

`Node (/patitas/api/nodes/#Node)`

Inline role (MyST syntax).

Markdown: {role}`content`
Example: {ref}`target` (/patitas/api/nodes/#Role), {kbd}`Ctrl+C`

#### Attributes

Name
Type
Description

`name`

`str`

—

`content`

`str`

—

`target`

`str | None`

—

`Strikethrough`

1

▼

Strikethrough (deleted) text.

Markdown: ~~deleted~~
HTML: <del>deleted</del>

Bases:

`Node (/patitas/api/nodes/#Node)`

Strikethrough (deleted) text.

Markdown: deleted
HTML: deleted

#### Attributes

Name
Type
Description

`children`

`tuple[Inline, ...]`

—

`Math`

1

▼

Inline math expression.

Markdown: $E = mc^2$
HTML: <span class="math">E = mc^2</span>

Bases:

`Node (/patitas/api/nodes/#Node)`

Inline math expression.

Markdown: $E = mc^2$
HTML: E = mc^2

#### Attributes

Name
Type
Description

`content`

`str`

—

`FootnoteRef`

1

▼

Footnote reference.

Markdown: [^1] or [^note]
HTML: <sup><a href="#fn-1">1</a></sup>

Bases:

`Node (/patitas/api/nodes/#Node)`

Footnote reference.

Markdown: [^1] or [^note]
HTML: 1 (#fn-1)

#### Attributes

Name
Type
Description

`identifier`

`str`

—

`Heading`

4

▼

ATX or setext heading.

Markdown: # Heading or Heading
======
HTML: <h1>Heading</h1>

S…

Bases:

`Node (/patitas/api/nodes/#Node)`

ATX or setext heading.

```
Markdown: # Heading or Heading
```

======
HTML:
# Heading

```
Supports MyST-compatible explicit anchor syntax: ## Title {#custom-id}
The {#id} is parsed during lexing and stored in explicit_id.
```

#### Attributes

Name
Type
Description

`level`

`Literal[1, 2, 3, 4, 5, 6]`

—

`children`

`tuple[Inline, ...]`

—

`style`

`Literal['atx', 'setext']`

—

`explicit_id`

`str | None`

—

`Paragraph`

1

▼

Paragraph block.

Markdown: Text separated by blank lines
HTML: <p>text</p>

Bases:

`Node (/patitas/api/nodes/#Node)`

Paragraph block.

Markdown: Text separated by blank lines
HTML:
text

#### Attributes

Name
Type
Description

`children`

`tuple[Inline, ...]`

—

`FencedCode`

8

▼

Fenced code block with zero-copy source reference.

BREAKING CHANGE (v0.4.0):
Previous: code: s…

Bases:

`Node (/patitas/api/nodes/#Node)`

Fenced code block with zero-copy source reference.

BREAKING CHANGE (v0.4.0):
Previous: code: str (extracted content)
Current: source_start/source_end indices into original source

Migration:

```
Old: block.code
New: block.get_code(source)
```

For nested contexts (e.g., fenced code inside block quotes), the
content_override field stores the actual code content directly
since the source offsets would be relative to a sub-parser's source.

#### Attributes

Name
Type
Description

`source_start`

`int`

—

`source_end`

`int`

—

`info`

`str | None`

—

`marker`

`Literal['`', '~']`

—

`fence_indent`

`int`

—

`content_override`

`str | None`

—

#### Methods

`get_code`

1

`str`

▼

Extract code content (creates new string).

CommonMark: strips up to fence_inde…

`def get_code(self, source: str) -> str`

Extract code content (creates new string).

CommonMark: strips up to fence_indent spaces from each content line.

##### Parameters

Name
Type
Description

`source`
`—`

##### Returns

`str`

`code_length`

0

`int`

▼

Length of code content without allocation.

`def code_length(self) -> int`

##### Returns

`int`

`IndentedCode`

1

▼

Indented code block (4+ spaces).

Markdown: ····code
HTML: <pre><code>code</code></pre>

Bases:

`Node (/patitas/api/nodes/#Node)`

Indented code block (4+ spaces).

Markdown: ····code
HTML:

```
code
```

#### Attributes

Name
Type
Description

`code`

`str`

—

`BlockQuote`

1

▼

Block quote.

Markdown: > quoted text
HTML: <blockquote>text</blockquote>

Bases:

`Node (/patitas/api/nodes/#Node)`

Block quote.

Markdown: > quoted text
HTML: text

#### Attributes

Name
Type
Description

`children`

`tuple[Block, ...]`

—

`ListItem`

2

▼

List item.

Markdown: - item or 1. item
HTML: <li>item</li>

Bases:

`Node (/patitas/api/nodes/#Node)`

List item.

Markdown: - item or 1. item
HTML:
- item

#### Attributes

Name
Type
Description

`children`

`tuple[Block, ...]`

—

`checked`

`bool | None`

—

`List`

4

▼

Ordered or unordered list.

Markdown: - item or 1. item
HTML: <ul>/<ol> with <li> children

Bases:

`Node (/patitas/api/nodes/#Node)`

Ordered or unordered list.

Markdown: - item or 1. item
HTML:
/
with
- children

#### Attributes

Name
Type
Description

`items`

`tuple[ListItem (/patitas/api/nodes/#ListItem), ...]`

—

`ordered`

`bool`

—

`start`

`int`

—

`tight`

`bool`

—

`ThematicBreak`

0

▼

Thematic break (horizontal rule).

Markdown: --- or *** or ___
HTML: <hr />

Bases:

`Node (/patitas/api/nodes/#Node)`

Thematic break (horizontal rule).

Markdown: --- or *** or ___
HTML:

`HtmlBlock`

1

▼

Raw HTML block.

Markdown: HTML that starts a block
HTML: passed through unchanged

Bases:

`Node (/patitas/api/nodes/#Node)`

Raw HTML block.

Markdown: HTML that starts a block
HTML: passed through unchanged

#### Attributes

Name
Type
Description

`html`

`str`

—

`Directive`

5

▼

Block directive (MyST syntax).

Markdown: :::{name} title
:option: value
content
:::

Gener…

Bases:

`Node (/patitas/api/nodes/#Node)`

Block directive (MyST syntax).

```
Markdown: :::{name} title
```

:option: value
content
:::

```
Generic over options type for full type safety. Use Directive[YourOptions]
to get typed options access in handlers.

PEP 695 Note:
    Uses Python 3.12+ type parameter syntax: `class Directive[TOptions: DirectiveOptions]`
    instead of the older `class Directive(Node, Generic[TOptions])` with TypeVar.
```

#### Attributes

Name
Type
Description

`name`

`str`

—

`title`

`str | None`

—

`options`

`TOptions`

—

`children`

`tuple[Block, ...]`

—

`raw_content`

`str | None`

—

`Document`

1

▼

Root document node.

Contains all top-level blocks in the document.

Bases:

`Node (/patitas/api/nodes/#Node)`

Root document node.

Contains all top-level blocks in the document.

#### Attributes

Name
Type
Description

`children`

`tuple[Block, ...]`

—

`TableCell`

3

▼

Table cell (th or td).

Markdown: | cell content |
HTML: <td>cell content</td> or <th>cell content<…

Bases:

`Node (/patitas/api/nodes/#Node)`

Table cell (th or td).

Markdown: | cell content |
HTML: cell content or cell content

#### Attributes

Name
Type
Description

`children`

`tuple[Inline, ...]`

—

`is_header`

`bool`

—

`align`

`Literal['left', 'center', 'right'] | None`

—

`TableRow`

2

▼

Table row.

Markdown: | cell1 | cell2 |
HTML: <tr><td>cell1</td><td>cell2</td></tr>

Bases:

`Node (/patitas/api/nodes/#Node)`

Table row.

Markdown: | cell1 | cell2 |
HTML: cell1cell2

#### Attributes

Name
Type
Description

`cells`

`tuple[TableCell (/patitas/api/nodes/#TableCell), ...]`

—

`is_header`

`bool`

—

`Table`

3

▼

Table (GFM-style).

Markdown:
| A | B |
|---|---|
| 1 | 2 |

HTML: <table>...</table>

Bases:

`Node (/patitas/api/nodes/#Node)`

Table (GFM-style).

Markdown:

```
| A | B |
|---|---|
| 1 | 2 |
```

HTML: ...

#### Attributes

Name
Type
Description

`head`

`tuple[TableRow (/patitas/api/nodes/#TableRow), ...]`

—

`body`

`tuple[TableRow (/patitas/api/nodes/#TableRow), ...]`

—

`alignments`

`tuple[Literal['left', 'center', 'right'] | None, ...]`

—

`MathBlock`

1

▼

Block math expression.

Markdown:
$$
E = mc^2
$$

HTML: <div class="math-block">E = mc^…

Bases:

`Node (/patitas/api/nodes/#Node)`

Block math expression.

Markdown:

```
$$
E = mc^2
$$
```

HTML:
E = mc^2

#### Attributes

Name
Type
Description

`content`

`str`

—

`FootnoteDef`

2

▼

Footnote definition.

Markdown: [^1]: Footnote content here.
HTML: (rendered in footnotes section)

Bases:

`Node (/patitas/api/nodes/#Node)`

Footnote definition.

Markdown: [^1]: Footnote content here.
HTML: (rendered in footnotes section)

#### Attributes

Name
Type
Description

`identifier`

`str`

—

`children`

`tuple[Block, ...]`

—
