User renderers to fill an Markdown template and write to path.
Source code in dvc_render/markdown.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 | def render_markdown(
renderers: list["Renderer"],
output_file: Optional["StrPath"] = None,
template_path: Optional["StrPath"] = None,
) -> "StrPath":
"User renderers to fill an Markdown template and write to path."
output_path = None
if output_file:
output_path = Path(output_file)
output_path.parent.mkdir(exist_ok=True)
page = None
if template_path:
with open(template_path, encoding="utf-8") as fobj:
page = fobj.read()
document = Markdown(page)
for renderer in renderers:
document.with_element(renderer.generate_markdown(report_path=output_path))
if output_file and output_path:
output_path.write_text(document.embed(), encoding="utf8")
return output_file
return document.embed()
|