From: David G. <go...@py...> - 2004-05-12 03:17:09
|
Pierre-Yves Delens wrote: > after a long end-user practice of Docutils/DocfFctory, and a > couple of tests of command Lines for Front-End tools , > I need to write small Python scripts. > Just making basically the same as command-lines, but in > batch instructions and parametrizable calls. > Example : > C:\Python\LTF\DocutilsTools\rst2html.py %f %p%n.html -o > iso-8859-1 > > Sorry for a newbie question : > Do you people have some sample code/snippets about this ? Take a look at rst2html.py. Notice that apart from a bit of environment setup, there's only three interesting statements: from docutils.core import publish_cmdline, default_description description = ('Generates (X)HTML documents from standalone ' 'reStructuredText sources. ' + default_description) publish_cmdline(writer_name='html', description=description) The first statement imports what we need. The second is only useful for command-line tools. The third statement calls Docutils, which does all the work. You probably want to use one of the other convenience functions in docutils.core, either publish_file, publish_string, or publish_parts. You can supply your parameters with "settings_overrides", mapping setting names to values: settings_overrides = {'output_encoding': 'iso-8859-1'} Take a look at docutils.examples.html_parts to see one convenience function in operation. Please feel free to ask more questions. -- David Goodger |