Skip to content

Commit 4c50a56

Browse files
committed
feat: support rendering class attributes
1 parent d9cbbab commit 4c50a56

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

quartodoc/renderers.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from griffe.docstrings import dataclasses as ds
22
from griffe import dataclasses as dc
3+
from griffe.expressions import Expression, Name
34
from dataclasses import dataclass
45
from tabulate import tabulate
56
from plum import dispatch
@@ -128,6 +129,15 @@ def __init__(
128129
def to_md(self, el):
129130
raise NotImplementedError(f"Unsupported type: {type(el)}")
130131

132+
@dispatch
133+
def to_md(self, el: str):
134+
return el
135+
136+
@dispatch
137+
def to_md(self, el: Union[Expression, Name]):
138+
# these are used often for annotations, and full returns it as a string
139+
return el.full
140+
131141
@dispatch
132142
def to_md(self, el: Union[dc.Alias, dc.Object]):
133143
# TODO: replace hard-coded header level
@@ -204,6 +214,19 @@ def to_md(self, el: ds.DocstringParameter) -> Tuple[str]:
204214
annotation = el.annotation.full if el.annotation else None
205215
return (escape(el.name), annotation, sanitize(el.description), default)
206216

217+
# attributes ----
218+
219+
@dispatch
220+
def to_md(self, el: ds.DocstringSectionAttributes):
221+
header = ["Name", "Type", "Description"]
222+
rows = list(map(self.to_md, el.value))
223+
224+
return tabulate(rows, header, tablefmt="github")
225+
226+
@dispatch
227+
def to_md(self, el: ds.DocstringAttribute):
228+
return el.name, self.to_md(el.annotation), el.description
229+
207230
# examples ----
208231

209232
@dispatch

0 commit comments

Comments
 (0)