Classes
DirectiveToken
dataclass
Typed AST token for directives.
Replaces ad-hoc dicts like:
{"type": "dropdown", "attrs": {...…
DirectiveToken
dataclass Typed AST token for directives.
Replaces ad-hoc dicts like: {"type": "dropdown", "attrs": {...}, "children": [...]}
Benefits:
- Type checking catches typos
- IDE autocomplete for fields
- Consistent structure across all directives
Attributes
| Name | Type | Description |
|---|---|---|
type |
str |
Token type string (e.g., "dropdown", "step", "tab_item") |
attrs |
dict[str, Any] |
Token attributes dict (title, options, etc.) |
children |
list[Any] |
Nested tokens (parsed child content) |
Methods 4
to_dict
Convert to dict for mistune AST compatibility.
to_dict
def to_dict(self) -> dict[str, Any]
Convert to dict for mistune AST compatibility.
Returns
Dict in the format mistune expects:dict[str, Any]
— {"type": str, "attrs": dict, "children": list}
from_dict
classmethod
Create from dict (useful for testing and deserialization).
from_dict
classmethod def from_dict(cls, data: dict[str, Any]) -> DirectiveToken
Create from dict (useful for testing and deserialization).
Parameters 1
data |
dict[str, Any] |
Dict with "type", optional "attrs", optional "children" |
Returns
DirectiveToken instanceDirectiveToken
—
with_attrs
Return new token with additional/updated attributes.
Useful for adding compute…
with_attrs
def with_attrs(self, **extra_attrs: Any) -> DirectiveToken
Return new token with additional/updated attributes.
Useful for adding computed attributes without mutating original.
Returns
New DirectiveToken with merged attrsDirectiveToken
—
with_children
Return new token with different children.
with_children
def with_children(self, children: list[Any]) -> DirectiveToken
Return new token with different children.
Parameters 1
children |
list[Any] |
New children list |
Returns
New DirectiveToken with specified childrenDirectiveToken
—