summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES2
-rw-r--r--sphinx/domains/std.py5
-rw-r--r--tests/root/markup.txt4
3 files changed, 11 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index 895f2143..51b3b5db 100644
--- a/CHANGES
+++ b/CHANGES
@@ -81,6 +81,8 @@ Features added
the order of documents before they are read by the environment.
* #1284: Program options documented with :rst:dir:`option` can now start with
``+``.
+* PR#291: The caption of :rst:dir:`code-block` is recognised as a title of ref
+ target. Thanks to Takeshi Komiya.
Bugs fixed
----------
diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py
index f14f65aa..a636299e 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 8a55e690..6ed396ac 100644
--- a/tests/root/markup.txt
+++ b/tests/root/markup.txt
@@ -142,6 +142,7 @@ Adding \n to test unescaping.
* :ref:`here <some-label>`
* :ref:`my-figure`
* :ref:`my-table`
+* :ref:`my-code-block`
* :doc:`subdir/includes`
* ``:download:`` is tested in includes.txt
* :option:`Python -c option <python -c>`
@@ -228,8 +229,11 @@ Version markup
Code blocks
-----------
+.. _my-code-block:
+
.. code-block:: ruby
:linenos:
+ :caption: my ruby code
def ruby?
false