2

I am building code documentation with Sphinx.

Let's say at some point there is documentation for a class foobar.Foo, i.e. something like

.. autoclass:: foobar.Foo
   :members:

At some other place, I have a code example (included using literalinclude), which contains the line

foo = foobar.Foo()

Is there a way to make the foobar.Foo in the code example automatically link to the documentation of that class like when using

:class:`foobar.Foo`

in normal text?

luator
  • 4,769
  • 3
  • 30
  • 51
  • No. literalinclude does not parse code. – Steve Piercy Oct 04 '20 at 07:59
  • @StevePiercy Would there be an alternative to `literalinclude` where this is possible? – luator Oct 05 '20 at 07:11
  • could it be that you're looking for [viewcode](https://www.sphinx-doc.org/en/master/usage/extensions/viewcode.html)? – kuropan Nov 12 '20 at 15:23
  • @kuropan That is going in the right direction but if I understand the documentation correctly, this generates separate pages for the files? What I am looking for is a solution where I can embed short code snippets in a page with text around it (like with `literalinclude` or `code-block`). – luator Nov 13 '20 at 08:12
  • 1
    @luator Yeah, I'm very much looking for the same thing and am also not yet sure if viewcode is doing that (I read contradictory things about it). We could also take a look at the ``setup.py`` of sklearn, because they seem to have exactly this feature enabled: [example](https://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html#) – kuropan Nov 13 '20 at 10:32

0 Answers0