#16: allow referring to figures without explicit text.

This commit is contained in:
Georg Brandl 2008-09-24 15:36:34 +00:00
parent 20e989e19b
commit 47ce40c492
3 changed files with 26 additions and 3 deletions

View File

@ -9,7 +9,8 @@ New features added
- Incompatible change: The "root" relation link (top left in the - Incompatible change: The "root" relation link (top left in the
relbar) now points to the ``master_doc`` by default, no longer to a relbar) now points to the ``master_doc`` by default, no longer to a
document called "index". The old behavior, while useful in some 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 JavaScript search now searches for objects before searching in
the full text. the full text.
@ -96,6 +97,9 @@ New features added
- Glossary entries are now automatically added to the index. - 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) Release 0.4.2 (Jul 29, 2008)
============================ ============================

View File

@ -205,6 +205,17 @@ to labels:
title being "Section to cross-reference". This works just as well when title being "Section to cross-reference". This works just as well when
section and reference are in different source files. 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, * 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 but you must give the link an explicit title, using this syntax: ``:ref:`Link
title <label-name>```. title <label-name>```.

View File

@ -658,10 +658,18 @@ class BuildEnvironment:
'other instance in %s' % self.doc2path(self.labels[name][0]), 'other instance in %s' % self.doc2path(self.labels[name][0]),
node.line) node.line)
self.anonlabels[name] = docname, labelid 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 # anonymous-only labels
continue continue
sectname = node[0].astext() # node[0] == title node
self.labels[name] = docname, labelid, sectname self.labels[name] = docname, labelid, sectname
def note_indexentries_from(self, docname, document): def note_indexentries_from(self, docname, document):