Use renderers
to fill an HTML template and write to output_file
.
Source code in dvc_render/html.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 | def render_html(
renderers: list["Renderer"],
output_file: "StrPath",
html_template: Optional["StrPath"] = None,
refresh_seconds: Optional[int] = None,
) -> "StrPath":
"Use `renderers` to fill an HTML template and write to `output_file`."
output_path = Path(output_file)
output_path.parent.mkdir(exist_ok=True)
page_html: Optional[str] = None
if html_template and Path(html_template).is_file():
page_html = Path(html_template).read_text(encoding="utf8")
elif isinstance(html_template, str):
page_html = html_template
document = HTML(page_html, refresh_seconds=refresh_seconds)
sorted_renderers = sorted(
renderers,
key=_order_image_per_step,
)
for renderer in sorted_renderers:
document.with_scripts(renderer.SCRIPTS)
document.with_element(renderer.generate_html(html_path=output_path))
output_path.write_text(document.embed(), encoding="utf8")
return output_file
|