Skip to main content

Document

ClassDataClassSource

Document(
type: Literal["document"] = "document",
children: list[DeletedNode | TextNode | LineBreakNode | HorizontalRuleNode | InlineCodeNode | CodeBlockNode | BoldNode | ItalicNode | UnderlineNode | StrikeNode | SpoilerNode | LinkNode | HeadingNode | ParagraphNode | QuoteNode | AlertNode | ListItemNode | ListNode | TableCellNode | TableRowNode | TableNode]
)

The top-level parsed document.

This document can be parsed in the following chain:

Markdown -> HTML -> Document

It is fully structured and ready to be converted to other formats.

Fields​

NameTypeRequired
Description
typeLiteral["document"]The type identifer of this document node.
childrenlist[DeletedNode | TextNode | LineBreakNode | HorizontalRuleNode | InlineCodeNode | CodeBlockNode | BoldNode | ItalicNode | UnderlineNode | StrikeNode | SpoilerNode | LinkNode | HeadingNode | ParagraphNode | QuoteNode | AlertNode | ListItemNode | ListNode | TableCellNode | TableRowNode | TableNode]The children of the document.

Methods​

walk​

self.walk(func: Callable[[Node], None])

Walk from the top to the down of each node in this document.

The visiting order is depth-first, i.e., the leaf nodes will be processed first.

Requires​

NameTypeRequired
Description
funcCallable[[Node], None]A function to be applied to each node. This function is a visitor that is used for processing the doucment.

Properties​

pure_text​

pure_text: str = self.pure_text

The pure text of the current node.


size​

size: int = self.size

The estimated text length of the current node.