diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index f14f65aab..a636299ea 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -562,6 +562,11 @@ class StandardDomain(Domain): break else: continue + elif node.tagname == 'literal_block': + if 'caption' in node: + sectname = node['caption'] + else: + continue else: # anonymous-only labels continue diff --git a/tests/root/markup.txt b/tests/root/markup.txt index 8a55e6901..6ed396ac0 100644 --- a/tests/root/markup.txt +++ b/tests/root/markup.txt @@ -142,6 +142,7 @@ Adding \n to test unescaping. * :ref:`here ` * :ref:`my-figure` * :ref:`my-table` +* :ref:`my-code-block` * :doc:`subdir/includes` * ``:download:`` is tested in includes.txt * :option:`Python -c option ` @@ -228,8 +229,11 @@ Version markup Code blocks ----------- +.. _my-code-block: + .. code-block:: ruby :linenos: + :caption: my ruby code def ruby? false