Skip to content

Commit 1e757ae

Browse files
committed
feat(renderer): narrow notes and warnings sections
1 parent a716a86 commit 1e757ae

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

quartodoc/renderers.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,28 @@ def tuple_to_data(el: "tuple[ds.DocstringSectionKind, str]"):
3030

3131
def docstring_section_narrow(el: ds.DocstringSection) -> ds.DocstringSection:
3232
# attempt to narrow down text sections
33+
to_narrow = [
34+
DocstringSectionSeeAlso,
35+
DocstringSectionNotes,
36+
DocstringSectionWarnings,
37+
]
3338
prefix = "See Also\n---"
34-
if isinstance(el, ds.DocstringSectionText) and el.value.startswith(prefix):
35-
stripped = el.value.replace(prefix, "", 1).lstrip("-\n")
36-
return DocstringSectionSeeAlso(stripped, el.title)
39+
40+
if isinstance(el, ds.DocstringSectionText):
41+
for cls in to_narrow:
42+
prefix = cls.kind.value.title() + "\n---"
43+
if el.value.lstrip("\n").startswith(prefix):
44+
45+
stripped = el.value.replace(prefix, "", 1).lstrip("-\n")
46+
return cls(stripped, el.title)
3747

3848
return el
3949

4050

4151
class DocstringSectionKindPatched(Enum):
4252
see_also = "see also"
53+
notes = "notes"
54+
warnings = "warnings"
4355

4456

4557
class DocstringSectionSeeAlso(ds.DocstringSection):
@@ -50,6 +62,22 @@ def __init__(self, value: str, title: "str | None"):
5062
super().__init__(title)
5163

5264

65+
class DocstringSectionNotes(ds.DocstringSection):
66+
kind = DocstringSectionKindPatched.notes
67+
68+
def __init__(self, value: str, title: "str | None"):
69+
self.value = value
70+
super().__init__(title)
71+
72+
73+
class DocstringSectionWarnings(ds.DocstringSection):
74+
kind = DocstringSectionKindPatched.warnings
75+
76+
def __init__(self, value: str, title: "str | None"):
77+
self.value = value
78+
super().__init__(title)
79+
80+
5381
@dataclass
5482
class ExampleCode:
5583
value: str

0 commit comments

Comments
 (0)