Classes
HybridHTMLTransformer
4
▼
Optimized HTML transformer combining multiple transformation passes.
This transformer applies Jinj…
HybridHTMLTransformer
4
▼
Optimized HTML transformer combining multiple transformation passes.
This transformer applies Jinja escaping and link transformations in an optimized sequence with quick rejection checks to skip unnecessary work.
Creation: transformer = HybridHTMLTransformer(baseurl="/bengal") result = transformer.transform(html)
Thread Safety: Thread-safe. Transformer instances are stateless after initialization and can be safely shared across threads.
Performance: Approximately 27% faster than calling separate transform functions. Improvement is most significant for pages with transformable content.
Methods
transform
1
str
▼
Transform HTML content with optimized multi-pass approach.
**Applies transform…
transform
1
str
▼
def transform(self, html: str) -> str
Transform HTML content with optimized multi-pass approach.
Applies transformations in sequence:
- Jinja block escaping ({%, %})
- Markdown link normalization (.md -> /)
- Internal link baseurl prefixing (/ -> /baseurl/)
Each step includes quick rejection to skip unnecessary regex work.
Parameters
| Name | Type | Description |
|---|---|---|
html |
— |
HTML content to transform |
Returns
str
Transformed HTML content
Internal Methods 3 ▼
__init__
1
▼
Initialize the transformer.
__init__
1
▼
def __init__(self, baseurl: str = '') -> None
Parameters
| Name | Type | Description |
|---|---|---|
baseurl |
— |
Base URL prefix for internal links (e.g., "/bengal"). If empty, internal link transformation is skipped. Default:''
|
_md_replacer
1
str
▼
Transform .md link to clean URL, preserving anchors.
Handles special cases:
- …
_md_replacer
1
str
▼
def _md_replacer(self, match: re.Match[str]) -> str
Transform .md link to clean URL, preserving anchors.
Handles special cases:
- ./page.md -> ./page/
- ./page.md#section -> ./page/#section
- ./_index.md -> ./
- ../other.md -> ../other/
- path/page.md -> path/page/
Parameters
| Name | Type | Description |
|---|---|---|
match |
— |
Returns
str
_internal_replacer
1
str
▼
Transform internal link with baseurl prefix.
Prepends baseurl to internal link…
_internal_replacer
1
str
▼
def _internal_replacer(self, match: re.Match[str]) -> str
Transform internal link with baseurl prefix.
Prepends baseurl to internal links starting with /. Skips links that already have the baseurl prefix.
Parameters
| Name | Type | Description |
|---|---|---|
match |
— |
Returns
str
Functions
create_transformer
1
HybridHTMLTransformer
▼
Create a transformer instance from site config.
Factory function that extracts…
create_transformer
1
HybridHTMLTransformer
▼
def create_transformer(config: dict[str, Any]) -> HybridHTMLTransformer
Create a transformer instance from site config.
Factory function that extracts baseurl from config and creates an appropriately configured transformer.
Parameters
| Name | Type | Description |
|---|---|---|
config |
dict[str, Any] |
Site configuration dictionary |
Returns
HybridHTMLTransformer