Classes
BlockParsingCoreMixin
12
▼
Core block parsing methods.
Required Host Attributes:
- _source: str
- _tokens: list[Token…
BlockParsingCoreMixin
12
▼
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.
_parse_block
0
Block | None
▼
def _parse_block(self: ParserHost) -> Block | None
Returns
Block | None
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
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
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
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
Parse thematic break (---, ***, ___).
def _parse_thematic_break(self: TokenNavHost) -> ThematicBreak
Returns
ThematicBreak
Parse HTML block (raw HTML content passed through unchanged).
def _parse_html_block(self: TokenNavHost) -> HtmlBlock
Returns
HtmlBlock
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
Parse indented code block.
def _parse_indented_code(self: TokenNavHost) -> IndentedCode
Returns
IndentedCode
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.
_is_setext_underline
1
bool
▼
Check if line is a setext heading underline.
Must be at least 1 character of =…
_is_setext_underline
1
bool
▼
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…
_starts_table_here
1
bool
▼
def _starts_table_here(self: BlockParsingHost, header_line: str) -> bool
Whetherheader_linebegins a GFM table at the current token.
Used to let a table interrupt a paragraph: returns True only when
header_lineis 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 …
_process_escapes
1
str
▼
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…
_extract_explicit_id
1
tuple[str, str | None]
▼
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]