Module

text

Extract plain text from Patitas AST nodes.

Provides a public API for extracting text content from any node type, used for heading slugs, excerpts, and LLM-safe text rendering.

Example:

>>> from patitas import parse, extract_text
>>> doc = parse("# Hello **World**")
>>> extract_text(doc.children[0])
'Hello World'

Functions

extract_text 2 str
Extract plain text from any AST node. Recursively walks the tree, concatenatin…
def extract_text(node: Node, *, source: str = '') -> str

Extract plain text from any AST node.

Recursively walks the tree, concatenating text content. Skips HtmlBlock, HtmlInline. LineBreak and SoftBreak contribute a space.

Parameters
Name Type Description
node Node

Any AST node (block or inline).

source str

Original source string (required for FencedCode zero-copy extraction; use empty string if unavailable).

Default:''
Returns
str