Skip to content

Commit

Permalink
fix: description list no longer escapes quotes inside code
Browse files Browse the repository at this point in the history
  • Loading branch information
machow committed Oct 11, 2024
1 parent 9edda48 commit 4824533
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
7 changes: 5 additions & 2 deletions quartodoc/renderers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ def escape(val: str):
return f"`{val}`"


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

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

# sanitize elements that can get interpreted as markdown links
# or citations
Expand Down
4 changes: 2 additions & 2 deletions quartodoc/renderers/md_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def to_definition_list(self):
name = self.name
anno = self.annotation
desc = sanitize(self.description, allow_markdown=True)
default = sanitize(str(self.default))
default = sanitize(str(self.default), escape_quotes=True)

part_name = (
Span(Strong(name), Attr(classes=["parameter-name"]))
Expand Down Expand Up @@ -219,7 +219,7 @@ def render_annotation(self, el: str) -> str:
el:
An object representing a type annotation.
"""
return sanitize(el)
return sanitize(el, escape_quotes=True)

@dispatch
def render_annotation(self, el: None) -> str:
Expand Down
32 changes: 16 additions & 16 deletions quartodoc/tests/__snapshots__/test_renderers.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -504,60 +504,60 @@
: A description.
'''
# ---
# name: test_render_numpydoc_section_return[name: int\n A description.]
# name: test_render_numpydoc_section_return[name: int\n A `"description"`.]
'''
Code
Parameters
---
name: int
A description.
A `"description"`.

Returns
---
name: int
A description.
A `"description"`.

Attributes
---
name: int
A description.
A `"description"`.

Default
# Parameters {.doc-section .doc-section-parameters}

| Name | Type | Description | Default |
|--------|--------|----------------|------------|
| name | | A description. | _required_ |
| Name | Type | Description | Default |
|--------|--------|--------------------|------------|
| name | | A `"description"`. | _required_ |

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

| Name | Type | Description |
|--------|--------|----------------|
| name | int | A description. |
| Name | Type | Description |
|--------|--------|--------------------|
| name | int | A `"description"`. |

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

| Name | Type | Description |
|--------|--------|----------------|
| name | int | A description. |
| Name | Type | Description |
|--------|--------|--------------------|
| name | int | A `"description"`. |

List
# Parameters {.doc-section .doc-section-parameters}

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

: A description.
: A `"description"`.

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

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

: A description.
: A `"description"`.

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

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

: A description.
: A `"description"`.
'''
# ---
2 changes: 1 addition & 1 deletion quartodoc/tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_render_doc_signature_name_alias_of_alias(snapshot, renderer):
@pytest.mark.parametrize(
"doc",
[
"""name: int\n A description.""",
"""name: int\n A `"description"`.""",
"""int\n A description.""",
],
)
Expand Down

0 comments on commit 4824533

Please sign in to comment.