Classes
HtmlFormatter
8
▼
HTML formatter with streaming output.
Thread-safe: all state is immutable or local to method calls…
HtmlFormatter
8
▼
HTML formatter with streaming output.
Thread-safe: all state is immutable or local to method calls. Instances are frozen dataclasses and can be safely shared across threads.
Output Structure:
def ...
Attributes
| Name | Type | Description |
|---|---|---|
config |
HighlightConfig
|
Highlight configuration for line highlighting, line numbers. |
css_class_style |
CssClassStyle
|
"semantic" for .syntax-* or "pygments" for .k, .nf |
Methods
name
0
str
▼
property
name
0
str
▼
def name(self) -> str
Returns
str
container_class
0
str
▼
Get the container CSS class based on style.
property
container_class
0
str
▼
def container_class(self) -> str
Returns
str
format_fast
2
Iterator[str]
▼
Ultra-fast formatting without line highlighting.
Uses role-based class names f…
format_fast
2
Iterator[str]
▼
def format_fast(self, tokens: Iterator[tuple[TokenType, str]], config: FormatConfig | None = None) -> Iterator[str]
Ultra-fast formatting without line highlighting.
Uses role-based class names for semantic mode.
Optimizations:
- Pre-built span templates (no f-string per token)
- Direct dict lookup (O(1))
- Minimal branching in hot path
Parameters
| Name | Type | Description |
|---|---|---|
tokens |
— |
|
config |
— |
Default:None
|
Returns
Iterator[str]
format
2
Iterator[str]
▼
Format tokens as HTML with streaming output.
format
2
Iterator[str]
▼
def format(self, tokens: Iterator[Token], config: FormatConfig | None = None) -> Iterator[str]
Parameters
| Name | Type | Description |
|---|---|---|
tokens |
— |
|
config |
— |
Default:None
|
Returns
Iterator[str]
format_string
2
str
▼
format_string
2
str
▼
def format_string(self, tokens: Iterator[Token], config: FormatConfig | None = None) -> str
Parameters
| Name | Type | Description |
|---|---|---|
tokens |
— |
|
config |
— |
Default:None
|
Returns
str
format_string_fast
2
str
▼
format_string_fast
2
str
▼
def format_string_fast(self, tokens: Iterator[tuple[TokenType, str]], config: FormatConfig | None = None) -> str
Parameters
| Name | Type | Description |
|---|---|---|
tokens |
— |
|
config |
— |
Default:None
|
Returns
str