Anonymous committed 35dc7f6

#16: allow referring to figures without explicit text.

Comments (0)

Files changed (3)

   - Incompatible change: The "root" relation link (top left in the
     relbar) now points to the ``master_doc`` by default, no longer to a
     document called "index".  The old behavior, while useful in some
-    situations, was somewhat unexpected.
+    situations, was somewhat unexpected.  Override the "rootrellink"
+    block in the template to customize where it refers to.
   - The JavaScript search now searches for objects before searching in
     the full text.
   - Glossary entries are now automatically added to the index.
+  - Figures with captions can now be referred to like section titles,
+    using the ``:ref:`` role without an explicit link text.
 Release 0.4.2 (Jul 29, 2008)


   title being "Section to cross-reference".  This works just as well when
   section and reference are in different source files.
+  Automatic labels also work with figures: given ::
+     .. _my-figure:
+     .. figure:: whatever
+        Figure caption
+  a reference ``:ref:`my-figure``` would insert a reference to the figure with
+  link text "Figure caption".
 * Labels that aren't placed before a section title can still be referenced to,
   but you must give the link an explicit title, using this syntax: ``:ref:`Link
   title <label-name>```.


                           'other instance in %s' % self.doc2path(self.labels[name][0]),
             self.anonlabels[name] = docname, labelid
-            if not isinstance(node, nodes.section):
+            if node.tagname == 'section':
+                sectname = node[0].astext() # node[0] == title node
+            elif node.tagname == 'figure':
+                for n in node:
+                    if n.tagname == 'caption':
+                        sectname = n.astext()
+                        break
+                else:
+                    continue
+            else:
                 # anonymous-only labels
-            sectname = node[0].astext() # node[0] == title node
             self.labels[name] = docname, labelid, sectname
     def note_indexentries_from(self, docname, document):