1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
class CodeBlockDirective(Directive):
required_arguments = 0
optional_arguments = 1
has_content = True
option_spec = { 'filename': directives.unchanged }
def run(self):
node = []
filename = self.options.pop('filename', None)
if filename is not None:
node.append(nodes.Text("\n%s:" % filename))
else:
node.append(nodes.Text("\n"))
opt = {'classes' : []}
if len(self.arguments) != 0:
opt['classes'].append("brush: %s" % self.arguments[0])
node.append(nodes.literal_block(self.content, "\n".join(self.content), **opt))
return node
|