I am documenting a python module in Sphinx. I have a source code file full of examples of the use of my module. I'd like to reference this file. It is too long to inline as continuous code. Is there a way to create a link to the full source file, formatted in a code-friendly way (ie literal or with line numbers)?
Thanks.
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.
The toctree directive is the central element. Note. Simple “inclusion” of one file in another can be done with the include directive. Note. To create table of contents for current document (.
If I get the question right, you want a link from your documentation to the original source file. You can do this by adding the sphinx.ext.viewcode
extension to your conf file (under extensions entry). This will create a "source" link for every header of a class, method, function, etc. Clicking the link will open the original file highlighting the clicked item. More explanation here
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