Module

parsing.inline.emphasis

Emphasis parsing for Patitas parser.

Implements CommonMark delimiter stack algorithm for emphasis/strong. See: https://spec.commonmark.org/0.31.2/#emphasis-and-strong-emphasis

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.

Classes

EmphasisMixin 5
Mixin for emphasis delimiter processing. Implements CommonMark flanking rules and delimiter matchi…

Mixin for emphasis delimiter processing.

Implements CommonMark flanking rules and delimiter matching algorithm. Uses external MatchRegistry for match tracking (enables immutable tokens).

Required Host Attributes: None

Required Host Methods: None

Methods

Internal Methods 5
_is_left_flanking 3 bool
Check if delimiter run is left-flanking. Left-flanking: not followed by whites…
def _is_left_flanking(self, before: str, after: str, delim: str) -> bool

Check if delimiter run is left-flanking.

Left-flanking: not followed by whitespace, and either:

  • not followed by punctuation, OR
  • preceded by whitespace or punctuation
Parameters
Name Type Description
before
after
delim
Returns
bool
_is_right_flanking 3 bool
Check if delimiter run is right-flanking. Right-flanking: not preceded by whit…
def _is_right_flanking(self, before: str, after: str, delim: str) -> bool

Check if delimiter run is right-flanking.

Right-flanking: not preceded by whitespace, and either:

  • not preceded by punctuation, OR
  • followed by whitespace or punctuation
Parameters
Name Type Description
before
after
delim
Returns
bool
_is_whitespace 1 bool
Check if character is Unicode whitespace. CommonMark uses Unicode whitespace f…
def _is_whitespace(self, char: str) -> bool

Check if character is Unicode whitespace.

CommonMark uses Unicode whitespace for emphasis flanking rules. Includes ASCII whitespace and Unicode category Zs.

Parameters
Name Type Description
char
Returns
bool
_is_punctuation 1 bool
Check if character is Unicode punctuation. CommonMark uses Unicode punctuation…
def _is_punctuation(self, char: str) -> bool

Check if character is Unicode punctuation.

CommonMark uses Unicode punctuation for emphasis flanking rules. Includes ASCII punctuation and Unicode categories P* and S*.

Parameters
Name Type Description
char
Returns
bool
_process_emphasis 2 MatchRegistry
Process delimiter stack to match emphasis openers/closers. Implements CommonMa…
def _process_emphasis(self, tokens: list[InlineToken], registry: MatchRegistry | None = None) -> MatchRegistry

Process delimiter stack to match emphasis openers/closers.

Implements CommonMark emphasis algorithm using external match tracking. Tokens are immutable; all state is tracked in the registry.

Parameters
Name Type Description
tokens

List of InlineToken NamedTuples from _tokenize_inline().

registry

Optional MatchRegistry to use. If None, creates a new one.

Default:None
Returns
MatchRegistry MatchRegistry containing all delimiter matches.