From: Leandro L. <ll...@gm...> - 2009-06-27 21:34:05
|
G. Milde, el 27 de junio a las 21:50 me escribiste: > In Docutils, any writer can add command-line-options/config settings, and > the config-file has writer-specific sections. The transform has access to > the 'document' object which has a 'document.settings' argument which is > already populated with the writer-dependend settings, e.g. since the last > commit, class SectNum(Transform) in parts.py contains writer-dependent > code (as LaTeX can generate section numbers):: > > def apply(self): > try: # leave section numbering to the writer? > numbering_by_writer = self.document.settings.use_latex_toc > except AttributeError: > numbering_by_writer = False > # ... > > You'll have to ask Georg about the situation in Sphinx -- conf.py has > just a comment telling that some settings are for LateX. Mmm, ok. I did some hacking to peek at self.document.settings when rendering using the HTML writer and the LaTeX writer and it seems that the first one has at least an option (stylesheet_path) that the other doesn't have. Checking the presence of that setting could do the trick, but I find it really dirty and fragile. =/ > > > Did you have a look how the graphviz extension does it? > > > It dos it wrong =) > > > I based my extension on that. It defines a new kind of node and add add > > new visit functions to render it. It generates the image file when > > rendering and use custom code to render (it writes it own HTML/LaTeX). > > But the image generation should be output-dependend too: there is no > vector format supported by both HTML and LaTeX (or you generate SVG first > and convert to EPS or PDF either in the tranform or with a latex wrapper > like `rubber`. It is output-dependent, that's why it's done at "visit-time" when the writer is know (I don't know how the Sphinx extension mechanism works in detail but I think it's done by the writer). > But still, doing this in a transforms seems the way to go. Yes, except that the writer-detection when transforming seems to be a little... weak. > You could also let the frontend add different tranforms (with a common > base class, of course) for the different output formats. I don't know how to do that. To be honest, I don't understand very well how transforming work either, even when I read some code and the PEP describing the design of Docutils =/ I guess I'll have to dig a little more. It's too sad that the project lacks some more documentation, because is really great, but it takes quite some time and effort to understand how it works. Thanks. -- Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/ ---------------------------------------------------------------------------- GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05) ---------------------------------------------------------------------------- Ya ni el cielo me quiere, ya ni la muerte me visita Ya ni el sol me calienta, ya ni el viento me acaricia |