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

Space-indented code block loses indentation #259

Open
langfingaz opened this issue Apr 25, 2022 · 3 comments
Open

Space-indented code block loses indentation #259

langfingaz opened this issue Apr 25, 2022 · 3 comments
Assignees
Labels
kind/bug kind/upstream Issues with an upstream dependency.

Comments

@langfingaz
Copy link

Environment

  • Pydoc-Markdown Version: v4.6.3
  • Python Version: v3.10.4
  • Operating System: Arch Linux

I am using the cli interface:

pydoc-markdown -I src -m "${module}" --render-toc > "${dst}".md

Describe the bug

The first line of a code block (that is not surrounded by 3-ticks, but instead indented with 4 spaces) looses its indentation.

Here is a docstring of a python function:

Example:

    >>> url = URL('https://foo.bar')
    >>> print(url)
    https://foo.bar

:param url: Link to a remote file.

And here the generated markdown:

Example:

>>> url = URL('https://foo.bar')
    >>> print(url)
    https://foo.bar

**Arguments**:

- `url`: Link to a remote file.

Expected behavior

All 3 lines of the codeblock should keep their indendations.

Example:

    >>> url = URL('https://foo.bar')
    >>> print(url)
    https://foo.bar

**Arguments**:

- `url`: Link to a remote file.

Note:

The above bug does also occur when one does not use the > sign. So this is not the problem here ;)

@NiklasRosenstein
Copy link
Owner

Thanks for reporting this issue @langfingaz ! I've experienced this as well but have not found the time to fix it yet :( I might get around to fix it sometime later this week. If you dare to take a look at it yourself, you want to look at the code for the preprocessors (I'm not sure yet if this issue affects all preprocessors).

NiklasRosenstein added a commit that referenced this issue Apr 25, 2022
@NiklasRosenstein
Copy link
Owner

Hello @langfingaz ,

I did some investigation and it turns out this issue is coming from the docstring_parser module.

parsed_docstring = docstring_parser.parse(node.docstring.content, docstring_parser.DocstringStyle.REST)

if parsed_docstring.short_description:
lines.append(parsed_docstring.short_description)
lines.append("")
if parsed_docstring.long_description:
lines.append(parsed_docstring.long_description)
lines.append("")

The short_description is Example: and the long_description contains your code block, though unfortunately with the leading whitespace removed.

@NiklasRosenstein NiklasRosenstein added the kind/upstream Issues with an upstream dependency. label Nov 13, 2022
@FranzAtGithub
Copy link

Hey there :)

is this the same problem I get for the following docstring?

def foo(arg1: int, **kwargs: dict):
    """
    Args:
        arg1: The first argument.

            A longer description of the argument.
            There is even a table.

            | value  | description       |
            |--------|-------------------|
            | 1-10   | some text         |
            | 10-100 | some other text   |

        kwargs: Additional options.

            Longer description of possible kwargs.
            Recogniced keywords include:

            * kw_arg1 (bool): description of first keyword

                Longer description the keyword.

            *  kw_arg2 (int): description of the second keyword

                Longer description of the keyword.
                There is even a table:

                | value | description    |
                |-------|----------------|
                | 0     | no output      |
                | 1     | some output    |
                | 2     | lots of output |

            * kw_arg3 (bool): description of third keyword

                Longer description of the keyword.
                This includes a list:

                - nested list item
                - other nested list item
    """

I get the following md-code

**Arguments**:

- `arg1` - The first argument.
  
  A longer description of the argument.
  There is even a table.
  
  | value  | description       |
  |--------|-------------------|
  | 1-10   | some text         |
  | 10-100 | some other text   |
  
- `kwargs` - Additional options.
  
  Longer description of possible kwargs.
  Recogniced keywords include:
  
  * kw_arg1 (bool): description of first keyword
  
  Longer description the keyword.
  
  *  kw_arg2 (int): description of the second keyword
  
  Longer description of the keyword.
  There is even a table:
  
  | value | description    |
  |-------|----------------|
  | 0     | no output      |
  | 1     | some output    |
  | 2     | lots of output |
  
  * kw_arg3 (bool): description of third keyword
  
  Longer description of the keyword.
  This includes a list:
  
  - nested list item
  - other nested list item

The nested structures are not correctly indented.
I would appreciate a fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug kind/upstream Issues with an upstream dependency.
Projects
None yet
Development

No branches or pull requests

3 participants