To make plots referenceable, we need to move the reference from the "htmlonly" (or "latexonly") node to the actual figure node itself.
(app, document)
| 236 | |
| 237 | |
| 238 | def mark_plot_labels(app, document): |
| 239 | """ |
| 240 | To make plots referenceable, we need to move the reference from the |
| 241 | "htmlonly" (or "latexonly") node to the actual figure node itself. |
| 242 | """ |
| 243 | for name, explicit in document.nametypes.items(): |
| 244 | if not explicit: |
| 245 | continue |
| 246 | labelid = document.nameids[name] |
| 247 | if labelid is None: |
| 248 | continue |
| 249 | node = document.ids[labelid] |
| 250 | if node.tagname in ('html_only', 'latex_only'): |
| 251 | for n in node: |
| 252 | if n.tagname == 'figure': |
| 253 | sectname = name |
| 254 | for c in n: |
| 255 | if c.tagname == 'caption': |
| 256 | sectname = c.astext() |
| 257 | break |
| 258 | |
| 259 | node['ids'].remove(labelid) |
| 260 | node['names'].remove(name) |
| 261 | n['ids'].append(labelid) |
| 262 | n['names'].append(name) |
| 263 | document.settings.env.labels[name] = \ |
| 264 | document.settings.env.docname, labelid, sectname |
| 265 | break |
| 266 | |
| 267 | |
| 268 | class PlotDirective(Directive): |
nothing calls this directly
no test coverage detected
searching dependent graphs…