Module

rendering.plugins.directives.tabs

Tabs directive for Mistune.

Provides tabbed content sections with full markdown support including nested directives, code blocks, and admonitions.

Architecture:

Built on BengalDirective base class with DirectiveContract validation.
  • TabSetDirective: requires_children=["tab_item"]
  • TabItemDirective: requires_parent=["tab_set"]

MyST syntax (with named closers): :::{tab-set} :::{tab-item} Python :icon: python :badge: Recommended Content here :::{/tab-item} :::{tab-item} JavaScript Content here :::{/tab-item} :::{/tab-set}

Tab-Item Options: :selected: - Whether this tab is initially selected :icon: - Icon name to show next to tab label :badge: - Badge text (e.g., "New", "Beta", "Pro") :disabled: - Mark tab as disabled/unavailable

Classes

TabItemOptions dataclass
Options for tab-item directive.
0

Options for tab-item directive.

Inherits from DirectiveOptions

Attributes

Name Type Description
selected bool

Whether this tab is initially selected

icon str

Icon name to show next to tab label

badge str

Badge text (e.g., "New", "Beta", "Pro")

disabled bool

Mark tab as disabled/unavailable

TabItemDirective
Individual tab directive (nested in tab-set). Syntax: :::{tab-item} Tab Title :selected: …
2

Individual tab directive (nested in tab-set).

Syntax:

:::{tab-item} Tab Title
:selected:
Tab content with full **markdown** support.
:::

Contract:

MUST be nested inside a :::{tab-set} directive.
Inherits from BengalDirective

Attributes

Name Type Description
NAMES ClassVar[list[str]]
TOKEN_TYPE ClassVar[str]
OPTIONS_CLASS ClassVar[type[DirectiveOptions]]
CONTRACT ClassVar[DirectiveContract]
DIRECTIVE_NAMES ClassVar[list[str]]

Methods 2

parse_directive
Build tab-item token from parsed components.
5 DirectiveToken
def parse_directive(self, title: str, options: TabItemOptions, content: str, children: list[Any], state: Any) -> DirectiveToken

Build tab-item token from parsed components.

Parameters 5
title str
options TabItemOptions
content str
children list[Any]
state Any
Returns

DirectiveToken

render
Render individual tab item to HTML. Creates a wrapper div with metadata that t…
2 str
def render(self, renderer: Any, text: str, **attrs: Any) -> str

Render individual tab item to HTML.

Creates a wrapper div with metadata that the parent tab-set will parse to build the navigation and panels.

Parameters 2
renderer Any
text str
Returns

str

TabSetOptions dataclass
Options for tab-set directive.
0

Options for tab-set directive.

Inherits from DirectiveOptions

Attributes

Name Type Description
id str

Unique ID for the tab set

sync str

Sync key for synchronizing tabs across multiple tab-sets

TabSetDirective
Modern MyST-style tab container directive. Syntax: ::::{tab-set} :sync: my-key :::{ta…
2

Modern MyST-style tab container directive.

Syntax:

::::{tab-set}
:sync: my-key

:::{tab-item} Python
Python content with **markdown** support.
:::

:::{tab-item} JavaScript
JavaScript content here.
:::
::::

Contract:

REQUIRES at least one :::{tab-item} child directive.
Inherits from BengalDirective

Attributes

Name Type Description
NAMES ClassVar[list[str]]
TOKEN_TYPE ClassVar[str]
OPTIONS_CLASS ClassVar[type[DirectiveOptions]]
CONTRACT ClassVar[DirectiveContract]
DIRECTIVE_NAMES ClassVar[list[str]]

Methods 2

parse_directive
Build tab-set token from parsed components.
5 DirectiveToken
def parse_directive(self, title: str, options: TabSetOptions, content: str, children: list[Any], state: Any) -> DirectiveToken

Build tab-set token from parsed components.

Parameters 5
title str
options TabSetOptions
content str
children list[Any]
state Any
Returns

DirectiveToken

render
Render tab-set container to HTML. Extracts tab items from rendered children an…
2 str
def render(self, renderer: Any, text: str, **attrs: Any) -> str

Render tab-set container to HTML.

Extracts tab items from rendered children and builds navigation + content panels.

Parameters 2
renderer Any
text str
Returns

str

TabItemData dataclass
Data extracted from a rendered tab-item div.
0

Data extracted from a rendered tab-item div.

Attributes

Name Type Description
title str
selected str
icon str
badge str
disabled str
content str

Functions

_extract_tab_items
Extract tab-item divs from rendered HTML, handling nested divs correctly.
1 list[TabItemData]
def _extract_tab_items(text: str) -> list[TabItemData]

Extract tab-item divs from rendered HTML, handling nested divs correctly.

Parameters 1

Name Type Default Description
text str

Rendered HTML containing tab-item divs

Returns

list[TabItemData]

List of TabItemData with extracted attributes