Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Nov 15, 2023
1 parent 3fe5eef commit 5634a33
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
27 changes: 22 additions & 5 deletions papyri/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -578,6 +578,7 @@ def render_one(
<Multiline Description Here>
"""
assert template is not None

assert isinstance(meta, dict)
# TODO : move this to ingest likely.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion papyri/templates/macros.tpl.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ e{% macro render_inner(type_, obj) -%}
{%- elif type_ == 'Directive' -%}
<!-- In theory we should never get Raw directive in final output --!>
{{ render_myst(obj) }}
{%- elif type_ in ('Math', 'Verbatim', 'Link', 'MText','MEmphasis','MInlineCode') -%}
{%- elif type_ in ('Link',) -%}
<!-- Likely replace with MLink-->
{{ 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__)}}
Expand Down

0 comments on commit 5634a33

Please sign in to comment.