authors file
[tiramisu.git] / doc / rst2man.py
1 #!/usr/bin/python
2 # unproudly borrowed from David Goodger's rst2html.py
3
4 """
5 A minimal front end to the Docutils Publisher, producing HTML.
6 """
7
8 try:
9     import locale
10     locale.setlocale(locale.LC_ALL, '')
11 except:
12     pass
13
14 from docutils.core import publish_cmdline, default_description
15 # ____________________________________________________________
16 from docutils import nodes, utils
17 from docutils.parsers.rst import roles
18 from docutils.writers import manpage
19
20 """
21 description of the new roles:
22
23 `:api:` : link to the code
24
25 - code.py becomes api/code.html
26 - code.Code.code_test becomes api/code.Code.code_test.html
27 - code.Code() becomes api/code.Code.html
28
29 `:doc:`a link to an internal file
30 example become example.html
31
32 ref: link with anchor as in an external file 
33
34 :ref:`toto#titi` becomes toto.html#titi 
35 """
36 from os.path import splitext
37
38 def api_reference_role(role, rawtext, text, lineno, inliner,
39                     options={}, content=[]):
40     basename = text
41     if "(" in text:
42         basename = text.split("(")[0]
43     if ".py" in text:
44         basename = splitext(text)[0]                
45     if "test_" in text:
46         refuri = "api/" + "tiramisu.test." + basename + '.html'
47     else:
48         refuri = "api/" + "tiramisu." + basename + '.html'
49     roles.set_classes(options)
50     node = nodes.reference(rawtext, utils.unescape(text), refuri=refuri,
51                         **options)
52     return [node], []
53
54 roles.register_local_role('api', api_reference_role)
55
56 def doc_reference_role(role, rawtext, text, lineno, inliner,
57                     options={}, content=[]):
58     refuri = text + '.html'
59     roles.set_classes(options)
60     node = nodes.reference(rawtext, utils.unescape(text), refuri=refuri,
61                         **options)
62     return [node], []
63
64 roles.register_local_role('doc', doc_reference_role)
65
66 def ref_reference_role(role, rawtext, text, lineno, inliner,
67                     options={}, content=[]):
68     fname, anchor = text.split('#')
69     refuri = fname + '.html#' + anchor 
70     roles.set_classes(options)
71     node = nodes.reference(rawtext, utils.unescape(anchor), refuri=refuri,
72                         **options)
73     return [node], []
74
75 roles.register_local_role('ref', ref_reference_role)
76
77 # ____________________________________________________________
78
79 description = ("Generates plain unix manual documents.  " + default_description)
80
81 publish_cmdline(writer=manpage.Writer(), description=description)
82