Skip to content

Commit

Permalink
chore: Upgrade to quartodoc 0.7.2 and use pandoc.blocks.DefinitionLis…
Browse files Browse the repository at this point in the history
…t to write parameters
  • Loading branch information
gadenbuie committed Dec 18, 2023
1 parent 9d1d012 commit 250f328
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
22 changes: 7 additions & 15 deletions docs/_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from griffe.docstrings import dataclasses as ds
from plum import dispatch
from quartodoc import MdRenderer
from quartodoc.pandoc.blocks import DefinitionList
from quartodoc.renderers.base import convert_rst_link_to_md, sanitize

SHINY_PATH = Path(files("shiny").joinpath())
Expand Down Expand Up @@ -128,17 +129,17 @@ def render_annotation(self, el: None):
return ""

@dispatch
def render_annotation(self, el: exp.Expression):
# an expression is essentially a list[exp.Name | str]
def render_annotation(self, el: exp.Expr):
# an expression is essentially a list[exp.ExprName | str]
# e.g. Optional[TagList]
# -> [Name(source="Optional", ...), "[", Name(...), "]"]

return "".join(map(self.render_annotation, el))

@dispatch
def render_annotation(self, el: exp.Name):
def render_annotation(self, el: exp.ExprName):
# e.g. Name(source="Optional", full="typing.Optional")
return f"[{el.source}](`{el.full}`)"
return f"[{el.name}](`{el.canonical_path}`)"

@dispatch
def summarize(self, el: dc.Object | dc.Alias):
Expand All @@ -163,9 +164,9 @@ def render(self, el: ds.DocstringParameter):
@dispatch
def render(self, el: ds.DocstringSectionParameters):
rows = list(map(self.render, el.value))
header = ["Parameter", "Description"]
# rows is a list of tuples of (<parameter>, <description>)

return render_definition_list(rows)
return str(DefinitionList(rows))

@dispatch
def signature(self, el: dc.Function, source: Optional[dc.Alias] = None):
Expand All @@ -183,15 +184,6 @@ def signature(self, el: dc.Function, source: Optional[dc.Alias] = None):
return super().signature(el, source)


def render_definition_list(rows: list[tuple[str, str]]) -> str:
def indent_newlines(s: str) -> str:
return s.replace("\n", "\n ")

out = [f"{param}\n\n: {indent_newlines(desc)}" for param, desc in rows]

return "\n\n".join(out)


def html_escape_except_backticks(s: str) -> str:
"""
HTML-escape a string, except for content inside of backticks.
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ doc =
tabulate
shinylive==0.1.1
pydantic==1.10
quartodoc==0.4.1
griffe==0.32.3
quartodoc==0.7.2
griffe==0.33.0

[options.packages.find]
include = shiny, shiny.*
Expand Down

0 comments on commit 250f328

Please sign in to comment.