Skip to content

Commit 8d7ade2

Browse files
authored
Merge pull request #375 from machow/fix-inline-code-quotes
fix: description list no longer escapes quotes inside code
2 parents 9edda48 + 4824533 commit 8d7ade2

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

quartodoc/renderers/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ def escape(val: str):
1313
return f"`{val}`"
1414

1515

16-
def sanitize(val: str, allow_markdown=False):
16+
def sanitize(val: str, allow_markdown=False, escape_quotes=False):
1717
# sanitize common tokens that break tables
1818
res = val.replace("\n", " ").replace("|", "\\|")
1919

2020
# sanitize elements that get turned into smart quotes
21-
res = res.replace("'", r"\'").replace('"', r"\"")
21+
# this is to avoid defaults that are strings having their
22+
# quotes screwed up.
23+
if escape_quotes:
24+
res = res.replace("'", r"\'").replace('"', r"\"")
2225

2326
# sanitize elements that can get interpreted as markdown links
2427
# or citations

quartodoc/renderers/md_renderer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def to_definition_list(self):
6060
name = self.name
6161
anno = self.annotation
6262
desc = sanitize(self.description, allow_markdown=True)
63-
default = sanitize(str(self.default))
63+
default = sanitize(str(self.default), escape_quotes=True)
6464

6565
part_name = (
6666
Span(Strong(name), Attr(classes=["parameter-name"]))
@@ -219,7 +219,7 @@ def render_annotation(self, el: str) -> str:
219219
el:
220220
An object representing a type annotation.
221221
"""
222-
return sanitize(el)
222+
return sanitize(el, escape_quotes=True)
223223

224224
@dispatch
225225
def render_annotation(self, el: None) -> str:

quartodoc/tests/__snapshots__/test_renderers.ambr

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -504,60 +504,60 @@
504504
: A description.
505505
'''
506506
# ---
507-
# name: test_render_numpydoc_section_return[name: int\n A description.]
507+
# name: test_render_numpydoc_section_return[name: int\n A `"description"`.]
508508
'''
509509
Code
510510
Parameters
511511
---
512512
name: int
513-
A description.
513+
A `"description"`.
514514

515515
Returns
516516
---
517517
name: int
518-
A description.
518+
A `"description"`.
519519

520520
Attributes
521521
---
522522
name: int
523-
A description.
523+
A `"description"`.
524524

525525
Default
526526
# Parameters {.doc-section .doc-section-parameters}
527527

528-
| Name | Type | Description | Default |
529-
|--------|--------|----------------|------------|
530-
| name | | A description. | _required_ |
528+
| Name | Type | Description | Default |
529+
|--------|--------|--------------------|------------|
530+
| name | | A `"description"`. | _required_ |
531531

532532
# Returns {.doc-section .doc-section-returns}
533533

534-
| Name | Type | Description |
535-
|--------|--------|----------------|
536-
| name | int | A description. |
534+
| Name | Type | Description |
535+
|--------|--------|--------------------|
536+
| name | int | A `"description"`. |
537537

538538
# Attributes {.doc-section .doc-section-attributes}
539539

540-
| Name | Type | Description |
541-
|--------|--------|----------------|
542-
| name | int | A description. |
540+
| Name | Type | Description |
541+
|--------|--------|--------------------|
542+
| name | int | A `"description"`. |
543543

544544
List
545545
# Parameters {.doc-section .doc-section-parameters}
546546

547547
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} []{.parameter-annotation}</code>
548548

549-
: A description.
549+
: A `"description"`.
550550

551551
# Returns {.doc-section .doc-section-returns}
552552

553553
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation}</code>
554554

555-
: A description.
555+
: A `"description"`.
556556

557557
# Attributes {.doc-section .doc-section-attributes}
558558

559559
<code>[**name**]{.parameter-name} [:]{.parameter-annotation-sep} [int]{.parameter-annotation}</code>
560560

561-
: A description.
561+
: A `"description"`.
562562
'''
563563
# ---

quartodoc/tests/test_renderers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def test_render_doc_signature_name_alias_of_alias(snapshot, renderer):
223223
@pytest.mark.parametrize(
224224
"doc",
225225
[
226-
"""name: int\n A description.""",
226+
"""name: int\n A `"description"`.""",
227227
"""int\n A description.""",
228228
],
229229
)

0 commit comments

Comments
 (0)