Module

lexer.classifiers.fence

Fenced code block classifier mixin.

Classes

FenceClassifierMixin 8
Mixin providing fenced code block classification.

Mixin providing fenced code block classification.

Attributes

Name Type Description
_fence_char str
_fence_count int
_fence_info str
_fence_indent int
_mode LexerMode

Methods

Internal Methods 3
_location_from 3 SourceLocation
Get source location from saved position. Implemented by Lexer.
def _location_from(self, start_pos: int, start_col: int | None = None, end_pos: int | None = None) -> SourceLocation
Parameters
Name Type Description
start_pos
start_col Default:None
end_pos Default:None
Returns
SourceLocation
_try_classify_fence_start 3 Token | None
Try to classify content as fenced code start. Fenced code blocks start with 3+…
def _try_classify_fence_start(self, content: str, line_start: int, indent: int = 0) -> Token | None

Try to classify content as fenced code start.

Fenced code blocks start with 3+ backticks or tildes. Backtick fences cannot have backticks in the info string.

Parameters
Name Type Description
content

Line content with leading whitespace stripped

line_start

Position in source where line starts

indent

Number of leading spaces (for CommonMark indent stripping)

Default:0
Returns
Token | None Token if valid fence, None otherwise.
_is_closing_fence 1 bool
Check if line is a closing fence for current code block. CommonMark 4.5: Closi…
def _is_closing_fence(self, line: str) -> bool

Check if line is a closing fence for current code block.

CommonMark 4.5: Closing fences may be indented 0-3 spaces. If indented 4+ spaces, it's NOT a closing fence (it's code content).

Parameters
Name Type Description
line

Full line content including leading whitespace

Returns
bool True if this is a valid closing fence.