From 47ce40c4923b580585ce6a9d68d57fee48cf23c3 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 24 Sep 2008 15:36:34 +0000 Subject: [PATCH] #16: allow referring to figures without explicit text. --- CHANGES | 6 +++++- doc/markup/inline.rst | 11 +++++++++++ sphinx/environment.py | 12 ++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 8d0a38787..35b5a722e 100644 --- a/CHANGES +++ b/CHANGES @@ -9,7 +9,8 @@ New features added - 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. @@ -96,6 +97,9 @@ New features added - 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) ============================ diff --git a/doc/markup/inline.rst b/doc/markup/inline.rst index a2a9bfc89..60bfae4e0 100644 --- a/doc/markup/inline.rst +++ b/doc/markup/inline.rst @@ -205,6 +205,17 @@ to labels: 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 ```. diff --git a/sphinx/environment.py b/sphinx/environment.py index 08dcb8b31..90b4a36e0 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -658,10 +658,18 @@ class BuildEnvironment: 'other instance in %s' % self.doc2path(self.labels[name][0]), node.line) 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 continue - sectname = node[0].astext() # node[0] == title node self.labels[name] = docname, labelid, sectname def note_indexentries_from(self, docname, document):