Module

roles.builtins.formatting

Formatting roles for inline styling.

Provides roles for common inline formatting:

  • kbd: Keyboard shortcuts
  • abbr: Abbreviations with expansion
  • sub: Subscript
  • sup: Superscript

Example:

Press Ctrl+C to copy. The HTML (HyperText Markup Language) standard. H2O is water. E = mc2.

Classes

KbdRole 4
Handler for {kbd}`key` role. Renders keyboard shortcuts with proper semantics. Syntax: {kbd}`…

Handler for key role.

Renders keyboard shortcuts with proper semantics.

Syntax:

{kbd}`Ctrl+C` - Single shortcut
{kbd}`Ctrl+Shift+P` - Multiple modifiers

Thread Safety:

Stateless handler. Safe for concurrent use.

Attributes

Name Type Description
names ClassVar[tuple[str, ...]]
token_type ClassVar[str]

Methods

parse 3 Role
Parse kbd role content.
def parse(self, name: str, content: str, location: SourceLocation) -> Role
Parameters
Name Type Description
name
content
location
Returns
Role
render 2
Render keyboard shortcut. Wraps each key in tags for proper semantics. Handle…
def render(self, node: Role, sb: StringBuilder) -> None

Render keyboard shortcut.

Wraps each key in tags for proper semantics. Handles + as key separator.

Parameters
Name Type Description
node
sb
AbbrRole 4
Handler for {abbr}`ABBR (expansion)` role. Renders abbreviations with title attribute for expansio…

Handler for ABBR (expansion) role.

Renders abbreviations with title attribute for expansion.

Syntax:

{abbr}`HTML (HyperText Markup Language)`

Thread Safety:

Stateless handler. Safe for concurrent use.

Attributes

Name Type Description
names ClassVar[tuple[str, ...]]
token_type ClassVar[str]

Methods

parse 3 Role
Parse abbr role content. Extracts abbreviation and expansion from "ABBR (expan…
def parse(self, name: str, content: str, location: SourceLocation) -> Role

Parse abbr role content.

Extracts abbreviation and expansion from "ABBR (expansion)" format.

Parameters
Name Type Description
name
content
location
Returns
Role
render 2
Render abbreviation with title.
def render(self, node: Role, sb: StringBuilder) -> None
Parameters
Name Type Description
node
sb
SubRole 4
Handler for {sub}`text` role. Renders subscript text. Syntax: H{sub}`2`O Thread Safety: …

Handler for text role.

Renders subscript text.

Syntax:

H{sub}`2`O

Thread Safety:

Stateless handler. Safe for concurrent use.

Attributes

Name Type Description
names ClassVar[tuple[str, ...]]
token_type ClassVar[str]

Methods

parse 3 Role
Parse sub role content.
def parse(self, name: str, content: str, location: SourceLocation) -> Role
Parameters
Name Type Description
name
content
location
Returns
Role
render 2
Render subscript.
def render(self, node: Role, sb: StringBuilder) -> None
Parameters
Name Type Description
node
sb
SupRole 4
Handler for {sup}`text` role. Renders superscript text. Syntax: E = mc{sup}`2` Thread Safety…

Handler for text role.

Renders superscript text.

Syntax:

E = mc{sup}`2`

Thread Safety:

Stateless handler. Safe for concurrent use.

Attributes

Name Type Description
names ClassVar[tuple[str, ...]]
token_type ClassVar[str]

Methods

parse 3 Role
Parse sup role content.
def parse(self, name: str, content: str, location: SourceLocation) -> Role
Parameters
Name Type Description
name
content
location
Returns
Role
render 2
Render superscript.
def render(self, node: Role, sb: StringBuilder) -> None
Parameters
Name Type Description
node
sb