Completed
Push — master ( 5db226...8f2faa )
by P.R.
03:03
created

ParagraphNode.set_toc_id()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

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