source: sasview/calculatorview/docs/sphinx/_extensions/only_directives.py @ d8f3cd8

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since d8f3cd8 was 76f2d63, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on documentation

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#
2# A pair of directives for inserting content that will only appear in
3# either html or latex.
4#
5
6from docutils.nodes import Body, Element
7from docutils.parsers.rst import directives
8
9class only_base(Body, Element):
10    def dont_traverse(self, *args, **kwargs):
11        return []
12
13class html_only(only_base):
14    pass
15
16class latex_only(only_base):
17    pass
18
19def run(content, node_class, state, content_offset):
20    text = '\n'.join(content)
21    node = node_class(text)
22    state.nested_parse(content, content_offset, node)
23    return [node]
24
25def html_only_directive(name, arguments, options, content, lineno,
26                        content_offset, block_text, state, state_machine):
27    return run(content, html_only, state, content_offset)
28
29def latex_only_directive(name, arguments, options, content, lineno,
30                         content_offset, block_text, state, state_machine):
31    return run(content, latex_only, state, content_offset)
32
33def builder_inited(app):
34    if app.builder.name == 'html':
35        latex_only.traverse = only_base.dont_traverse
36    else:
37        html_only.traverse = only_base.dont_traverse
38
39def setup(app):
40    app.add_directive('htmlonly', html_only_directive, True, (0, 0, 0))
41    app.add_directive('latexonly', latex_only_directive, True, (0, 0, 0))
42    app.add_node(html_only)
43    app.add_node(latex_only)
44
45    # This will *really* never see the light of day As it turns out,
46    # this results in "broken" image nodes since they never get
47    # processed, so best not to do this.
48    # app.connect('builder-inited', builder_inited)
49
50    # Add visit/depart methods to HTML-Translator:
51    def visit_perform(self, node):
52        pass
53    def depart_perform(self, node):
54        pass
55    def visit_ignore(self, node):
56        node.children = []
57    def depart_ignore(self, node):
58        node.children = []
59
60    app.add_node(html_only, html=(visit_perform, depart_perform))
61    app.add_node(html_only, latex=(visit_ignore, depart_ignore))
62    app.add_node(latex_only, latex=(visit_perform, depart_perform))
63    app.add_node(latex_only, html=(visit_ignore, depart_ignore))
Note: See TracBrowser for help on using the repository browser.