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
|
from docutils import nodes
from docutils.parsers.rst import Directive
class my_figure(nodes.figure):
pass
def visit_my_figure(self, node):
self.visit_figure(node)
def depart_my_figure(self, node):
self.depart_figure(node)
class MyFigure(Directive):
required_arguments = 1
has_content = True
def run(self):
figure_node = my_figure()
figure_node += nodes.image(uri=self.arguments[0])
figure_node += nodes.caption(text=''.join(self.content))
return [figure_node]
class numbered_text(nodes.Element):
pass
def visit_numbered_text(self, node):
self.body.append(self.starttag(node, 'div'))
self.add_fignumber(node)
self.body.append(node['title'])
self.body.append('</div>')
raise nodes.SkipNode
def get_title(node):
return node['title']
class NumberedText(Directive):
required_arguments = 1
final_argument_whitespace = True
def run(self):
return [numbered_text(title=self.arguments[0])]
def setup(app):
# my-figure
app.add_enumerable_node(my_figure, 'figure',
html=(visit_my_figure, depart_my_figure))
app.add_directive('my-figure', MyFigure)
# numbered_label
app.add_enumerable_node(numbered_text, 'original', get_title,
html=(visit_numbered_text, None))
app.add_directive('numbered-text', NumberedText)
app.config.numfig_format.setdefault('original', 'No.%s')
|