Skip to content

Commit d85484a

Browse files
authored
Merge pull request #374 from machow/fix-param-desc-list-default
fix: parameter description list do not render None as default
2 parents 5ed1430 + 69158d9 commit d85484a

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

quartodoc/renderers/md_renderer.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ParamRow:
5959
def to_definition_list(self):
6060
name = self.name
6161
anno = self.annotation
62-
desc = self.description
62+
desc = sanitize(self.description, allow_markdown=True)
6363
default = sanitize(str(self.default))
6464

6565
part_name = (
@@ -77,7 +77,7 @@ def to_definition_list(self):
7777
# in the table display format, not description lists....
7878
# by this stage _required_ is basically a special token to indicate
7979
# a required argument.
80-
if default is not None:
80+
if self.default is not None:
8181
part_default_sep = Span(" = ", Attr(classes=["parameter-default-sep"]))
8282
part_default = Span(default, Attr(classes=["parameter-default"]))
8383
else:
@@ -100,13 +100,15 @@ def to_definition_list(self):
100100

101101
def to_tuple(self, style: Literal["parameters", "attributes", "returns"]):
102102
name = self.name
103+
description = sanitize(self.description, allow_markdown=True)
104+
103105
if style == "parameters":
104106
default = "_required_" if self.default is None else escape(self.default)
105-
return (name, self.annotation, self.description, default)
107+
return (name, self.annotation, description, default)
106108
elif style == "attributes":
107-
return (name, self.annotation, self.description)
109+
return (name, self.annotation, description)
108110
elif style == "returns":
109-
return (name, self.annotation, self.description)
111+
return (name, self.annotation, description)
110112

111113
raise NotImplementedError(f"Unsupported table style: {style}")
112114

@@ -595,8 +597,9 @@ def render(self, el: ds.DocstringSectionParameters):
595597
@dispatch
596598
def render(self, el: ds.DocstringParameter) -> ParamRow:
597599
annotation = self.render_annotation(el.annotation)
598-
clean_desc = sanitize(el.description, allow_markdown=True)
599-
return ParamRow(el.name, clean_desc, annotation=annotation, default=el.default)
600+
return ParamRow(
601+
el.name, el.description, annotation=annotation, default=el.default
602+
)
600603

601604
# attributes ----
602605

@@ -611,7 +614,7 @@ def render(self, el: ds.DocstringSectionAttributes):
611614
def render(self, el: ds.DocstringAttribute) -> ParamRow:
612615
return ParamRow(
613616
el.name,
614-
sanitize(el.description or "", allow_markdown=True),
617+
el.description or "",
615618
annotation=self.render_annotation(el.annotation),
616619
)
617620

@@ -680,7 +683,7 @@ def render(self, el: ds.DocstringReturn):
680683
# similar to DocstringParameter, but no name or default
681684
return ParamRow(
682685
el.name,
683-
sanitize(el.description, allow_markdown=True),
686+
el.description,
684687
annotation=self.render_annotation(el.annotation),
685688
)
686689

@@ -689,7 +692,7 @@ def render(self, el: ds.DocstringRaise) -> ParamRow:
689692
# similar to DocstringParameter, but no name or default
690693
return ParamRow(
691694
None,
692-
sanitize(el.description, allow_markdown=True),
695+
el.description,
693696
annotation=self.render_annotation(el.annotation),
694697
)
695698

quartodoc/tests/__snapshots__/test_renderers.ambr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,19 +483,19 @@
483483
List
484484
# Parameters {.doc-section .doc-section-parameters}
485485

486-
<code>[**int**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation} [ = ]{.parameter-default-sep} [None]{.parameter-default}</code>
486+
<code>[**int**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation}</code>
487487

488488
: A description.
489489

490490
# Returns {.doc-section .doc-section-returns}
491491

492-
<code>[]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation} [ = ]{.parameter-default-sep} [None]{.parameter-default}</code>
492+
<code>[]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation}</code>
493493

494494
: A description.
495495

496496
# Attributes {.doc-section .doc-section-attributes}
497497

498-
<code>[**int**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation} [ = ]{.parameter-default-sep} [None]{.parameter-default}</code>
498+
<code>[**int**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation}</code>
499499

500500
: A description.
501501
'''
@@ -540,19 +540,19 @@
540540
List
541541
# Parameters {.doc-section .doc-section-parameters}
542542

543-
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation} [ = ]{.parameter-default-sep} [None]{.parameter-default}</code>
543+
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation}</code>
544544

545545
: A description.
546546

547547
# Returns {.doc-section .doc-section-returns}
548548

549-
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation} [ = ]{.parameter-default-sep} [None]{.parameter-default}</code>
549+
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation}</code>
550550

551551
: A description.
552552

553553
# Attributes {.doc-section .doc-section-attributes}
554554

555-
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation} [ = ]{.parameter-default-sep} [None]{.parameter-default}</code>
555+
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation}</code>
556556

557557
: A description.
558558
'''

0 commit comments

Comments
 (0)