Initial checkin of RST to Wiki frontend
[docutils/kirr.git] / sandbox / tibs / pysource / rjhack.py
blob6046312acb5b99caeaf2a993a0f84f5aeda22bea
1 #!/usr/bin/env python
3 # Author: Richard Jones
4 # Contact: richard@users.sourceforge.net
5 # Revision: $Revision$
6 # Date: $Date$
7 # Copyright: This module has been placed in the public domain.
9 """
10 A front end to the Docutils Publisher, taking Python source and producing HTML.
11 """
13 import os, locale
14 try:
15 locale.setlocale(locale.LC_ALL, '')
16 except:
17 pass
19 import visit, transform
21 from docutils.parsers.rst import Parser
22 class SourceParser(Parser):
23 supported = ('pysource',)
24 settings_spec = (
25 'PySource Parser Options',
26 None,
27 (('Be verbose while parsing', ['--verbose-parse'],
28 {'action': 'store_true'}),
29 )) + Parser.settings_spec
30 def parse(self, filename, document):
31 if os.path.isdir(filename):
32 thing = visit.Package(document.settings, filename)
33 else:
34 thing = visit.Module(document.settings, filename)
35 process = transform.Process(with_groups=0, document=document)
36 process(thing)
38 from docutils.readers import Reader
39 class SourceReader(Reader):
40 def read(self, source, parser, settings):
41 self.source = source
42 if not self.parser:
43 self.parser = parser
44 self.settings = settings
45 # we want the input as the filename, not the file content
46 self.source.source.close()
47 self.input = self.source.source_path
48 self.parse()
49 return self.document
51 from docutils.core import publish_cmdline, default_description
52 description = ('Generates (X)HTML documents from Python sources. '
53 + default_description)
54 parser = SourceParser()
55 reader = SourceReader(parser, 'pysource')
56 publish_cmdline(reader=reader, parser=parser, writer_name='html',
57 description=description)