Search code examples
python-sphinxrestructuredtext

restructuredtext link to other rst file menu anchor


With this structure:

$ tree
.
├── Editors.rst
└── Tool_vim.rst

From Editor.rst file I want to do a link to the Tool_vim.rst file.

I get it with:

Follow install from :doc:`Tool_linux_install`

But on Tool_linux_install.rst I have a menu with .. contents:: and sections but I don't succeed to do a link to the vim chapter:

Follow install from :doc:`Tool_linux_install#vim`

But I get an error when compiling:

Tool_vim.rst:423: WARNING: unknown document: Tool_linux_install#vim

Solution

  • The :doc: role can be used to link to another document, but it does not support linking to a specific location within the document.

    Instead, use the :ref: role to link to a target defined by a label. It is possible to generate labels automatically with the sphinx.ext.autosectionlabel extension.

    See also https://github.com/sphinx-doc/sphinx/issues/6766.