On Thu, 2009-01-08 at 13:12 -0800, Eric wrote:
> I have ~400 svgs in my project that i'm trying to incorporate into my
> documentation that I've started writing with sphinx. The problem is
> that I can't get either the 0.5.1 or the latest code from hg to work,
> as it appears to generate an <img> tag, and at least in firefox I need
> to generate an <object> tag with the appropriate parameters.
> 
> I looked in the htmlwriter.py source, and it seems that code
> generation for an image node is passed off to the BaseTranslator,
> which in this case appears to be HTMLTranslator from
> docutils.writers.html4css1.
> 
> There was a discussion on this topic in the sphinx-dev list around the
> middle of November, but it doesn't appear a conclusion was reached.
> 
> So I'm trying to figure out if I should hack on the overall
> HTMLTranslator, and add in a special case of explicitly generating
> HTML when the image type is SVG (and passing it to the docutils
> HTMLTranslator otherwise), or perhaps create a pre-processing step
> that will convert SVGs into PNGs for inclusion.
> 

Hi Eric

I am interested in this also (but for audio files).

As I understand things, there are two parts here:

  #. defining custom 'object' and 'param' nodes, and subclassing the
     sphinx htmltranslator to output the correct html when it
     encounters these nodes
  #. writing custom directives, so that you can write .. svg::, .. mpg::
     in your rest source and the html builder will insert the
     appropriate 'object'/'param' nodes in the doctree


The first is more or less straightforward. I would suggest imitating the
docutils.nodes.bullet_list and docutils.nodes.listitem classes:

from docutils import nodes

class media(nodes.Sequential, nodes.Element):
    pass

class media_param(nodes.Part, nodes.Element):
    pass

Then you have a translator:

class EricsHTMLTranslator(sphinx.writers.html.HTMLTranslator):
    
   def visit_media(self, node):
       """code here"""

   def depart_media(self, node):
       """code here"""

   def visit_media_param(self, node):
       """code here"""

   def depart_media_param(self, node):
       """code here"""

There is a parameter in conf.py that you use to tell Sphinx to use your
custom translator rather than the builtin.

For the custom directive part, you are as wise as me - I've never done
that. Here is some prior art though:

http://www.bitbucket.org/birkenfeld/sphinx/src/tip/sphinx/ext/todo.py
http://svn.scipy.org/svn/numpy/trunk/doc/sphinxext/

I have to go out now, but I can make a start on this in maybe 2/3 hours
time - if you make any progress yourself, let me know!

All the best

G.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to