Implementation:666ghj BettaFish HTMLRenderer render
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Report_Generation, HTML_Rendering, Data_Visualization |
| Last Updated | 2026-10-08 00:00 GMT |
Overview
Concrete renderer that converts a Document IR into a complete, self-contained HTML document with embedded CSS, Chart.js visualizations, MathJax formulas, and interactive scripts.
Description
The HTMLRenderer is the largest component in ReportEngine (6536 lines). It takes a Document IR dict and produces a complete HTML string. Key capabilities:
- Renders all IR block types (headings, paragraphs, lists, tables, charts, code, math, callouts, KPI cards, timelines, word clouds, sankey diagrams)
- Validates Chart.js configurations via ChartValidator and repairs invalid configs via ChartRepairAPI (LLM-based)
- Embeds all JavaScript libraries (Chart.js, MathJax, html2canvas, jsPDF, wordcloud2) as inline strings for self-contained output
- Generates table of contents from chapter anchors
- Renders hero sections with KPI metrics
- Supports custom theme overrides via config
Usage
Import this class when you need to render a Document IR to HTML. It is the final step in the ReportEngine pipeline.
Code Reference
Source Location
- Repository: BettaFish
- File: `ReportEngine/renderers/html_renderer.py:L35-6536`
Signature
class HTMLRenderer:
def __init__(self, config: Dict[str, Any] | None = None):
"""
Args:
config: Optional overrides (themeOverride, enableDebug)
"""
def render(
self,
document_ir: Dict[str, Any],
ir_file_path: str | None = None,
) -> str:
"""
Render Document IR to complete HTML string.
Args:
document_ir: Document IR from DocumentComposer
ir_file_path: Optional path for chart repair persistence
Returns:
Complete HTML document string with embedded CSS, JS, charts
"""
Import
from ReportEngine.renderers import HTMLRenderer
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| document_ir | Dict[str, Any] | Yes | Document IR from DocumentComposer |
| ir_file_path | None | No | Path for chart repair persistence |
| config | Dict | No | Theme overrides, debug flag |
Outputs
| Name | Type | Description |
|---|---|---|
| html | str | Complete HTML document with CSS, Chart.js, MathJax |
Usage Examples
Render Document IR to HTML
from ReportEngine.renderers import HTMLRenderer
renderer = HTMLRenderer(config={"enableDebug": True})
html = renderer.render(
document_ir=document_ir,
ir_file_path="output/run1/document_ir.json"
)
# Save to file
with open("output/report.html", "w", encoding="utf-8") as f:
f.write(html)
print(f"Generated {len(html)} chars of HTML")
Related Pages
Implements Principle
- Principle:666ghj_BettaFish_IR_Validation
- Principle:666ghj_BettaFish_Template_Driven_Report_Generation
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment