From 083c9d8fb92075d95224a544c697916c7a064d80 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 21 Dec 2023 11:55:47 +0100 Subject: [PATCH] Don't execute serialisation login in jinja. This makes it a bit easier to profile as function calls in jinja are hard to track. --- papyri/render.py | 2 +- papyri/templates/html.tpl.j2 | 4 ++-- papyri/templates/macros.tpl.j2 | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/papyri/render.py b/papyri/render.py index a9e4a23e..58cea122 100644 --- a/papyri/render.py +++ b/papyri/render.py @@ -657,7 +657,7 @@ def render_one( backrefs_ = (None, group_backrefs(backrefs, self.LR)) - root = self._myst_root(doc) + root = json.dumps(self._myst_root(doc).to_dict(), indent=2) try: module = qa.split(".")[0] return template.render( diff --git a/papyri/templates/html.tpl.j2 b/papyri/templates/html.tpl.j2 index 4b0aae64..6302c31e 100644 --- a/papyri/templates/html.tpl.j2 +++ b/papyri/templates/html.tpl.j2 @@ -4,12 +4,12 @@
-{% from 'macros.tpl.j2' import render_paragraph, example, render_myst, render_II with context %} +{% from 'macros.tpl.j2' import render_paragraph, example, render_myst_json, render_II with context %} {% from 'graph.tpl.j2' import d3script with context%} -{{render_myst(myst_root)}} +{{render_myst_json(myst_root)}} {% if backrefs[0] or backrefs[1] %} diff --git a/papyri/templates/macros.tpl.j2 b/papyri/templates/macros.tpl.j2 index 5b4500cb..e1ba06b7 100644 --- a/papyri/templates/macros.tpl.j2 +++ b/papyri/templates/macros.tpl.j2 @@ -5,6 +5,15 @@ {%- endfor %} {%- endmacro %} + + +{% macro render_myst_json(json) -%} + {% set key = uuid() %} +
+ +{%- endmacro %} {% macro render_myst(obj) -%} {% set astJson = obj.to_dict() %} {% set key = uuid() %}