32 lines
806 B
Python
32 lines
806 B
Python
import json
|
|
from pathlib import Path
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
|
|
def main():
|
|
# load input data
|
|
# path() over hardcoding str
|
|
data = json.loads(Path("examples/input.json").read_text(encoding="utf-8"))
|
|
|
|
# setup template eng
|
|
# create jinja2 env for templates
|
|
env = Environment(
|
|
# look in templates/
|
|
loader=FileSystemLoader("templates"),
|
|
# trim whitespaces
|
|
trim_blocks=True,
|
|
lstrip_blocks=True,
|
|
)
|
|
# load template to render
|
|
# **data spreads dict so keys become template vars
|
|
template = env.get_template("doc.md.j2")
|
|
out = template.render(**data)
|
|
|
|
# write output - render md to file
|
|
Path("out.md").write_text(out, encoding="utf-8")
|
|
print("wrote out.md")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|