@@ -276,8 +276,8 @@ def plot_directive(name, arguments, options, content, lineno,
276
276
# treated as relative to the root of the documentation tree. We need
277
277
# to support both methods here.
278
278
tmpdir = os .path .join ('build' , outdir )
279
+ tmpdir = os .path .abspath (tmpdir )
279
280
if sphinx_version < (0 , 6 ):
280
- tmpdir = os .path .abspath (tmpdir )
281
281
prefix = ''
282
282
else :
283
283
prefix = '/'
@@ -343,6 +343,36 @@ def plot_directive(name, arguments, options, content, lineno,
343
343
344
344
return []
345
345
346
+ def mark_plot_labels (app , document ):
347
+ """
348
+ To make plots referenceable, we need to move the reference from
349
+ the "htmlonly" (or "latexonly") node to the actual figure node
350
+ itself.
351
+ """
352
+ for name , explicit in document .nametypes .iteritems ():
353
+ if not explicit :
354
+ continue
355
+ labelid = document .nameids [name ]
356
+ if labelid is None :
357
+ continue
358
+ node = document .ids [labelid ]
359
+ if node .tagname in ('html_only' , 'latex_only' ):
360
+ for n in node :
361
+ if n .tagname == 'figure' :
362
+ sectname = name
363
+ for c in n :
364
+ if c .tagname == 'caption' :
365
+ sectname = c .astext ()
366
+ break
367
+
368
+ node ['ids' ].remove (labelid )
369
+ node ['names' ].remove (name )
370
+ n ['ids' ].append (labelid )
371
+ n ['names' ].append (name )
372
+ document .settings .env .labels [name ] = \
373
+ document .settings .env .docname , labelid , sectname
374
+ break
375
+
346
376
def setup (app ):
347
377
setup .app = app
348
378
setup .config = app .config
@@ -354,3 +384,4 @@ def setup(app):
354
384
['png' , 'hires.png' , 'pdf' ],
355
385
True )
356
386
387
+ app .connect ('doctree-read' , mark_plot_labels )
0 commit comments