Functions
_normalize_language
Normalize a requested language to a Pygments-friendly name.
Applies alias mapping and lowercases t…
_normalize_language
def _normalize_language(language: str) -> str
Normalize a requested language to a Pygments-friendly name.
Applies alias mapping and lowercases the language name. Strips file paths if language identifier includes colon (e.g., 'jinja2:path/to/file.html' -> 'jinja2').
Parameters 1
| Name | Type | Default | Description |
|---|---|---|---|
language |
str |
— |
Returns
str
get_lexer_cached
Get a Pygments lexer with aggressive caching.
Strategy:
1. If language specified: cache by languag…
get_lexer_cached
def get_lexer_cached(language: str | None = None, code: str = '') -> Any
Get a Pygments lexer with aggressive caching.
Strategy:
- If language specified: cache by language name (fast path)
- If no language: hash code sample and cache guess result
- Fallback: return text lexer if all else fails
Parameters 2
| Name | Type | Default | Description |
|---|---|---|---|
language |
str | None |
None |
Optional language name (e.g., 'python', 'javascript') |
code |
str |
'' |
Code content (used for guessing if language not specified) |
Returns
Pygments lexer instance Performance:Any
—
clear_cache
Clear the lexer cache. Useful for testing or memory management.
clear_cache
def clear_cache() -> None
Clear the lexer cache. Useful for testing or memory management.
get_cache_stats
Get cache statistics for monitoring.
get_cache_stats
def get_cache_stats() -> dict[str, int | float]
Get cache statistics for monitoring.
Returns
Dict with hits, misses, guess_calls, hit_ratedict[str, int | float]
—
log_cache_stats
Log cache statistics. Call at end of build for visibility.
log_cache_stats
def log_cache_stats() -> None
Log cache statistics. Call at end of build for visibility.