Completed
Pull Request — master (#43)
by Oleg
02:07
created

ParagraphNode   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 80.77%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
dl 0
loc 79
ccs 21
cts 26
cp 0.8077
rs 10
c 1
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A is_inline_command() 0 7 1
A is_block_command() 0 7 1
A __init__() 0 9 1
A set_toc_id() 0 5 1
A number() 0 7 1
A get_command() 0 7 1
B prune_whitespace() 0 19 7
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