Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: descriptions no longer escape quotes inside code #375

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading