Extension adding images

24 views
Skip to first unread message

Jean Abou Samra

unread,
Feb 18, 2023, 5:21:12 PM2/18/23
to sphinx...@googlegroups.com

Hi,

I'm writing an extension that dynamically generates images. My problem is that when Sphinx finds the image nodes, it tries to find the images relative to the source. An absolute path is relative to the source directory, while a relative path is relative to the source file. (See sphinx/environment/collectors/asset.py.) In order not to pollute the source directory, I would naturally like to generate the images in the build directory.

I see that the sphinx.ext.graphviz extension does this by adding a node type that does not inherit from docutils.nodes.image, and implementing its own output functions for each builder. I'd like to avoid this if possible, as I won't be outputting the images differently than the image directives, just generating them on the fly.

I guess a possible way would be to generate a special node type while reading, then use a transform running after the DoctreeReadEvent (i.e., with priority > 880) to replace those nodes with normal image nodes.

Is there a better way?

Thanks,

Jean

signature.asc
Reply all
Reply to author
Forward
0 new messages