Skip to content

0.4.2 MystRenderer renders default values incorrectly #28

Open
@johanseland

Description

@johanseland

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions