From 5634a33097101370b8b0689aaf3c072251862e14 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 9 Nov 2023 14:49:04 +0100 Subject: [PATCH] cleanup --- papyri/render.py | 27 ++++++++++++++++++++++----- papyri/templates/macros.tpl.j2 | 6 +++++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/papyri/render.py b/papyri/render.py index 0f9c38e3..61c510be 100644 --- a/papyri/render.py +++ b/papyri/render.py @@ -31,7 +31,7 @@ from .crosslink import IngestedBlobs, find_all_refs from .graphstore import GraphStore, Key from .myst_ast import MLink, MText -from .take2 import RefInfo, Section, encoder +from .take2 import RefInfo, Section, encoder, Link from .tree import TreeReplacer, TreeVisitor from .utils import dummy_progress, progress @@ -578,6 +578,7 @@ def render_one( """ + assert template is not None assert isinstance(meta, dict) # TODO : move this to ingest likely. @@ -752,11 +753,15 @@ async def _write_api_file( gfiles = list(self.store.glob((None, None, "module", None))) random.shuffle(gfiles) if config.ascii: - env, template = _ascii_env() + env, ascii_template = _ascii_env() + else: + env, ascii_template = None, None for _, key in progress(gfiles, description="Rendering API..."): module, version = key.module, key.version if config.ascii: - await _ascii_render(key, store=self.store, env=env, template=template) + await _ascii_render( + key, store=self.store, env=env, template=ascii_template + ) if config.html: doc_blob, qa, siblings, parts_links, backward, forward = await loc( key, @@ -1142,7 +1147,7 @@ class LinkReifier(TreeReplacer): def __init__(self, resolver): self.resolver = resolver - def replace_Link(self, link): + def replace_Link(self, link: Link): """ By default our links resolution is delayed, Here we resolve them. @@ -1164,6 +1169,19 @@ def replace_Link(self, link): else: return [MText(link.value + "(?)")] + def replace_RefInfo(self, refinfo: RefInfo): + """ + By default our links resolution is delayed, + Here we resolve them. + + Some of this resolution should be moved to earlier. + """ + exists, turl = self.resolver.exists_resolve(refinfo) + if exists: + return [MLink(children=[MText(refinfo.path)], url=turl, title=refinfo.path)] + else: + return [MText(refinfo.path + "(?)")] + def old_render_one( store: GraphStore, @@ -1185,7 +1203,6 @@ def old_render_one( a Doc object with the informations for current obj qa : str fully qualified name for current object - """ assert isinstance(meta, dict) diff --git a/papyri/templates/macros.tpl.j2 b/papyri/templates/macros.tpl.j2 index 3466609c..93b5298d 100644 --- a/papyri/templates/macros.tpl.j2 +++ b/papyri/templates/macros.tpl.j2 @@ -12,7 +12,11 @@ e{% macro render_inner(type_, obj) -%} {%- elif type_ == 'Directive' -%} {{ render_myst(obj) }} - {%- elif type_ in ('Math', 'Verbatim', 'Link', 'MText','MEmphasis','MInlineCode') -%} + {%- elif type_ in ('Link',) -%} + + {{ unreachable(obj)}} + {{ render_myst(obj) }} + {%- elif type_ in ('Math', 'Verbatim', 'MText','MEmphasis','MInlineCode') -%} {{ render_myst(obj) }} {%- elif type_ in ['SubstitutionRef','Unimplemented'] %} {{unimplemented(type_, obj.__class__.__name__, obj.__dict__)}}