|
1
|
|
|
""" |
|
2
|
|
|
SDoc |
|
3
|
|
|
|
|
4
|
|
|
Copyright 2016 Set Based IT Consultancy |
|
5
|
|
|
|
|
6
|
|
|
Licence MIT |
|
7
|
|
|
""" |
|
8
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
|
9
|
1 |
|
from sdoc.sdoc2 import node_store |
|
10
|
1 |
|
from sdoc.sdoc2.node.Node import Node |
|
11
|
1 |
|
from sdoc.sdoc2.node.HeadingNode import HeadingNode |
|
12
|
1 |
|
from sdoc.sdoc2.node.ParagraphNode import ParagraphNode |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
1 |
|
class TocNode(Node): |
|
16
|
|
|
""" |
|
17
|
|
|
SDoc2 node for table of contents. |
|
18
|
|
|
""" |
|
19
|
|
|
|
|
20
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
21
|
1 |
|
def __init__(self, options, argument): |
|
22
|
|
|
""" |
|
23
|
|
|
Object constructor. |
|
24
|
|
|
|
|
25
|
|
|
:param dict[str,str] options: The options of this table of contents. |
|
26
|
|
|
:param str argument: The argument of this TOC. |
|
27
|
|
|
""" |
|
28
|
|
|
super().__init__('toc', options, argument) |
|
29
|
|
|
|
|
30
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
31
|
1 |
|
def get_command(self): |
|
32
|
|
|
""" |
|
33
|
|
|
Returns the command of this node (i.e. toc). |
|
34
|
|
|
|
|
35
|
|
|
:rtype: str |
|
36
|
|
|
""" |
|
37
|
|
|
return 'toc' |
|
38
|
|
|
|
|
39
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
40
|
1 |
|
def is_block_command(self): |
|
41
|
|
|
""" |
|
42
|
|
|
Returns False. |
|
43
|
|
|
|
|
44
|
|
|
:rtype: bool |
|
45
|
|
|
""" |
|
46
|
|
|
return False |
|
47
|
|
|
|
|
48
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
49
|
1 |
|
def is_inline_command(self): |
|
50
|
|
|
""" |
|
51
|
|
|
Returns True. |
|
52
|
|
|
|
|
53
|
|
|
:rtype: bool |
|
54
|
|
|
""" |
|
55
|
|
|
return True |
|
56
|
|
|
|
|
57
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
58
|
1 |
|
def generate_toc(self): |
|
59
|
|
|
""" |
|
60
|
|
|
Generates the table of contents. |
|
61
|
|
|
""" |
|
62
|
|
|
self._options['ids'] = [] |
|
63
|
|
|
|
|
64
|
|
|
for key, node in node_store.nodes.items(): |
|
|
|
|
|
|
65
|
|
|
if not isinstance(node, ParagraphNode) and isinstance(node, HeadingNode): |
|
66
|
|
|
node.set_toc_id() |
|
67
|
|
|
|
|
68
|
|
|
data = {'id': node.get_option_value('id'), |
|
69
|
|
|
'arg': node.argument, |
|
70
|
|
|
'level': node.get_hierarchy_level(), |
|
71
|
|
|
'number': node.get_option_value('number')} |
|
72
|
|
|
|
|
73
|
|
|
self._options['ids'].append(data) |
|
74
|
|
|
|
|
75
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
|
76
|
|
|
node_store.register_inline_command('toc', TocNode) |
|
77
|
|
|
|