Skip to content

common_reports.builders.renderers.html

HTML renderers — the three concrete views of one Document tree.

  • :class:InteractiveHtmlRenderer ← report_template_v2.html — full standalone page: flex shell + sticky TOC + accordion + JS resize, figures rendered TWICE (CDN interactive + base64 PNG fallback).
  • :class:EmailRenderer ← email_report_template.html — single-column stacked block, static PNG only, no JS/TOC/accordion. [G10] viewport initial-scale=2.0, [G11] title=None self-labelling via <h2>, [G12] <style> block + inline critical CSS on elements (multipart-safe).
  • :class:GhostRenderer ← ghost.py — the SAME body wrapped into ONE Mobiledoc HTML-card via GhostPost.mobiledoc_for; figures use hosted PNG URLs.

[G14/G15] honour Section.render_figures. [G16] FigureAsset order (interactive, static, url). Renderers import contracts + schemas only and NEVER mutate components.

Classes

EmailRenderer

Bases: Renderer

Single-column, static-PNG, multipart-safe email view (email_report_template.html). Serves both the report email and the algo update email (algo_update_template == email_template, G17).

images chooses how plots and byte images embed:

  • "data-uri" (default, AlgoReports parity): base64 <img> in the HTML. Gmail’s web client blocks data URIs and clips HTML over ~102 KB.
  • "cid": <img src="cid:figure-N"> plus inline image parts on RenderResult.attachments — send them with the HTML. Email-client-safe and keeps the HTML small.

style chooses the look:

  • "classic" (default): the 0.1.x look, byte-for-byte.
  • "modern": the branded, email-client-safe layout (:class:~common_reports.builders.renderers.modern.ModernEmailRenderer), which also takes brand= and preheader= and defaults to images="cid".

Carried state: per-render figure counter and collected inline attachments (reset by each render). The manifest reports size_bytes and gmail_clip_risk so senders can react before a report is truncated.

__init__

def __init__(*, theme: Theme | None = None, title: str | None = None, date: str | None = None, images: str = 'data-uri', style: str = 'classic', **kw: Any) -> None

Fields and properties declared here; inherited members belong to the bases above.

GMAIL_CLIP_BYTES

GMAIL_CLIP_BYTES = 102 * 1024

STYLES

STYLES = ('classic', 'modern')

style

style = style

target

target = Target.EMAIL

finalize

def finalize(document: Document, body: str) -> RenderResult

render

def render(document: Document) -> RenderResult

visit_button

def visit_button(node: Button) -> str

visit_callout

def visit_callout(node: Callout) -> str

visit_cell

def visit_cell(node: Cell) -> str

visit_columns

def visit_columns(node: Columns) -> str

visit_divider

def visit_divider(node: Divider) -> str

visit_figure

def visit_figure(node: Figure) -> str

visit_grid

def visit_grid(node: Grid) -> str

visit_heading

def visit_heading(node: Heading) -> str

visit_image

def visit_image(node: Image) -> str

visit_kpis

def visit_kpis(node: Kpis) -> str

visit_row

def visit_row(node: Row) -> str

visit_section

def visit_section(node: Section) -> str

visit_spacer

def visit_spacer(node: Spacer) -> str

visit_status

def visit_status(node: Status) -> str

visit_table

def visit_table(node: Table) -> str

visit_text

def visit_text(node: Text) -> str

GhostRenderer

Bases: InteractiveHtmlRenderer

Ghost Admin view — the SAME interactive body, but figures use HOSTED PNG URLs (uploaded via uploader), and the WHOLE rendered HTML is wrapped into one Mobiledoc HTML-card via :meth:GhostPost.mobiledoc_for.

The render result’s manifest['ghost_post'] carries a :class:GhostPost ready for the Admin API POST.

__init__

def __init__(*, uploader: Any = None, theme: Theme | None = None, title: str | None = None, status: str = 'draft', **kw: Any) -> None

Fields and properties declared here; inherited members belong to the bases above.

status

status = status

target

target = Target.GHOST

uploader

uploader = uploader

finalize

def finalize(document: Document, body: str) -> RenderResult

visit_figure

def visit_figure(node: Figure) -> str

InteractiveHtmlRenderer

Bases: Renderer

Full standalone interactive page (report_template_v2.html).

style="modern" builds the branded page instead (:class:~common_reports.builders.renderers.page.ModernPageRenderer).

__init__

def __init__(*, theme: Theme | None = None, title: str | None = None, style: str = 'classic', **kw: Any) -> None

Fields and properties declared here; inherited members belong to the bases above.

STYLES

STYLES = ('classic', 'modern')

style

style = style

target

target = Target.INTERACTIVE

finalize

def finalize(document: Document, body: str) -> RenderResult

visit_button

def visit_button(node: Button) -> str

visit_callout

def visit_callout(node: Callout) -> str

visit_cell

def visit_cell(node: Cell) -> str

visit_columns

def visit_columns(node: Columns) -> str

visit_divider

def visit_divider(node: Divider) -> str

visit_figure

def visit_figure(node: Figure) -> str

visit_grid

def visit_grid(node: Grid) -> str

visit_heading

def visit_heading(node: Heading) -> str

visit_image

def visit_image(node: Image) -> str

visit_kpis

def visit_kpis(node: Kpis) -> str

visit_row

def visit_row(node: Row) -> str

visit_section

def visit_section(node: Section) -> str

visit_spacer

def visit_spacer(node: Spacer) -> str

visit_status

def visit_status(node: Status) -> str

visit_table

def visit_table(node: Table) -> str

visit_text

def visit_text(node: Text) -> str

Functions

render_table_html

def render_table_html(table: Table, *, inline: bool = False) -> str

Render a :class:Table to an HTML <table> honouring the full :class:TableFormat (membership / per-column overrides / scale / colour / index). inline=True adds element-level styles for email robustness [G12].

The values come from the one table engine (builders/tables.py); this is the classic markup all three renderers share.