From: Leandro L. <ll...@gm...> - 2009-06-26 01:07:45
|
Leandro Lucarella, el 23 de junio a las 22:15 me escribiste: > Hi. > > I'm trying to improve the aafig_ Sphinx extension to use an image node > to output the aafigure_ generated image, so it can take advantage of the > extra image options (like height, width, etc.) and any bug-fixes. > Consistency is a nice advantage too. > > The problem is I'm getting an error when doing that. I'm sorry about the > cross-posting, but I don't know if the error is docutils or Sphinx > related. > > What I'm doing is something like:: > > def aafig_node_html_visit(self, node): > # generate the aafigure image > node.img = nodes.image() > # copy aafig attributes to the image node > self.visit_image(node.img) > raise nodes.SkipNode > > def aafig_node_html_depart(self, node): > self.depart_image(node.img) > raise nodes.SkipNode I took a different approach trying to do this. I saw how the figure directive is implemented and I decided to give that way a try. It's all almost working, but I have a small problem and I don't know how to fix it, if it's even possible without modifying docutils/Sphinx. What I'm doing is inherit my Aafig directive from docutil's Image and create an image in a similar way as the Figure directive does. This is the simplified code: class Aafig(directives.images.Image): def run(self): self.arguments = ['???'] # (1) (image_node,) = directives.images.Image.run(self) aafig_node = aafig(text, image_node, **aafig_options) return [aafig_node] def aafig_html_visit(self, node): # generate the image image_node = node[0] image_node['src'] = image_file_path # (2) My problem is, I don't know the file name of the image at point (1) because the image file name depends on the builder used to render the document. As things are now, I have to add the argument to the directive because the Image directive expects one argument, but I don't know what's the image file name until (2). I can't come up with a format-independent image file name because I have to store the generated image in the build directory, which is builder-dependent. Is there any way to do what I want? If not, will you be willing to accept patches to allow this? I think other extensions can benefit from this, like the official graphviz extension (in which I based the aafig extension) and my other graphviz-based extension: mscgen. TIA. -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) |