Allow Parsers to output images
I spent some time looking for parsers/macros to integrate GraphViz into a MoinMoin wiki. The most complete solution I found was GraphVizForMoin, which consists of a parser and an action.
The parser parses GraphViz graphs such as the following:
{{{#!GraphViz <layouter> <graph script> }}}
When the parser is invoked, it searches for an attachment with the name: graphviz-$graphname-$hash.png. If such an attachment is not found, the parser invokes GraphViz to draw the graph, and then attaches it to the page. Finially, it outputs the HTML to embed the attached image into the page.
The problem is that graphs pollute the attachments list; if you have a lot of them then it becomes difficult to find non-GraphViz graph attachments.
Attachments are also not deleted when a graph is edited, so they tend to accumulate until someone invokes the GraphVizCleanup action, which deletes any attachments with a name that matches the pattern above, for which a graph with a matching hash cannot be found.
So, back to the feature: it would be great if parsers could output images.
While writing up this feature request, a crazy idea occurred to me. It would be cool if parsers could specify the Internet media types that they can produce; a renderer could then negotiate with a parser to determine the optimum format for the parser to output its data.
Most parsers could continue to output text/x-moin-markup or text/html; a GraphViz parser could offer image/png, image/svg+xml; a MathML parser could offer text/x-mathml, image/svg+xml, image/png; a LilyPond parser could offer image/png, audio/ogg or audio/midi. This is probably stupidly over-engineered, but at the same time it is quite a neat idea.
Tips for improving that parser
Use MoinMoin.caching (not action.AttachFile) to store the rendered images, that solves the pollution of attachment list.
Also, I thought you could put image data directly into <img> somehow, but I can't currently find how. If you can't find it either, using some cachedimage action that just emits image data from Moin's cache could be useful (not only for GraphViz, also for Thumbnails etc.).
FYI, image data can be embedded directly with data URI scheme, however it quickly gets too large to be manageable.
arnica has some of this ideas implemented. arnica_slides.send_cache_file can be used for sending images from the cachearena to the browser. base64 encoded image data used in the <img> tag is not rendered by IE. text_x_arnica.create_thumbnail_and_webnail shows how I create thumbnails and webnails for arnica. I do use a prefix e.g.
webnail = 'tmp.webnail_%s.png' % fname thumbfile = 'tmp.thumbnail_%s.png' % fname
This makes it easier to remove them also on fs level.
If GraphViz has a prameter list please look at how I solved it using the parameter parser in text_x_arnica search for
settings = wikiutil.invoke_extension_function(request, macro_arnica, args)
-- ReimarBauer 2008-06-24 07:25:32