Skip to content

Commit 4b90124

Browse files
committed
added admonition support for google doc strings
1 parent 049a7ba commit 4b90124

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

quartodoc/renderers/md_renderer.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ def _fetch_object_dispname(self, el: "dc.Alias | dc.Object"):
9999
return el.canonical_path
100100

101101
raise ValueError(f"Unsupported display_name: `{self.display_name}`")
102-
102+
103103
def _fetch_method_parameters(self, el: dc.Function):
104104
# adapted from mkdocstrings-python jinja tempalate
105105
if el.parent and el.parent.is_class and len(el.parameters) > 0:
106106
if el.parameters[0].name in {"self", "cls"}:
107107
return dc.Parameters(*list(el.parameters)[1:])
108-
108+
109109
return el.parameters
110110

111111
def _render_table(self, rows, headers):
@@ -135,7 +135,7 @@ def render_annotation(self, el: expr.Name) -> str:
135135
# unescaped pipes screw up table formatting
136136
if self.render_interlinks:
137137
return f"[{sanitize(el.source)}](`{el.full}`)"
138-
138+
139139
return sanitize(el.source)
140140

141141
@dispatch
@@ -502,6 +502,20 @@ def render(self, el: ds.DocstringAttribute):
502502
]
503503
return row
504504

505+
# admonition ----
506+
# note this can be a see-also, warnings, or notes section
507+
# from the googledoc standard
508+
@dispatch
509+
def render(self, el: ds.DocstringSectionAdmonition):
510+
kind = el.title.lower()
511+
if kind in ["notes", "warnings"]:
512+
return el.value.description
513+
elif kind == "see also":
514+
# TODO: attempt to parse See Also sections
515+
return convert_rst_link_to_md(el.value.description)
516+
517+
raise NotImplementedError(f"Unsupported DocstringSectionAdmonition kind: {kind}")
518+
505519
# warnings ----
506520

507521
@dispatch

quartodoc/tests/test_renderers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ def test_render_doc_attribute(renderer):
103103

104104
assert res == ["abc", r"Optional\[\]", "xyz"]
105105

106+
def test_render_doc_section_admonition(renderer):
107+
section = ds.DocstringSectionAdmonition(
108+
kind="see also",
109+
text="quartodoc.tests.example: Method for doing a thing",
110+
title="See Also",
111+
)
112+
113+
res = renderer.render(section)
114+
print(res)
115+
116+
assert res == "quartodoc.tests.example: Method for doing a thing"
117+
106118

107119
@pytest.mark.parametrize("children", ["embedded", "flat"])
108120
def test_render_doc_module(snapshot, renderer, children):

0 commit comments

Comments
 (0)