liran-funaro / sphinx-markdown-builder

A Sphinx extension to add markdown generation support.
https://pypi.org/project/sphinx-markdown-builder
MIT License
32 stars 14 forks source link

Incorrectly processes single-item lists #1

Closed remiconnesson closed 11 months ago

remiconnesson commented 11 months ago

When processing a list with a single item sphinx-markdown-builder will not add a list marker in front of the single item.

This bug does not happen when a list has more than one item.

Steps to reproduce the behavior:

Try to document a docstring with only one parameter listed. This will result in incorrect markdown.

for example:

### func.func1(param1: int)

This is a function with a single parameter.

* **Parameters**
  **param1** – This is a single parameter.

A minimal reproduction is available here:

https://github.com/remiconnesson/repro-sphinx-md-list-with-single-item/tree/main


detailed reproduction

files

.
├── docs/
│   ├── conf.py
│   └── index.rst
├── src/
│   └── func.py
└── requirements.txt

ROOT_DIR = Path(file).parents[1] sys.path.append(str(ROOT_DIR / 'src'))

extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.autosummary',

'sphinx.ext.napoleon',

'sphinxarg.ext',
"sphinx_markdown_builder",

]

source_suffix = ['.rst']


## steps

1. `pip install -r requirements`

2. `cd docs && sphinx-build -M markdown build`

3. `cat docs/build/markdown/index.md`

this will result in a file that is not valid markdown. (the list marker is missing)

```markdown
### func.func1(param1: int)

This is a function with a single parameter.

* **Parameters**
  **param1** – This is a single parameter.
  1. but the actual source file is src/func.py
def func1(param1: int):
   """This is a function with a single parameter.

   :param param1: This is a single parameter.
   """
   pass
liran-funaro commented 11 months ago

Thanks for taking the time to submit this issue.

It seems that it is not a bug, but the intentional behavior of sphinx. The same behavior occurs for all output formats.

I think it looks weird here because I didn't add a colon (":") after the "Parameters" title. If I'll add it, the output code would be as follows:

### func.func1(param1: int)

This is a function with a single parameter.

* **Parameters:**
  **param1** – This is a single parameter.

And it would look like this:

func.func1(param1: int)

This is a function with a single parameter.

Will this solution be helpful for you?

remiconnesson commented 11 months ago

Thanks for taking the time to submit this issue.

It seems that it is not a bug, but the intentional behavior of sphinx. The same behavior occurs for all output formats.

I think it looks weird here because I didn't add a colon (":") after the "Parameters" title. If I'll add it, the output code would be as follows:

### func.func1(param1: int)

This is a function with a single parameter.

* **Parameters:**
  **param1** – This is a single parameter.

And it would look like this:

func.func1(param1: int)

This is a function with a single parameter.

  • Parameters: param1 – This is a single parameter.

Will this solution be helpful for you?

Yes that would totally make sense :)

Thank you very much

liran-funaro commented 11 months ago

@remiconnesson Please update to the latest version. If the solution works for you, please close this issue.

remiconnesson commented 11 months ago

Perfect thank you!