# core

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

Provides the main inline tokenization and AST building logic.

Thread Safety:
All methods are stateless or use instance-local state only.
Safe for concurrent use when each parser instance is used by one thread.

---

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

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

Share with AI

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

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

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

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

Module

#
`parsing.inline.core`

Core inline parsing for Patitas parser.

Provides the main inline tokenization and AST building logic.

Thread Safety:

All methods are stateless or use instance-local state only.
Safe for concurrent use when each parser instance is used by one thread.

1Class

## Classes

`InlineParsingCoreMixin`

5

▼

Core inline parsing methods.

Required Host Attributes:
- _math_enabled: bool
- _strikethro…

Core inline parsing methods.

Required Host Attributes:

- _math_enabled: bool

- _strikethrough_enabled: bool

- _footnotes_enabled: bool

- _autolinks_enabled: bool

- _link_refs: dict[str, tuple[str, str]]

Required Host Methods (from other mixins):

- _is_left_flanking(before, after, delim) -> bool

- _is_right_flanking(before, after, delim) -> bool

- _is_punctuation(char) -> bool

- _process_emphasis(tokens, registry) -> MatchRegistry

- _try_parse_footnote_ref(text, pos, location) -> tuple | None

- _try_parse_link(text, pos, location) -> tuple | None

- _try_parse_image(text, pos, location) -> tuple | None

- _try_parse_autolink(text, pos, location) -> tuple | None

- _try_parse_html_inline(text, pos, location) -> tuple | None

- _try_parse_role(text, pos, location) -> tuple | None

- _try_parse_math(text, pos, location) -> tuple | None

#### Methods

Internal Methods
5

▼

`_parse_inline`

2

`tuple[Inline, ...]`

▼

Parse inline content using CommonMark delimiter stack algorithm.

This implemen…

`def _parse_inline(self: InlineParsingHost, text: str, location: SourceLocation) -> tuple[Inline, ...]`

Parse inline content using CommonMark delimiter stack algorithm.

This implements the proper flanking delimiter rules for emphasis/strong.
See: https://spec.commonmark.org/0.31.2/#emphasis-and-strong-emphasis

##### Parameters

Name
Type
Description

`text`
`—`

`location`
`—`

##### Returns

`tuple[Inline, ...]`

`_tokenize_inline`

2

`list[InlineToken]`

▼

Tokenize inline content into typed token objects.

Returns list of InlineToken …

`def _tokenize_inline(self: InlineParsingHost, text: str, location: SourceLocation) -> list[InlineToken]`

Tokenize inline content into typed token objects.

Returns list of InlineToken NamedTuples for type safety and performance.

##### Parameters

Name
Type
Description

`text`
`—`

`location`
`—`

##### Returns

`list[InlineToken]`

`_find_code_span_close`

3

`int`

▼

Find closing backticks for code span.

`def _find_code_span_close(self, text: str, start: int, backtick_count: int) -> int`

##### Parameters

Name
Type
Description

`text`
`—`

`start`
`—`

`backtick_count`
`—`

##### Returns

`int`

`_try_parse_entity`

2

`tuple[str, int] | None`

▼

Try to parse an HTML entity reference at position.

CommonMark 6.2: Entity and …

`def _try_parse_entity(self, text: str, pos: int) -> tuple[str, int] | None`

Try to parse an HTML entity reference at position.

CommonMark 6.2: Entity and numeric character references.

Supports:

- Named entities: &   © etc.

- Decimal: &#digits; (1-7 digits, value <= 0x10FFFF)

- Hexadecimal: &#xhex; or &#Xhex; (1-6 hex digits)

##### Parameters

Name
Type
Description

`text`
`—`

`pos`
`—`

##### Returns

`tuple[str, int] | None`

Tuple of (decoded_char, new_position) if valid, None otherwise.

`_build_inline_ast`

6

`tuple[Inline, ...]`

▼

Build AST from processed tokens using match registry.

Uses pattern matching fo…

`def _build_inline_ast(self: InlineParsingHost, tokens: list[InlineToken], registry: MatchRegistry, location: SourceLocation, start: int = 0, end: int | None = None, depth: int = 0) -> tuple[Inline, ...]`

Build AST from processed tokens using match registry.

Uses pattern matching for type-safe token dispatch.
Uses index bounds instead of list slicing to avoid allocations.

##### Parameters

Name
Type
Description

`tokens`
`—`

List of InlineToken NamedTuples from _tokenize_inline().

`registry`
`—`

MatchRegistry containing delimiter matches.

`location`
`—`

Source location for node creation.

`start`
`—`

Start index in tokens (inclusive). Default 0.

Default:`0`

`end`
`—`

End index in tokens (exclusive). Default len(tokens).

Default:`None`

`depth`
`—`

Current inline emphasis/strong/strikethrough nesting depth. Each nested span recurses one level deeper here; bounding it with`max_nesting_depth` prevents the (mutually recursive) HTML inline renderer from overflowing the interpreter stack on adversarial input such as `"*" * 5000 + "x" + "*" * 5000`. Consistent with the block-container depth guard, we raise a catchable `ParseError`.

Default:`0`

##### Returns

`tuple[Inline, ...]`

Tuple of Inline nodes.
