Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refering to a (sphynx autodoc generated) python method (:py:meth:) from a myst-parser markdown file?

I have a section of sphinx doc generated by the sphinx :autoclass: directive

I want to refer to the (docstring) generated doc of a python method from a mystmarkdown file

From

I have tried this:

{:py:meth:}the_module.TheClass.the_method

but the generated doc has no hyperlink, only highlighted the_module.TheClass.the_method

like image 995
Max L. Avatar asked Oct 23 '25 07:10

Max L.


1 Answers

According to the MyST documentation, you would use the following syntax.

Using the role

{py:meth}`the_module.TheClass.the_method`

If you want to give a shorter name to the method, you have two options.

{py:meth}`the_method <the_module.TheClass.the_method>`
{py:meth}`~the_module.TheClass.the_method`

See Sphinx documentation on [Target specification](https://www.sphinx-doc.org/en/master/usage/domains/python.html#target-specification

Note that the py: in the start is optional.

Using the Markdown syntax

[the_method](the_module.TheClass.the_method)

Difference of the two syntaxes

The advantage of using the {meth}`foo` (role syntax) is that it keeps the semantic meaning of the link, and applies the required CSS to differentiate it from a regular link.

like image 153
Steve Piercy Avatar answered Oct 25 '25 10:10

Steve Piercy