opened
tk0miya
username_0
In [reStructuredText Markup Specification](http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#hyperlink-targets), "indirect hyperlink targets" is introduced.
It can define an alias of hyperlink targets.

It works fine with Sphinx. But, it could not refer them by `:ref:` role.

Example::
```
.. indirect hyperlink targets

.. _one: two_
.. _two: three_
.. _three:

.. figure:: logo.jpg

   caption of figure

Reference Names:
    one_, two_ and three_ work fine.

Reference role:
    :ref:`three` works fine. But :ref:`one` and :ref:`two` does not work.
```

It warns like following:
```
/Users/tkomiya/work/tmp/doc/index.rst:23: WARNING: undefined label: one (if the link has no caption the label must precede a section header)
/Users/tkomiya/work/tmp/doc/index.rst:23: WARNING: undefined label: two (if the link has no caption the label must precede a section header)
```
Could not refer "indirect hyperlink targets" by ref-role
issue
created
shimizukawa
username_1
I hope this patch solve the issue.
```diff
diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py
index 9fb16a9..dcf87e3 100644
--- a/sphinx/domains/std.py
+++ b/sphinx/domains/std.py
@@ -541,6 +541,8 @@ class StandardDomain(Domain):
                 env.warn_node('duplicate label %s, ' % name + 'other instance '
                               'in ' + env.doc2path(labels[name][0]), node)
             anonlabels[name] = docname, labelid
+            while node.tagname == 'target':
+                node = node.next_node(siblings=True)
             if node.tagname == 'section':
                 sectname = clean_astext(node[0])  # node[0] == title node
             elif node.tagname == 'figure':
```
comment
created
tk0miya
username_0
@username_1 It does not work following case:
```
.. _one: two_
.. _three:

.. figure:: logo.jpg

   caption of figure

Reference Names:
    one_, two_ and three_ work fine.

Reference role:
    :ref:`three` works fine. But :ref:`one` and :ref:`two` does not work.

.. _two: three_
```

`node.next_node()` is not good to resolve indirect hyperlink target. we have to trace the references recursively.
comment
created
tk0miya
username_0
Fixed at ad738a0.
comment
closed
tk0miya
username_0
issue