Module

_config

Frozen configuration dataclasses for Rosettes.

All configuration objects are immutable (frozen) for thread-safety.

Design Philosophy:

Configuration in Rosettes uses frozen dataclasses to ensure:

1. **Thread-Safety**: Immutable state can be safely shared across threads
2. **Predictability**: Config cannot change after creation
3. **Performance**: slots=True reduces memory overhead

Configuration Types:

LexerConfig: Controls lexer behavior (whitespace handling, tab size)
FormatConfig: Controls formatter output (CSS class, wrapping)
HighlightConfig: Controls highlighting (line numbers, hl_lines)

Usage:

Most users don't need to create config objects directly — the high-level
highlight() function accepts keyword arguments that create configs internally.

Direct config usage is for:
  • Custom formatters needing specific settings
  • Reusing config across multiple highlight calls
  • Unit testing with controlled configuration

See Also:

rosettes.highlight: High-level API that accepts config via kwargs
rosettes.formatters.html.HtmlFormatter: Uses HighlightConfig

Classes

LexerConfig 2
Configuration for lexer behavior.

Configuration for lexer behavior.

Attributes

Name Type Description
strip_whitespace bool

If True, strip trailing whitespace from lines.

tab_size int

Number of spaces per tab for column calculation.

FormatConfig 4
Configuration for output formatting.

Configuration for output formatting.

Attributes

Name Type Description
css_class str

Base CSS class for the code container.

wrap_code bool

If True, wrap output in

 tags.

class_prefix str

Prefix for token CSS classes.

data_language str | None

Language name for data-language attribute (e.g., 'python').

HighlightConfig 5
Combined configuration for syntax highlighting.

Combined configuration for syntax highlighting.

Attributes

Name Type Description
hl_lines frozenset[int]

Set of 1-based line numbers to highlight.

show_linenos bool

If True, include line numbers in output.

css_class str

Base CSS class for the code container.

lineno_class str

CSS class for line number elements.

hl_line_class str

CSS class for highlighted lines.