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

Image/figure can not use :target: from other document #4351

Open
jessetan opened this issue Dec 28, 2017 · 6 comments
Open

Image/figure can not use :target: from other document #4351

jessetan opened this issue Dec 28, 2017 · 6 comments
Labels
markup type:enhancement enhance or introduce a new feature type:proposal a feature suggestion

Comments

@jessetan
Copy link
Contributor

Problem

Consider two files:

A.rst

.. _my-header:

This is my header
=================

.. figure:: image.png
    :target: my-header_

B.rst

.. figure:: image.png
    :target: my-header_

The figure in A.rst can be clicked to jump to the header in A.rst. Processing B.rst will print ERROR: Unknown target name: "my-header" and the figure will not be clickable.

It seems that it is a docutils limitation that the hyperlink target my-header is not searched for across files. Is it possible to add this in Sphinx (e.g. in patches.py) so that these internal targets are checked across all documents, just like using :ref: would?

A workaround is to use a URL in the target in B.rst:

.. figure:: image.png
    :target: A.html#my-header

But this is bad because it requires the author to know the exact output filename. It is also marked as an external link by docutils.

Environment info

  • OS: macOS 10.12.6
  • Python version: 2.7.10
  • Sphinx version: 1.5.6
@tk0miya tk0miya added type:enhancement enhance or introduce a new feature markup type:proposal a feature suggestion labels Dec 28, 2017
@tk0miya tk0miya added this to the 1.8 milestone Dec 28, 2017
@kassbohm
Copy link

@jessetan thank you.

@tk0miya
Copy link
Member

tk0miya commented Jun 1, 2018

I like this idea, but we have to consider before supporting this.
At present, Sphinx does not resolve a hyperlink reference across files.

.. _my-header:

This is my header
=================
In another file:
blah blah blah my-header_ blah blah blah

So it is a bit strange to support only the target option of figure and image directive.
We have to consider whole of notation.

@tk0miya tk0miya modified the milestones: 1.8.0, some future version Jul 18, 2018
@lcnittl
Copy link

lcnittl commented Sep 11, 2020

Would enabling sphinx.ext.autosectionlabel :ref: style targets be an option? Or directly use a :ref: option instead of :target:?

@darebgd
Copy link

darebgd commented Oct 24, 2021

Is there still no solution for this? I tried adding target to document B as in the OP, still the same.
Nowadays, ref: works across the different .rst files just fine but this was probably forgotten.
:target: still works with URLs only, which is lame and completely unlogical.

@amotl
Copy link

amotl commented Apr 11, 2022

Hi there,

@darebgd said:

:target: still works with URLs only.

We just ran into the same problem where we wanted to do something like

.. image:: startup.png
    :alt: A screenshot after startup
    :target: :ref:`getting-started`

However, that croaks with

(           index: line    5) broken    :ref:`getting-started` -

With kind regards,
Andreas.

@raphaelquast
Copy link

Hey, I just wanted to put a comment here to keep this issue running and to note that using :target: for internal targets in different files is still not working as expected.

Here's a link to my associated stackoverflow question that brought me here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
markup type:enhancement enhance or introduce a new feature type:proposal a feature suggestion
Projects
None yet
Development

No branches or pull requests

7 participants