click-contrib / sphinx-click

A Sphinx plugin to automatically document click-based applications
MIT License
212 stars 57 forks source link

Support myst-parser #127

Open LecrisUT opened 9 months ago

LecrisUT commented 9 months ago

Currently the generated code is specific for rst documents such that the following does not work:

```{click} module:parser
:prog: hello-world
There is a workaround using:
````markdown
```{eval-rst}
.. click:: [scikit_build_core.cli.main:skbuild](module:parser)
   :prog: hello-world

However it would be good to have built-in to use the appropriate parser (i.e. rst) for the generated code.
stephenfin commented 3 months ago

fwiw, I looked at this today. It seems myst_parser does not seem to be happy with our use of sphinx.utils.nodes.nested_parse_with_titles. That should return a load of docutils nodes but the output is off.

Here's an example using reStructuredText:

Screen Shot 2024-04-06 at 10 28 29

and here's the equivalent using Markdown:

Screen Shot 2024-04-06 at 10 28 17

You can see that all the directives are outputted in raw form rather than being processed and nested as expected. I'm not sure how you'd go about fixing this, tbh.

stephenfin commented 3 months ago

If anyone is interested in fixing this, there's a minimal reproducer here.

LecrisUT commented 3 months ago

Yes, and I think that's expected, I've used something similar when messing around with autodoc extensions. For that case, it was fine because the nature of the docstring (rst or md fomat) is known by the user, amd they could fine-tune and select the appropriate parser with eval-rst.

The issue here are:

I think the only relevant references here is sphinx-autodoc2, e.g. see their approach here (navigate to the concrete implementations for myst and rst)