Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External references are not resolved in TOC tree sidebar #4448

Open
mwoehlke opened this issue Jan 17, 2018 · 0 comments · May be fixed by #4475
Open

External references are not resolved in TOC tree sidebar #4448

mwoehlke opened this issue Jan 17, 2018 · 0 comments · May be fixed by #4475

Comments

@mwoehlke
Copy link
Contributor

Let's say I have a document like:

Title
=====

:doc:`some-page`
----------------

This is a section (but not the page title)
whose name is the same as,
and incidentally also a link to,
another piece of documentation.
I used ``:doc:`` here,
but at least ``:ref:``
|--| very possibly everything that uses ``XRefRole``
and the delayed resolution thereof |--|
shows the same problem.

In the body of the document, the reference title is resolved as expected. (Let's say for example that the document title is "Describe Some Page Here". Then, in the body, the heading appears as "Describe Some Page Here".) However, in the sidebar TOC, the heading appears as "some-page". That is, the TOC uses the raw text of the reference, rather than the resolved text. Besides looking ugly, this is confusing and almost certainly not intended, as it means that the heading text in the TOC and the document body are different.

On consideration, I suspect the problem is that the TOC is using astext on XRefRole nodes, which drops the external reference bits before they can be resolved. This may be a tricky fix, as I suspect that, besides tweaking the TOC to allowed delayed text resolution (which in itself may be non-trivial), all of StandardDomain.resolve_xref may need to sprout a mode to resolve text but not actually emit a reference (since in the TOC case, the reference we want is to the section that used the external reference in its title, and not what the external reference actually references).

This should be reproducible with the following index.rst::

Hello, World
============

:doc:`index`
------------

(Verified by making a comparable change to the index.rst of a sphinx-quickstart project.)

@tk0miya tk0miya added the markup label Jan 17, 2018
@tk0miya tk0miya modified the milestones: 1.8, 1.7 Jan 17, 2018
mwoehlke added a commit to mwoehlke/sphinx that referenced this issue Jan 21, 2018
Implement a new node that converts its contents to text (via astext()),
but delays doing so until the post-transform stage. Modify TOC
collection to use this. Modify TOC extraction to perform post-transforms
(specifically, reference resolution and resolution of the aforementioned
new nodes).

This fixes an annoying behavior where the use of an external reference
in a section name would use the raw reference text rather than the
resolved reference text in the sidebar table of contents, resulting in a
mismatch between the section title as it appears in said table of
contents and how it appears in the document body.

Fixes sphinx-doc#4448.
mwoehlke added a commit to mwoehlke/sphinx that referenced this issue Jan 21, 2018
Implement a new node that converts its contents to text (via astext()),
but delays doing so until the post-transform stage. Modify TOC
collection to use this. Modify TOC extraction to perform post-transforms
(specifically, reference resolution and resolution of the aforementioned
new nodes).

This fixes an annoying behavior where the use of an external reference
in a section name would use the raw reference text rather than the
resolved reference text in the sidebar table of contents, resulting in a
mismatch between the section title as it appears in said table of
contents and how it appears in the document body.

Fixes sphinx-doc#4448.
@mwoehlke mwoehlke linked a pull request Jan 21, 2018 that will close this issue
mwoehlke added a commit to mwoehlke/sphinx that referenced this issue Jan 22, 2018
Implement a new node that converts its contents to text (via astext()),
but delays doing so until the post-transform stage. Modify TOC
collection to use this. Modify TOC extraction to perform post-transforms
(specifically, reference resolution and resolution of the aforementioned
new nodes).

This fixes an annoying behavior where the use of an external reference
in a section name would use the raw reference text rather than the
resolved reference text in the sidebar table of contents, resulting in a
mismatch between the section title as it appears in said table of
contents and how it appears in the document body.

Fixes sphinx-doc#4448.
@tk0miya tk0miya modified the milestones: 1.7, 1.8 Feb 11, 2018
@tk0miya tk0miya modified the milestones: 1.8.0, some future version Aug 19, 2018
@AA-Turner AA-Turner added this to the some future version milestone Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants