# fence

URL: /patitas/api/lexer/classifiers/fence/
Section: classifiers
Description: Fenced code block classifier mixin.

---

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

Open LLM text
(/patitas/api/lexer/classifiers/fence/index.txt)

Share with AI

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

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

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

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

Module

#
`lexer.classifiers.fence`

Fenced code block classifier mixin.

1Class

## 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 (/patitas/api/lexer/modes/#LexerMode)`

—

#### Methods

Internal Methods
3

▼

`_make_token`

6

`Token (/patitas/api/tokens/#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 (/patitas/api/tokens/#Token)`

`_try_classify_fence_start`

4

`Token (/patitas/api/tokens/#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, *, change_mode: bool = True) -> 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`

`change_mode`
`—`

If True, switch lexer to CODE_FENCE mode. Set to False when detecting fences inside containers (blockquotes) where the container handles fence content collection.

Default:`True`

##### Returns

`Token (/patitas/api/tokens/#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.
