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, in_scope, out_scope |
10
|
1 |
|
from sdoc.sdoc2.node.HeadingNode import HeadingNode |
11
|
1 |
|
from sdoc.sdoc2.node.Node import Node |
12
|
1 |
|
from sdoc.sdoc2.node.TextNode import TextNode |
13
|
|
|
|
14
|
|
|
|
15
|
1 |
|
class ParagraphNode(HeadingNode): |
16
|
|
|
""" |
17
|
|
|
SDoc2 node for paragraphs. |
18
|
|
|
""" |
19
|
|
|
|
20
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
21
|
1 |
|
def __init__(self, io, options, argument): |
22
|
|
|
""" |
23
|
|
|
Object constructor. |
24
|
|
|
|
25
|
|
|
:param None|cleo.styles.output_style.OutputStyle io: The IO object. |
26
|
|
|
:param dict[str,str] options: Not used. |
27
|
|
|
:param str argument: The text of this paragraph. |
28
|
|
|
""" |
29
|
1 |
|
super().__init__(io, 'paragraph', options, argument) |
30
|
|
|
|
31
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
32
|
1 |
|
def get_command(self): |
33
|
|
|
""" |
34
|
|
|
Returns the command of this node, i.e. paragraph. |
35
|
|
|
|
36
|
|
|
:rtype: str |
37
|
|
|
""" |
38
|
|
|
return 'paragraph' |
39
|
|
|
|
40
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
41
|
1 |
|
def is_block_command(self): |
42
|
|
|
""" |
43
|
|
|
Returns False. |
44
|
|
|
|
45
|
|
|
:rtype: bool |
46
|
|
|
""" |
47
|
|
|
return False |
48
|
|
|
|
49
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
50
|
1 |
|
def number(self, numbers): |
51
|
|
|
""" |
52
|
|
|
Overrides the HeadingNode implementation withe the (original) Node implementation. |
53
|
|
|
|
54
|
|
|
:param dict[str,str] numbers: The number of last node. |
55
|
|
|
""" |
56
|
1 |
|
Node.number(self, numbers) |
57
|
|
|
|
58
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
59
|
1 |
|
def is_inline_command(self): |
60
|
|
|
""" |
61
|
|
|
Returns False. |
62
|
|
|
|
63
|
|
|
:rtype: bool |
64
|
|
|
""" |
65
|
|
|
return False |
66
|
|
|
|
67
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
68
|
1 |
|
def set_toc_id(self): |
69
|
|
|
""" |
70
|
|
|
Don't do anything. Because we needn't this behaviour here. |
71
|
|
|
""" |
72
|
|
|
pass |
73
|
|
|
|
74
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
75
|
1 |
|
def prune_whitespace(self): |
76
|
|
|
""" |
77
|
|
|
Removes spaces from end of a paragraph. |
78
|
|
|
""" |
79
|
1 |
|
first = self.child_nodes[0] |
80
|
1 |
|
last = self.child_nodes[-1] |
81
|
|
|
|
82
|
1 |
|
for node_id in self.child_nodes: |
83
|
1 |
|
node = in_scope(node_id) |
84
|
|
|
|
85
|
1 |
|
if isinstance(node, TextNode): |
86
|
1 |
|
if node.id == first: |
87
|
1 |
|
node.prune_whitespace(leading=True) |
88
|
1 |
|
if node.id == last: |
89
|
1 |
|
node.prune_whitespace(trailing=True) |
90
|
1 |
|
if node.id != last and node.id != first: |
91
|
|
|
node.prune_whitespace() |
92
|
|
|
|
93
|
1 |
|
out_scope(node) |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
97
|
|
|
node_store.register_inline_command('paragraph', ParagraphNode) |
98
|
|
|
|