# directive

URL: /patitas/api/lexer/classifiers/directive/
Section: classifiers
Description: Directive classifier mixin.

---

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

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

Share with AI

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

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

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

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

Module

#
`lexer.classifiers.directive`

Directive classifier mixin.

1Class

## Classes

`DirectiveClassifierMixin`

8

▼

Mixin providing MyST-style directive classification.

Handles :::{name} and ::::{name} syntax with …

Mixin providing MyST-style directive classification.

Handles :::{name} and ::::{name} syntax with nesting support.

#### Attributes

Name
Type
Description

`_mode`

`LexerMode (/patitas/api/lexer/modes/#LexerMode)`

—

`_directive_stack`

`list[tuple[int, str]]`

—

#### Methods

Internal Methods
6

▼

`_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_directive_start`

3

`Iterator[Token (/patitas/api/tokens/#Token)] | None`

▼

Try to classify content as directive start.

Detects :::{name} or ::::{name} sy…

`def _try_classify_directive_start(self, content: str, line_start: int, indent: int = 0) -> Iterator[Token] | None`

Try to classify content as directive start.

Detects :::{name} or ::::{name} syntax (MyST-style fenced directives).

Supports:

- Nested directives via colon count (:::: > :::)

- Named closers (:::{/name})

- Optional title after name

##### 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 line_indent)

Default:`0`

##### Returns

`Iterator[Token (/patitas/api/tokens/#Token)] | None`

Iterator of tokens if valid directive, None otherwise.

`_emit_directive_tokens`

6

`Iterator[Token (/patitas/api/tokens/#Token)]`

▼

Emit directive tokens and update state.

`def _emit_directive_tokens(self, colon_count: int, name: str, title: str, is_closer: bool, line_start: int, indent: int = 0) -> Iterator[Token]`

##### Parameters

Name
Type
Description

`colon_count`
`—`

Number of colons in the fence

`name`
`—`

Directive name

`title`
`—`

Optional title after the name

`is_closer`
`—`

Whether this is a named closer (:::{/name})

`line_start`
`—`

Position in source where line starts

`indent`
`—`

Number of leading spaces (for line_indent)

Default:`0`

##### Returns

`Iterator[Token (/patitas/api/tokens/#Token)]`

`_try_classify_directive_close`

3

`Iterator[Token (/patitas/api/tokens/#Token)] | None`

▼

Check if content is a directive closing fence.

**Valid closing:**
- ::: (simpl…

`def _try_classify_directive_close(self, content: str, line_start: int, indent: int = 0) -> Iterator[Token] | None`

Check if content is a directive closing fence.

Valid closing:

- ::: (simple close, 3+ colons matching or exceeding opener)

- :::{/name} (named close)

##### Parameters

Name
Type
Description

`content`
`—`

Line content starting with :::

`line_start`
`—`

Position in source where line starts

`indent`
`—`

Number of leading spaces (for line_indent)

Default:`0`

##### Returns

`Iterator[Token (/patitas/api/tokens/#Token)] | None`

Iterator of tokens if valid close, None otherwise.

`_emit_directive_close`

4

`Iterator[Token (/patitas/api/tokens/#Token)]`

▼

Emit directive close token and update state.

`def _emit_directive_close(self, colon_count: int, name: str | None, line_start: int, indent: int = 0) -> Iterator[Token]`

##### Parameters

Name
Type
Description

`colon_count`
`—`

Number of colons in the closing fence

`name`
`—`

Optional directive name for named closers

`line_start`
`—`

Position in source where line starts

`indent`
`—`

Number of leading spaces (for line_indent)

Default:`0`

##### Returns

`Iterator[Token (/patitas/api/tokens/#Token)]`

`_try_classify_directive_option`

3

`Token (/patitas/api/tokens/#Token) | None`

▼

Try to classify content as directive option.

Format: :key: value

`def _try_classify_directive_option(self, content: str, line_start: int, indent: int = 0) -> Token | None`

##### Parameters

Name
Type
Description

`content`
`—`

Line content starting with :

`line_start`
`—`

Position in source where line starts

`indent`
`—`

Number of leading spaces (for line_indent)

Default:`0`

##### Returns

`Token (/patitas/api/tokens/#Token) | None`

DIRECTIVE_OPTION token if valid, None otherwise.
