Classes
TargetOptions
dataclass
Options for target directive.
The target directive is intentionally simple - no options by default…
TargetOptions
dataclass Options for target directive.
The target directive is intentionally simple - no options by default. The anchor ID is specified as the directive title.
DirectiveOptions
TargetDirective
Create an explicit anchor target at any location.
Syntax:
:::{target} my-anchor-id
:::
Th…
TargetDirective
Create an explicit anchor target at any location.
Syntax:
:::{target} my-anchor-id
:::
The target renders as an invisible anchor element that can be referenced via [[#my-anchor-id]] cross-reference syntax.
Anchor ID Requirements:
- Must start with a letter (a-z, A-Z)
- May contain letters, numbers, hyphens, underscores
- Case-sensitive in output, case-insensitive for resolution
Use Cases:
- Anchor before a note/warning that users should link to
- Stable anchor that survives content restructuring
- **Migration from Sphinx's
.. _label**:syntax
BengalDirectiveAttributes
| Name | Type | Description |
|---|---|---|
NAMES |
ClassVar[list[str]] |
|
TOKEN_TYPE |
ClassVar[str] |
|
OPTIONS_CLASS |
ClassVar[type[DirectiveOptions]] |
|
DIRECTIVE_NAMES |
ClassVar[list[str]] |
|
ID_PATTERN |
ClassVar[re.Pattern[str]] |
Methods 3
validate_id
Validate anchor ID format.
validate_id
def validate_id(self, anchor_id: str) -> str | None
Validate anchor ID format.
Parameters 1
anchor_id |
str |
The anchor ID to validate |
Returns
Error message if invalid, None if validstr | None
—
parse_directive
Build target token from parsed components.
The anchor ID is taken from the tit…
parse_directive
def parse_directive(self, title: str, options: TargetOptions, content: str, children: list[Any], state: Any) -> DirectiveToken
Build target token from parsed components.
The anchor ID is taken from the title. Content is ignored since targets are point anchors, not containers.
Parameters 5
title |
str |
The anchor ID (from directive title) |
options |
TargetOptions |
Parsed options (unused for target) |
content |
str |
Raw content inside directive (ignored) |
children |
list[Any] |
Parsed children (ignored) |
state |
Any |
Parser state |
Returns
DirectiveToken with anchor ID in attrsDirectiveToken
—
render
Render target as invisible anchor element.
The anchor renders as an empty <spa…
render
def render(self, renderer: Any, text: str, **attrs: Any) -> str
Render target as invisible anchor element.
The anchor renders as an empty <span> with the target ID. CSS class "target-anchor" allows styling if needed (e.g., scroll offset).
Parameters 2
renderer |
Any |
Mistune renderer instance |
text |
str |
Rendered children (empty for targets) **attrs: Attributes from token (id, error) |
Returns
HTML anchor element (invisible by default)str
—
Functions
render_target
Legacy render function for backward compatibility.
render_target
def render_target(renderer: Any, text: str, **attrs: Any) -> str
Legacy render function for backward compatibility.
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
renderer |
Any |
— | |
text |
str |
— |
Returns
str