# core

URL: /patitas/api/parsing/blocks/core/
Section: blocks
Description: Core block parsing for Patitas parser.

Provides block dispatch and basic block parsing (headings, code, quotes, paragraphs).

---

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

Open LLM text
(/patitas/api/parsing/blocks/core/index.txt)

Share with AI

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

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

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

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

Module

#
`parsing.blocks.core`

Core block parsing for Patitas parser.

Provides block dispatch and basic block parsing (headings, code, quotes, paragraphs).

1Class2Functions

## Classes

`BlockParsingCoreMixin`

12

▼

Core block parsing methods.

Required Host Attributes:
- _source: str
- _tokens: list[Token…

Core block parsing methods.

Required Host Attributes:

- _source: str

- _tokens: list[Token]

- _pos: int

- _current: Token | None

- _tables_enabled: bool

Required Host Methods:

- _at_end() -> bool

- _advance() -> Token | None

- _parse_inline(text, location) -> tuple[Inline, ...]

- _parse_list(parent_indent) -> List

- _parse_directive() -> Directive

- _parse_footnote_def() -> FootnoteDef

- _try_parse_table(lines, location) -> Table | None

#### Methods

Internal Methods
12

▼

`_parse_block`

0

`Block | None`

▼

Parse a single block element.

`def _parse_block(self: ParserHost) -> Block | None`

##### Returns

`Block | None`

`_parse_atx_heading`

0

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

▼

Parse ATX heading (# Heading).

Supports MyST-compatible explicit anchor syntax…

`def _parse_atx_heading(self: ParserHost) -> Heading`

Parse ATX heading (# Heading).

Supports MyST-compatible explicit anchor syntax: ## Title {#custom-id}

##### Returns

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

`_parse_fenced_code`

1

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

▼

Parse fenced code block with zero-copy coordinates.

`def _parse_fenced_code(self: TokenNavHost, override_fence_indent: int | None = None) -> FencedCode`

##### Parameters

Name
Type
Description

`override_fence_indent`
`—`

If provided, use this instead of the token's indent. Used for fenced code blocks in list items.

Default:`None`

##### Returns

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

`_parse_orphaned_fence_content`

0

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

▼

Parse orphaned FENCED_CODE_CONTENT as paragraph.

This happens when a fenced co…

`def _parse_orphaned_fence_content(self: ParserHost) -> Paragraph`

Parse orphaned FENCED_CODE_CONTENT as paragraph.

This happens when a fenced code block is interrupted (e.g., by block quote
ending without >), leaving content tokens orphaned. Treat as paragraph text.

##### Returns

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

`_parse_orphaned_fence_end`

0

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

▼

Parse orphaned FENCED_CODE_END as new unclosed fenced code block.

This happens…

`def _parse_orphaned_fence_end(self: TokenNavHost) -> FencedCode`

Parse orphaned FENCED_CODE_END as new unclosed fenced code block.

This happens when a fenced code block is interrupted, and the closing fence
is now orphaned. In CommonMark, this becomes a new unclosed fenced code block.

##### Returns

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

`_parse_thematic_break`

0

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

▼

Parse thematic break (---, ***, ___).

`def _parse_thematic_break(self: TokenNavHost) -> ThematicBreak`

##### Returns

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

`_parse_html_block`

0

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

▼

Parse HTML block (raw HTML content passed through unchanged).

`def _parse_html_block(self: TokenNavHost) -> HtmlBlock`

##### Returns

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

`_parse_block_quote`

0

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

▼

Parse block quote (> quoted).

CommonMark 5.1: Block quotes can contain any blo…

`def _parse_block_quote(self: ParserHost) -> BlockQuote`

Parse block quote (> quoted).

CommonMark 5.1: Block quotes can contain any block-level content,
including headings, code blocks, lists, and nested block quotes.

Algorithm:

- Consume the first BLOCK_QUOTE_MARKER

- Collect content, preserving nested > markers as content

- Handle lazy continuation (lines without > that continue paragraphs)

- Sub-parse the content for nested blocks

##### Returns

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

`_parse_indented_code`

0

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

▼

Parse indented code block.

`def _parse_indented_code(self: TokenNavHost) -> IndentedCode`

##### Returns

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

`_parse_paragraph`

0

`Paragraph (/patitas/api/nodes/#Paragraph) | Table (/patitas/api/nodes/#Table) | Head…`

▼

Parse paragraph (consecutive text lines), table, or setext heading.

If the sec…

`def _parse_paragraph(self: ParserHost) -> Paragraph | Table | Heading`

Parse paragraph (consecutive text lines), table, or setext heading.

If the second line is a setext underline (=== or ---), returns Heading.
If tables are enabled and lines form a valid GFM table, returns Table.
Otherwise returns Paragraph.

CommonMark: Ordered lists can only interrupt paragraphs if they start with 1.

##### Returns

`Paragraph (/patitas/api/nodes/#Paragraph) | Table (/patitas/api/nodes/#Table) | Heading (/patitas/api/nodes/#Heading)`

`_is_setext_underline`

1

`bool`

▼

Check if line is a setext heading underline.

Must be at least 1 character of =…

`def _is_setext_underline(self, line: str) -> bool`

Check if line is a setext heading underline.

Must be at least 1 character of = or - with optional trailing spaces.
CommonMark allows up to 3 leading spaces.

##### Parameters

Name
Type
Description

`line`
`—`

##### Returns

`bool`

`_starts_table_here`

1

`bool`

▼

Whether ``header_line`` begins a GFM table at the current token.

Used to let a…

`def _starts_table_here(self: BlockParsingHost, header_line: str) -> bool`

Whether`header_line`begins a GFM table at the current token.

Used to let a table interrupt a paragraph: returns True only when
`header_line`is a valid table row AND the immediately following
PARAGRAPH_LINE token is a valid delimiter row whose column count
matches the header. Does not consume any tokens.

##### Parameters

Name
Type
Description

`header_line`
`—`

##### Returns

`bool`

## Functions

`_process_escapes`

1

`str`

▼

Process backslash escapes in info strings.

CommonMark: Backslash escapes work …

`def _process_escapes(text: str) -> str`

Process backslash escapes in info strings.

CommonMark: Backslash escapes work in code fence info strings.

##### Parameters

Name
Type
Description

`text`
`str`

##### Returns

`str`

`_extract_explicit_id`

1

`tuple[str, str | None]`

▼

Extract MyST-compatible explicit anchor ID from heading content.

Syntax: ## Ti…

`def _extract_explicit_id(content: str) -> tuple[str, str | None]`

Extract MyST-compatible explicit anchor ID from heading content.

Syntax: ## Title {#custom-id}

The {#id} must be at the end of the content, preceded by whitespace.
ID must start with a letter, contain only letters, numbers, hyphens, underscores.

##### Parameters

Name
Type
Description

`content`
`str`

Heading content (already stripped)

##### Returns

`tuple[str, str | None]`
