sphinx-doc / sphinx-doc/sphinx

Cross-reference including penultimate parts of target

Open
#8,167 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

domains:py type:enhancement
Dominant language
Python
Stars
8k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Is your feature request related to a problem? Please describe.
We can generate lovely hyperlinked documentation with sphinx, for instance for some particular max python method (appearance in built docs follows after the line of code):

:py:meth:`mylongpackagename.myimportantmodule.longclassname.max`
    .. mylongpackagename.myimportantmodule.longclassname.max() 

Using tilde (~), we can hide everything but the final part of the target:

:py:meth:`~mylongpackagename.myimportantmodule.longclassname.max`
    .. max() 

But often it would be nice to include the penultimate part of the target, in order to be give context about where the method is used, without cluttering the documentation with unnecessarily long code:

    .. longclassname.max() 

While I would be happy with only including the penultimate and ultimate part of the target, it would be nice to have the option to include more as well:

Describe the solution you'd like
The first solution that comes to mind is to use multiple tildes (~~) to indicate the number of parts to include from the end. The example above would be achieved with

:py:meth:`~~mylongpackagename.myimportantmodule.longclassname.max`
    .. longclassname.max()

Describe alternatives you've considered
Alternatively, one could prefix the tilde with the number of wanted parts:

:py:meth:`2~mylongpackagename.myimportantmodule.longclassname.max`
    .. longclassname.max()
:py:meth:`3~mylongpackagename.myimportantmodule.longclassname.max`
    .. myimportantmodule.longclassname.max()

As far as I can see in the documentation, this does not already exist. What do you think?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Sphinx's cross-referencing syntax documentation and the py:meth role described in the issue. Determine how shortened targets are currently handled, then define and document the accepted syntax for retaining multiple trailing parts. Done should include the requested behavior and coverage for the proposed forms.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.