Classes
PygmentsPatch
Context manager and utility class for patching Pygments lexer lookups.
This patch replaces expensi…
PygmentsPatch
Context manager and utility class for patching Pygments lexer lookups.
This patch replaces expensive Pygments plugin discovery with cached lexer instances, dramatically improving markdown parsing performance.
The patch is applied at the module level to markdown.extensions.codehilite, affecting all uses of that module in the current process.
Attributes
| Name | Type | Description |
|---|---|---|
_patched |
bool |
Class-level flag indicating if patch is currently active |
_codehilite_module |
ModuleType | None |
Reference to the patched module (if active) |
_originals |
dict[str, Any] |
Saved original functions for restoration |
Methods 3
apply
classmethod
Apply the Pygments caching patch to markdown.extensions.codehilite.
This metho…
apply
classmethod def apply(cls) -> bool
Apply the Pygments caching patch to markdown.extensions.codehilite.
This method is idempotent - calling it multiple times is safe.
Returns
bool: True if patch was applied, False if already applied or failed.bool
—
restore
classmethod
Restore the original Pygments functions.
This removes the patch and restores t…
restore
classmethod def restore(cls) -> bool
Restore the original Pygments functions.
This removes the patch and restores the original behavior. Primarily useful for testing.
Returns
bool: True if patch was restored, False if not currently patched.bool
—
is_patched
classmethod
Check if the patch is currently active.
is_patched
classmethod def is_patched(cls) -> bool
Check if the patch is currently active.
Returns
bool: True if patched, False otherwise.bool
—
Internal Methods 3
__init__
Initialize the patch context manager.
__init__
def __init__(self) -> None
Initialize the patch context manager.
__enter__
Apply the patch on context enter.
__enter__
def __enter__(self) -> PygmentsPatch
Apply the patch on context enter.
Returns
PygmentsPatch
__exit__
Remove the patch on context exit.
__exit__
def __exit__(self, *args: Any) -> None
Remove the patch on context exit.