Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linking to source code file in sphinx

Tags:

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.

like image 473
Eli S Avatar asked Nov 18 '13 23:11

Eli S


People also ask

Does Sphinx support markdown?

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.

What is Toctree?

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 (.


1 Answers

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

like image 146
A. B Avatar answered Oct 07 '22 00:10

A. B