Revision: 7997
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7997&view=rev
Author: mdboom
Date: 2009-12-01 18:58:49 +0000 (Tue, 01 Dec 2009)
Log Message:
-----------
[2906157] Let sphinx reference matplotlib-created plots
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py
Modified: trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py 2009-12-01
15:17:21 UTC (rev 7996)
+++ trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py 2009-12-01
18:58:49 UTC (rev 7997)
@@ -308,8 +308,8 @@
# treated as relative to the root of the documentation tree. We
# need to support both methods here.
tmpdir = os.path.join('build', outdir)
+ tmpdir = os.path.abspath(tmpdir)
if sphinx_version < (0, 6):
- tmpdir = os.path.abspath(tmpdir)
prefix = ''
else:
prefix = '/'
@@ -421,6 +421,36 @@
return _plot_directive(plot_path, 'inline', None, plot_code, '',
options,
state_machine)
+def mark_plot_labels(app, document):
+ """
+ To make plots referenceable, we need to move the reference from
+ the "htmlonly" (or "latexonly") node to the actual figure node
+ itself.
+ """
+ for name, explicit in document.nametypes.iteritems():
+ if not explicit:
+ continue
+ labelid = document.nameids[name]
+ if labelid is None:
+ continue
+ node = document.ids[labelid]
+ if node.tagname in ('html_only', 'latex_only'):
+ for n in node:
+ if n.tagname == 'figure':
+ sectname = name
+ for c in n:
+ if c.tagname == 'caption':
+ sectname = c.astext()
+ break
+
+ node['ids'].remove(labelid)
+ node['names'].remove(name)
+ n['ids'].append(labelid)
+ n['names'].append(name)
+ document.settings.env.labels[name] = \
+ document.settings.env.docname, labelid, sectname
+ break
+
def setup(app):
setup.app = app
setup.config = app.config
@@ -441,3 +471,4 @@
[('png', 80), ('hires.png', 200), ('pdf', 50)],
True)
+ app.connect('doctree-read', mark_plot_labels)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins