diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 6b94b3000..1184672b2 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -574,6 +574,12 @@ class StandardDomain(Domain): break else: continue + elif node.traverse(addnodes.toctree): + n = node.traverse(addnodes.toctree)[0] + if n.get('caption'): + sectname = n['caption'] + else: + continue else: # anonymous-only labels continue diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 931d95aaa..4e4c117fc 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -487,6 +487,10 @@ def get_figtype(node): from docutils import nodes if isinstance(node, nodes.figure): return 'figure' + elif isinstance(node, nodes.image) and isinstance(node.parent, nodes.figure): + # bare image node is not supported because it doesn't have caption and + # no-caption-target isn't a numbered figure. + return 'figure' elif isinstance(node, nodes.table): return 'table' elif isinstance(node, nodes.container): diff --git a/tests/root/contents.txt b/tests/root/contents.txt index dbc6f5be1..bee6a896e 100644 --- a/tests/root/contents.txt +++ b/tests/root/contents.txt @@ -10,6 +10,8 @@ Contents: .. toctree:: :maxdepth: 2 :numbered: + :caption: Table of Contents + :name: mastertoc extapi images @@ -54,3 +56,9 @@ This used to crash: .. toctree:: :hidden: + +Test for issue #1700 +==================== + +:ref:`mastertoc` + diff --git a/tests/root/markup.txt b/tests/root/markup.txt index 63afc3083..de1bcaecb 100644 --- a/tests/root/markup.txt +++ b/tests/root/markup.txt @@ -141,11 +141,17 @@ Adding \n to test unescaping. * :ref:`admonition-section` * :ref:`here ` * :ref:`my-figure` +* :ref:`my-figure-name` * :ref:`my-table` +* :ref:`my-table-name` * :ref:`my-code-block` +* :ref:`my-code-block-name` * :numref:`my-figure` +* :numref:`my-figure-name` * :numref:`my-table` +* :numref:`my-table-name` * :numref:`my-code-block` +* :numref:`my-code-block-name` * :doc:`subdir/includes` * ``:download:`` is tested in includes.txt * :option:`Python -c option ` @@ -172,6 +178,7 @@ Tables .. _my-table: .. table:: my table + :name: my-table-name +----+----------------+----+ | 1 | * Block elems | x | @@ -199,6 +206,7 @@ Figures .. _my-figure: .. figure:: img.png + :name: my-figure-name My caption of the figure @@ -237,6 +245,7 @@ Code blocks .. code-block:: ruby :linenos: :caption: my ruby code + :name: my-code-block-name def ruby? false