Revision: 7998 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7998&view=rev Author: mdboom Date: 2009-12-01 19:01:45 +0000 (Tue, 01 Dec 2009)
Log Message: ----------- [2906157] Let sphinx reference matplotlib-created plots (backport) Modified Paths: -------------- branches/v0_99_maint/lib/matplotlib/sphinxext/plot_directive.py Modified: branches/v0_99_maint/lib/matplotlib/sphinxext/plot_directive.py =================================================================== --- branches/v0_99_maint/lib/matplotlib/sphinxext/plot_directive.py 2009-12-01 18:58:49 UTC (rev 7997) +++ branches/v0_99_maint/lib/matplotlib/sphinxext/plot_directive.py 2009-12-01 19:01:45 UTC (rev 7998) @@ -276,8 +276,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 = '/' @@ -343,6 +343,36 @@ return [] +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 @@ -354,3 +384,4 @@ ['png', 'hires.png', 'pdf'], 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 Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins