An awesome theme for the Sphinx documentation generator with enhanced features, custom code highlighting, and modern responsive design
Custom HTML builder that extends Sphinx's StandaloneHTMLBuilder with enhanced Pygments highlighting and dark mode CSS support. The AwesomeHTMLBuilder provides advanced code highlighting features and proper handling of dual-mode (light/dark) Pygments styles.
from sphinxawesome_theme.builder import AwesomeHTMLBuilderCustom HTML builder that overrides Pygments CSS handling to support both light and dark mode styles in a single CSS file.
class AwesomeHTMLBuilder(StandaloneHTMLBuilder):
"""HTML builder that overrides methods related to handling CSS for Pygments."""
def init_highlighter(self) -> None:
"""
Initialize Pygments highlighters for both light and dark modes.
Sets up the main highlighter based on pygments_style configuration
and optionally creates a dark mode highlighter if pygments_style_dark
is configured.
"""
def create_pygments_style_file(self) -> None:
"""
Create CSS file for Pygments that includes both light and dark mode styles.
Generates a single pygments.css file that contains the main stylesheet
plus dark mode styles prefixed with '.dark' selector.
"""# Attributes set by init_highlighter
highlighter: AwesomePygmentsBridge # Main highlighter instance
dark_highlighter: AwesomePygmentsBridge | None # Dark mode highlighter if configuredInstall with Tessl CLI
npx tessl i tessl/pypi-sphinxawesome-theme