Module

lexer.classifiers.link_ref

Link reference definition classifier mixin.

Handles multi-line definitions, escaped characters, and strict validation according to CommonMark 0.31.2 spec.

Classes

LinkRefClassifierMixin 12 ▼
Mixin providing link reference definition classification.

Mixin providing link reference definition classification.

Attributes

Name Type Description
_source str —
_source_len int —
_pos int —
_lineno int —
_col int —

Methods

Internal Methods 7 ▼
_make_token 6 Token ▼
Create token with raw coordinates. Implemented by Lexer.
def _make_token(self, token_type: TokenType, value: str, start_pos: int, *, start_col: int | None = None, end_pos: int | None = None, line_indent: int = -1) -> Token
Parameters
Name Type Description
token_type —
value —
start_pos —
start_col — Default:None
end_pos — Default:None
line_indent — Default:-1
Returns
Token
_find_line_end 0 int ▼
Find end of current line. Implemented by Lexer.
def _find_line_end(self) -> int
Returns
int
_commit_to 1 ▼
Commit position. Implemented by Lexer.
def _commit_to(self, line_end: int) -> None
Parameters
Name Type Description
line_end —
_try_classify_link_reference_def 3 Token | None ▼
Try to classify content as link reference definition. CommonMark 4.7: **A lin…
def _try_classify_link_reference_def(self, first_line_content: str, line_start: int, indent: int = 0) -> Token | None

Try to classify content as link reference definition.

CommonMark 4.7:

A link reference definition consists of:

  1. A link label (indented by up to 3 spaces)
  2. A colon (:)
  3. Optional whitespace (including up to one line change)
  4. A link destination
  5. Optional whitespace (including up to one line change)
  6. An optional link title
Parameters
Name Type Description
first_line_content —

Content of the first line (indents < 4 stripped)

line_start —

Source position where the first line starts

indent —

Number of leading spaces (for line_indent)

Default:0
Returns
Token | None LINK_REFERENCE_DEF token if valid, None otherwise. Token value format: label|url|title (pipe-separated)
_parse_label_multiline 2 tuple[str, int, bool] ▼
Parse link label, possibly spanning multiple lines.
def _parse_label_multiline(self, first_line: str, line_start: int) -> tuple[str, int, bool]
Parameters
Name Type Description
first_line —
line_start —
Returns
tuple[str, int, bool]
_parse_destination_multiline 1 tuple[str, int, bool] ▼
Parse link destination, possibly after one newline.
def _parse_destination_multiline(self, start_pos: int) -> tuple[str, int, bool]
Parameters
Name Type Description
start_pos —
Returns
tuple[str, int, bool]
_parse_title_multiline 1 tuple[str, int, bool] ▼
Parse optional link title, possibly after one newline.
def _parse_title_multiline(self, start_pos: int) -> tuple[str, int, bool]
Parameters
Name Type Description
start_pos —
Returns
tuple[str, int, bool]