Module

rendering.link_transformer

Link Transformer - Prepends baseurl to internal links in rendered HTML.

This module handles the transformation of internal links (those starting with /) to include the configured baseurl. This is essential for deployments where the site is not at the root of the domain (e.g., GitHub Pages project sites).

Example:

Withbaseurl="/bengal":

href="/docs/guide/"     -> href="/bengal/docs/guide/"
href="https://ext.com/" -> unchanged (external)
href="guide/"           -> unchanged (relative)
href="#section"         -> unchanged (anchor)

Functions

transform_internal_links
Transform internal links to include baseurl prefix. This function finds all ``<a href="/...">`` an…
2 str
def transform_internal_links(html: str, baseurl: str) -> str

Transform internal links to include baseurl prefix.

This function finds all<a href="/...">and<img src="/...">tags where the path starts with "/" and prepends the baseurl.

Parameters 2

Name Type Default Description
html str

Rendered HTML content

baseurl str

Base URL prefix (e.g., "/bengal" or "https://example.com/bengal")

Returns

str

HTML with transformed internal links

should_transform_links
Check if link transformation should be applied. Link transformation is enabled when: 1. baseurl is…
1 bool
def should_transform_links(config: dict[str, Any]) -> bool

Check if link transformation should be applied.

Link transformation is enabled when:

  1. baseurl is configured (non-empty)
  2. transform_links is not explicitly disabled

Parameters 1

Name Type Default Description
config dict[str, Any]

Site configuration dict

Returns

bool

True if links should be transformed

get_baseurl
Get normalized baseurl from config.
1 str
def get_baseurl(config: dict[str, Any]) -> str

Get normalized baseurl from config.

Parameters 1

Name Type Default Description
config dict[str, Any]

Site configuration dict

Returns

str

Normalized baseurl string or empty string