Source code for httk.serve.web.renderers.base

"""Define renderer inputs and outputs shared by content renderers."""

from collections.abc import Mapping
from dataclasses import dataclass
from pathlib import Path


@dataclass(frozen=True)
[docs] class WidgetPlacement: """Describe a widget invocation replaced by a stable placeholder. :param placeholder: Placeholder text inserted into rendered content. :param name: Requested widget name. :param props: Literal widget properties. :param source_path: Source file containing the invocation. :param line: One-based source line. :param column: One-based source column. :param snippet: Original invocation text. """
[docs] placeholder: str
[docs] name: str
[docs] props: Mapping[str, object]
[docs] source_path: Path
[docs] line: int
[docs] column: int
[docs] snippet: str
from typing import Protocol @dataclass(frozen=True)
[docs] class RenderResult: """Carry rendered HTML, metadata, and widget placements. :param html: Rendered HTML before templates are applied. :param metadata: Source metadata. :param widgets: Widget placements found in the source. """
[docs] html: str
[docs] metadata: dict[str, object]
[docs] widgets: tuple[WidgetPlacement, ...] = ()
[docs] class Renderer(Protocol): """Define the source-renderer protocol."""
[docs] def render(self, source_path: Path) -> RenderResult: """Render a source file into HTML and metadata.""" ...