Skip to content

Commit fc6f182

Browse files
committed
fix: move sanitization back inside render_annotations
1 parent 7ff0016 commit fc6f182

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

quartodoc/renderers/md_renderer.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def render_annotation(self, el: str) -> str:
114114
el:
115115
An object representing a type annotation.
116116
"""
117-
return el
117+
return sanitize(el)
118118

119119
@dispatch
120120
def render_annotation(self, el: None) -> str:
@@ -125,9 +125,9 @@ def render_annotation(self, el: expr.Name) -> str:
125125
# TODO: maybe there is a way to get tabulate to handle this?
126126
# unescaped pipes screw up table formatting
127127
if self.render_interlinks:
128-
return f"[{el.source}](`{el.full}`)"
128+
return f"[{sanitize(el.source)}](`{el.full}`)"
129129

130-
return el.source
130+
return sanitize(el.source)
131131

132132
@dispatch
133133
def render_annotation(self, el: expr.Expression) -> str:
@@ -415,17 +415,19 @@ def render(self, el: dc.Parameter):
415415
glob = ""
416416

417417
annotation = self.render_annotation(el.annotation)
418+
name = sanitize(el.name)
419+
418420
if self.show_signature_annotations:
419421
if annotation and has_default:
420-
res = f"{glob}{el.name}: {annotation} = {el.default}"
422+
res = f"{glob}{name}: {annotation} = {el.default}"
421423
elif annotation:
422-
res = f"{glob}{el.name}: {annotation}"
424+
res = f"{glob}{name}: {annotation}"
423425
elif has_default:
424-
res = f"{glob}{el.name}={el.default}"
426+
res = f"{glob}{name}={el.default}"
425427
else:
426-
res = f"{glob}{el.name}"
428+
res = f"{glob}{name}"
427429

428-
return sanitize(res)
430+
return res
429431

430432
# docstring parts -------------------------------------------------------------
431433

@@ -471,7 +473,7 @@ def render(self, el: ds.DocstringSectionAttributes):
471473
def render(self, el: ds.DocstringAttribute):
472474
row = [
473475
sanitize(el.name),
474-
sanitize(self.render_annotation(el.annotation)),
476+
self.render_annotation(el.annotation),
475477
sanitize(el.description or "", allow_markdown=True),
476478
]
477479
return row

quartodoc/tests/__snapshots__/test_renderers.ambr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
'''
44
# quartodoc.tests.example_signature.a_complex_signature { #quartodoc.tests.example_signature.a_complex_signature }
55

6-
`tests.example_signature.a_complex_signature(x)`
6+
`tests.example_signature.a_complex_signature(x: [list](`list`)\[[C](`quartodoc.tests.example_signature.C`) \| [int](`int`) \| None\])`
7+
8+
## Parameters
9+
10+
| Name | Type | Description | Default |
11+
|--------|--------------------------------------------------------------------------------------|-----------------|------------|
12+
| `x` | [list](`list`)\[[C](`quartodoc.tests.example_signature.C`) \| [int](`int`) \| None\] | The x parameter | _required_ |
713
'''
814
# ---
915
# name: test_render_doc_class[embedded]

quartodoc/tests/example_signature.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ class C:
2929

3030

3131
def a_complex_signature(x: "list[C | int | None]"):
32-
...
32+
"""
33+
Parameters
34+
----------
35+
x:
36+
The x parameter
37+
"""

quartodoc/tests/test_renderers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_render_doc_module(snapshot, renderer, children):
113113

114114

115115
def test_render_annotations_complex(snapshot):
116-
renderer = MdRenderer(render_interlinks=True)
116+
renderer = MdRenderer(render_interlinks=True, show_signature_annotations=True)
117117
bp = blueprint(Auto(name="quartodoc.tests.example_signature.a_complex_signature"))
118118
res = renderer.render(bp)
119119

0 commit comments

Comments
 (0)