This repository was archived by the owner on Apr 16, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathconfigurationblock.py
107 lines (83 loc) · 3.04 KB
/
configurationblock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# -*- coding: utf-8 -*-
"""
:copyright: (c) 2010-2012 Fabien Potencier
:license: MIT, see LICENSE for more details.
"""
from docutils.parsers.rst import Directive, directives
from docutils import nodes
class configurationblock(nodes.General, nodes.Element):
pass
class ConfigurationBlock(Directive):
has_content = True
required_arguments = 0
optional_arguments = 0
final_argument_whitespace = True
option_spec = {}
formats = {
'html': 'HTML',
'xml': 'XML',
'php': 'PHP',
'yaml': 'YAML',
'jinja': 'Twig',
'html+jinja': 'Twig',
'jinja+html': 'Twig',
'twig': 'Twig',
'html+twig': 'Twig',
'twig+html': 'Twig',
'php+html': 'PHP',
'html+php': 'PHP',
'ini': 'INI',
'markdown': 'Markdown',
'php-annotations': 'Annotations',
'php-attributes': 'Attributes',
'php-standalone': 'Standalone Use',
'php-symfony': 'Framework Use',
'rst': 'reStructuredText',
'varnish2': 'Varnish 2',
'varnish3': 'Varnish 3',
'varnish4': 'Varnish 4',
'blackfire': 'Blackfire',
'bash': 'Bash',
'apache': 'Apache',
'nginx': 'Nginx',
'terminal': 'Terminal',
'env': '.env',
}
def run(self):
env = self.state.document.settings.env
node = nodes.Element()
node.document = self.state.document
self.state.nested_parse(self.content, self.content_offset, node)
entries = []
for i, child in enumerate(node):
if isinstance(child, nodes.literal_block):
# add a title (the language name) before each block
#targetid = "configuration-block-%d" % env.new_serialno('configuration-block')
#targetnode = nodes.target('', '', ids=[targetid])
#targetnode.append(child)
innernode = nodes.emphasis(self.formats[child['language']],
self.formats[child['language']])
para = nodes.paragraph()
para += [innernode, child]
entry = nodes.list_item('')
entry.append(para)
entries.append(entry)
resultnode = configurationblock()
resultnode.append(nodes.bullet_list('', *entries))
return [resultnode]
def visit_configurationblock_html(self, node):
self.body.append(self.starttag(node, 'div', CLASS='configuration-block'))
def depart_configurationblock_html(self, node):
self.body.append('</div>\n')
def visit_configurationblock_latex(self, node):
pass
def depart_configurationblock_latex(self, node):
pass
def setup(app):
app.add_node(configurationblock,
html=(visit_configurationblock_html,
depart_configurationblock_html),
latex=(visit_configurationblock_latex,
depart_configurationblock_latex))
app.add_directive('configuration-block', ConfigurationBlock)
return {'parallel_read_safe': True}