Skip to content

Commit c4cbbea

Browse files
authored
Merge pull request #286 from epinzur/esp/add_admonition_support
added admonition support for google docstrings
2 parents e7ffb08 + 2197b39 commit c4cbbea

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ def test_render_doc_attribute(renderer):
104104
assert res == ["abc", r"Optional\[\]", "xyz"]
105105

106106

107+
def test_render_doc_section_admonition(renderer):
108+
section = ds.DocstringSectionAdmonition(
109+
kind="see also",
110+
text="quartodoc.tests.example: Method for doing a thing",
111+
title="See Also",
112+
)
113+
114+
res = renderer.render(section)
115+
print(res)
116+
117+
assert res == "quartodoc.tests.example: Method for doing a thing"
118+
119+
107120
@pytest.mark.parametrize("children", ["embedded", "flat"])
108121
def test_render_doc_module(snapshot, renderer, children):
109122
bp = blueprint(Auto(name="quartodoc.tests.example", children=children))

0 commit comments

Comments
 (0)