Completed
Push — master ( 172351...9797b3 )
by P.R.
03:28
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 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, options, argument):
22
        """
23
        Object constructor.
24
25
        :param dict[str,str] options: Not used.
26
        :param str argument: The text of this paragraph.
27
        """
28 1
        super().__init__('paragraph', options, argument)
29
30
    # ------------------------------------------------------------------------------------------------------------------
31 1
    def get_command(self):
32
        """
33
        Returns the command of this node, i.e. paragraph.
34
35
        :rtype: str
36
        """
37
        return 'paragraph'
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 number(self, numbers):
50
        """
51
        Overrides the HeadingNode implementation withe the (original) Node implementation.
52
53
        :param dict[str,str] numbers: The number of last node.
54
        """
55 1
        Node.number(self, numbers)
56
57
    # ------------------------------------------------------------------------------------------------------------------
58 1
    def is_inline_command(self):
59
        """
60
        Returns False.
61
62
        :rtype: bool
63
        """
64
        return False
65
66
    # ------------------------------------------------------------------------------------------------------------------
67 1
    def set_toc_id(self):
68
        """
69
        Don't do anything. Because we needn't this behaviour here.
70
        """
71
        pass
72
73
    # ------------------------------------------------------------------------------------------------------------------
74 1
    def prune_whitespace(self):
75
        """
76
        Removes spaces from end of a paragraph.
77
        """
78 1
        first = self.child_nodes[0]
79 1
        last = self.child_nodes[-1]
80
81 1
        for node_id in self.child_nodes:
82 1
            node = in_scope(node_id)
83
84 1
            if isinstance(node, TextNode):
85 1
                if node.id == first:
86 1
                    node.prune_whitespace(leading=True)
87 1
                if node.id == last:
88 1
                    node.prune_whitespace(trailing=True)
89 1
                if node.id != last and node.id != first:
90
                    node.prune_whitespace()
91
92 1
            out_scope(node)
93
94
95
# ----------------------------------------------------------------------------------------------------------------------
96
node_store.register_inline_command('paragraph', ParagraphNode)
97