I understand the Sphinx supports markdown or .md files optionally, which works great for me for my supplimental documentation. What I am trying to do is use the autoclass
or automodule
tags in a markdown file.
Normally, in a .rst
file, if I do
.. autoclass:: my.module.SomeClass
:members:
it will automatically pull all the docstrings and create the documentation. Is it possible to use this in .md
files? At the moment, when I attempt to do so, the generated docs only contains .. autoclass:...
which is expected.
My conf.py
is
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "recommonmark"]
source_suffix = {
'.rst': 'restructuredtext',
'.txt': 'markdown',
'.md': 'markdown',
}
Because of read the docs compatibility, I did consider mkdocs, but it does not offer autodoc like capabilities. I am very open to any other library (does not have to be RTD compatible) in order to accomplish this.
To support Markdown-based documentation, Sphinx can use MyST-Parser. MyST-Parser is a Docutils bridge to markdown-it-py, a Python package for parsing the CommonMark Markdown flavor.
To support Markdown-based documentation, Sphinx can use MyST-Parser . MyST-Parser is a Docutils bridge to markdown-it-py, a Python package for parsing the CommonMark Markdown flavor.
That means that the module or the package must be in one of the directories on sys.path – adapt your sys.path in the configuration file accordingly. autodoc imports the modules to be documented. If any modules have side effects on import, these will be executed by autodoc when sphinx-build is run.
For Sphinx (actually, the Python interpreter that executes Sphinx) to find your module, it must be importable. That means that the module or the package must be in one of the directories on sys.path – adapt your sys.path in the configuration file accordingly.
In an automodule directive with the members option set, only module members whose __module__ attribute is equal to the module name as given to automodule will be documented. This is to prevent documentation of imported classes or functions. Set the imported-members option if you want to prevent this behavior and document all available members.
pip install myst-parser
Add this extension to your sphinx config:
extensions = [..., "myst_parser"]
Use {eval-rst}
with autoclass
role, within a ```
block
```{eval-rst} .. autoclass:: my.module.SomeClass :members: ```
This might require using AutoStructify of Recommonmark, namely the RST embedding feature.
With it, you'd add the following to your markdown:
```eval_rst
.. autoclass:: my.module.SomeClass
:members:
```
Adding the ".md" to the source_suffix
list worked for me:
In your conf.py:
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
source_suffix = ['.rst', '.md']
I am using sphinx 2.1.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With