2 # unproudly borrowed from David Goodger's rst2html.py
5 A minimal front end to the Docutils Publisher, producing HTML.
10 locale.setlocale(locale.LC_ALL, '')
14 from docutils.core import publish_cmdline, default_description
15 # ____________________________________________________________
16 from docutils import nodes, utils
17 from docutils.parsers.rst import roles
20 description of the new roles:
22 `:api:` : link to the code
24 - code.py becomes api/code.html
25 - code.Code.code_test becomes api/code.Code.code_test.html
26 - code.Code() becomes api/code.Code.html
28 `:doc:`a link to an internal file
29 example become example.html
31 ref: link with anchor as in an external file
33 :ref:`toto#titi` becomes toto.html#titi
35 from os.path import splitext
37 def api_reference_role(role, rawtext, text, lineno, inliner,
38 options={}, content=[]):
41 basename = text.split("(")[0]
43 basename = splitext(text)[0]
45 refuri = "api/" + "tiramisu.test." + basename + '.html'
47 refuri = "api/" + "tiramisu." + basename + '.html'
48 roles.set_classes(options)
49 node = nodes.reference(rawtext, utils.unescape(text), refuri=refuri,
53 roles.register_local_role('api', api_reference_role)
55 def doc_reference_role(role, rawtext, text, lineno, inliner,
56 options={}, content=[]):
57 refuri = text + '.html'
58 roles.set_classes(options)
59 node = nodes.reference(rawtext, utils.unescape(text), refuri=refuri,
63 roles.register_local_role('doc', doc_reference_role)
65 def ref_reference_role(role, rawtext, text, lineno, inliner,
66 options={}, content=[]):
67 fname, anchor = text.split('#')
68 refuri = fname + '.html#' + anchor
69 roles.set_classes(options)
70 node = nodes.reference(rawtext, utils.unescape(anchor), refuri=refuri,
74 roles.register_local_role('ref', ref_reference_role)
76 # ____________________________________________________________
78 description = ('Generates (X)HTML documents from standalone reStructuredText '
79 'sources. ' + default_description)
81 publish_cmdline(writer_name='html', description=description)