1
|
1 |
|
from typing import Dict, Optional |
2
|
|
|
|
3
|
1 |
|
from cleo.io.io import IO |
4
|
|
|
|
5
|
1 |
|
from sdoc.sdoc2.node.Node import Node |
6
|
1 |
|
from sdoc.sdoc2.NodeStore import NodeStore |
7
|
|
|
|
8
|
|
|
|
9
|
1 |
View Code Duplication |
class IconNode(Node): |
|
|
|
|
10
|
|
|
""" |
11
|
|
|
Node for icons (i.e. small inline images). |
12
|
|
|
""" |
13
|
|
|
|
14
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
15
|
1 |
|
_definitions = {} |
16
|
|
|
""" |
17
|
|
|
The icon definitions. Map from ion name ot attributes. |
18
|
|
|
|
19
|
|
|
:type: dict[str,dict[str,str]] |
20
|
|
|
""" |
21
|
|
|
|
22
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
23
|
1 |
|
def __init__(self, io: IO, options: Dict[str, str], argument: str): |
24
|
|
|
""" |
25
|
|
|
Object constructor. |
26
|
|
|
|
27
|
|
|
:param OutputStyle io: The IO object. |
28
|
|
|
:param dict[str,str] options: The options of this figure. |
29
|
|
|
:param str argument: Not used. |
30
|
|
|
""" |
31
|
|
|
super().__init__(io, 'icon', options, argument) |
32
|
|
|
|
33
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
34
|
1 |
|
def get_command(self) -> str: |
35
|
|
|
""" |
36
|
|
|
Returns the command of this node, i.e. icon. |
37
|
|
|
""" |
38
|
|
|
return 'icon' |
39
|
|
|
|
40
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
41
|
1 |
|
def is_block_command(self) -> bool: |
42
|
|
|
""" |
43
|
|
|
Returns False. |
44
|
|
|
""" |
45
|
|
|
return False |
46
|
|
|
|
47
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
48
|
1 |
|
def is_inline_command(self) -> bool: |
49
|
|
|
""" |
50
|
|
|
Returns True. |
51
|
|
|
""" |
52
|
|
|
return True |
53
|
|
|
|
54
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
55
|
1 |
|
def is_phrasing(self) -> bool: |
56
|
|
|
""" |
57
|
|
|
Returns True if this node is a phrasing node, i.e. is a part of a paragraph. Otherwise returns False. |
58
|
|
|
""" |
59
|
|
|
return True |
60
|
|
|
|
61
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
62
|
1 |
|
@staticmethod |
63
|
1 |
|
def add_definition(name: str, attributes: Dict[str, str]): |
64
|
|
|
""" |
65
|
|
|
Adds the definition of an icon to the icon definitions. |
66
|
|
|
|
67
|
|
|
:param str name: The name of a reference to icon definition. |
68
|
|
|
:param dict[str,str] attributes: The attributes. |
69
|
|
|
""" |
70
|
|
|
IconNode._definitions[name] = attributes |
71
|
|
|
|
72
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
73
|
1 |
|
@staticmethod |
74
|
1 |
|
def get_definition(name: str) -> Optional[Dict[str, str]]: |
75
|
|
|
""" |
76
|
|
|
Returns the attributes of a definition, if name of definition is exists. |
77
|
|
|
|
78
|
|
|
:param str name: The name of a definition |
79
|
|
|
|
80
|
|
|
:rtype: dict[str,str]|None |
81
|
|
|
""" |
82
|
|
|
if name in IconNode._definitions: |
83
|
|
|
return IconNode._definitions[name] |
84
|
|
|
else: |
85
|
|
|
return None |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
89
|
|
|
NodeStore.register_inline_command('icon', IconNode) |
90
|
|
|
|