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

0.4.2 MystRenderer renders default values incorrectly #28

Open
johanseland opened this issue Jul 18, 2023 · 0 comments
Open

0.4.2 MystRenderer renders default values incorrectly #28

johanseland opened this issue Jul 18, 2023 · 0 comments

Comments

@johanseland
Copy link

I am using sphinx2-autodoc2 to generate documentation for a Python class like this:

class Foo:
"""This is class foo"""

  bar = 42
  """The bar of foo"""

When running this through Sphinx-autodoc2 it creates Foo.md with the following relevant parts:

````{py:attribute} bar
:canonical: Foo.bar
:value: >
   1

```{autodoc2-docstring} Foo.bar
```
````

Notice the ">" and extra linebreak!

This renders rather ugly:
image

What is wanted is more akin to:

image

This is caused by the following from myst_.py:

if isinstance(value, str):
if len(value.splitlines()) == 1:
if len(value) > 100:
value = value[:100] + "..."
yield ":value: >" # use > to ensure its understood as a string
yield f" {value!r}"
else:
yield ":value: <Multiline-String>"
# TODO in sphinx-autoapi, they made a code block inside a details/summary HTML
else:
value = str(value).replace("\n", " ")
if len(value) > 100:
value = value[:100] + "..."
yield ":value: >"
yield f" {value}"

I'm not sure what the intent of the comment: # use > to ensure its understood as a string is supposed to mean.

The rst-renderer is not up to such shenigans:

if isinstance(value, str):
if len(value.splitlines()) == 1:
if len(value) > 100:
value = value[:100] + "..."
yield f" :value: {value!r}"
else:
yield " :value: <Multiline-String>"
# TODO in sphinx-autoapi, they made a code block inside a details/summary HTML
else:
value = str(value).replace("\n", " ")
if len(value) > 100:
value = value[:100] + "..."
yield f" :value: {value}"

I can make a PR with a proposed fix, are you still accepting those?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant