Classes
Renderer
Renders individual pages using templates and content processing.
Handles template rendering, conte…
Renderer
Renders individual pages using templates and content processing.
Handles template rendering, content processing (H1 stripping), and error collection. Integrates with template engine for Jinja2 rendering and provides graceful error handling.
Creation:
Direct instantiation: Renderer(template_engine, build_stats=None)
- Created by RenderingPipeline for page rendering
- Requires TemplateEngine instance
Attributes
| Name | Type | Description |
|---|---|---|
template_engine |
— | TemplateEngine instance for Jinja2 rendering |
site |
— | Site instance (accessed via template_engine.site) |
build_stats |
— | Optional BuildStats for error collection |
Relationships |
— |
|
Methods 2
render_content
Render raw content (already parsed HTML).
Automatically strips the first H1 ta…
render_content
def render_content(self, content: str) -> str
Render raw content (already parsed HTML).
Automatically strips the first H1 tag to avoid duplication with the template-rendered title.
Parameters 1
content |
str |
Parsed HTML content |
Returns
Content with first H1 removedstr
—
render_page
Render a complete page with template.
Architecture:
1. Builds initial context …
render_page
def render_page(self, page: Page, content: str | None = None) -> str
Render a complete page with template.
Architecture:
- Builds initial context (metadata, TOC, content)
- Adds specialized context based on page type:
- Generated pages (tags/archives): Adds filtered
postslist - Section pages: Adds section-specific
posts - Root index: Adds top-level pages
- Generated pages (tags/archives): Adds filtered
- Renders using Jinja2 template
Conflict Prevention:
Logic strictly separates "Root Index" (home page) from "Generated Index" (tag pages).
Tag pages often have source paths liketags/foo/index.md(is_index_page=True)
but must NOT use the root home page logic which overwrites theirpostslist.
Parameters 2
page |
Page |
Page to render |
content |
str | None |
Optional pre-rendered content (uses page.parsed_ast if not provided) |
Returns
Fully rendered HTML pagestr
—
Internal Methods 6
__init__
Initialize the renderer.
__init__
def __init__(self, template_engine: Any, build_stats: Any = None) -> None
Initialize the renderer.
Parameters 2
template_engine |
Any |
Template engine instance |
build_stats |
Any |
Optional BuildStats object for error collection |
_strip_first_h1
Remove the first H1 tag from HTML content.
This prevents duplication when temp…
_strip_first_h1
def _strip_first_h1(self, content: str) -> str
Remove the first H1 tag from HTML content.
This prevents duplication when templates render {{ page.title }} as H1 and the markdown also contains an H1 heading.
Parameters 1
content |
str |
HTML content |
Returns
Content with first H1 tag removedstr
—
_add_generated_page_context
Add special context variables for generated pages (archives, tags, etc.).
_add_generated_page_context
def _add_generated_page_context(self, page: Page, context: dict[str, Any]) -> None
Add special context variables for generated pages (archives, tags, etc.).
Parameters 2
page |
Page |
Page being rendered |
context |
dict[str, Any] |
Template context to update |
_get_template_name
Determine which template to use for a page.
Priority order:
1. Explicit templa…
_get_template_name
def _get_template_name(self, page: Page) -> str
Determine which template to use for a page.
Priority order:
- Explicit template in frontmatter (
template: doc.html) - Content type strategy (delegates to strategy.get_template())
- Section-based auto-detection (e.g.,
docs.html,docs/single.html) - Default fallback (
page.htmlorindex.html)
Note: We use a simple, explicit template selection strategy without complex type/kind/layout hierarchies.
Parameters 1
page |
Page |
Page to get template for |
Returns
Template namestr
—
_template_exists
Check if a template exists in any template directory.
_template_exists
def _template_exists(self, template_name: str) -> bool
Check if a template exists in any template directory.
Parameters 1
template_name |
str |
Template filename or path |
Returns
True if template exists, False otherwisebool
—
_render_fallback
Render a fallback HTML page with basic styling.
When the main template fails, …
_render_fallback
def _render_fallback(self, page: Page, content: str) -> str
Render a fallback HTML page with basic styling.
When the main template fails, we still try to produce a usable page with basic CSS and structure (though without partials/navigation).
Parameters 2
page |
Page |
Page to render |
content |
str |
Page content |
Returns
Fallback HTML page with minimal stylingstr
—