Completed
Push — master ( 57e7bf...8a74a7 )
by P.R.
01:36
created

ParagraphNode   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 71
Duplicated Lines 0 %
Metric Value
wmc 12
dl 0
loc 71
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A is_inline_command() 0 7 1
A is_block_command() 0 7 1
A __init__() 0 8 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
from sdoc.sdoc2 import node_store, in_scope, out_scope
10
from sdoc.sdoc2.node.HeadingNode import HeadingNode
11
from sdoc.sdoc2.node.Node import Node
12
from sdoc.sdoc2.node.TextNode import TextNode
13
14
15
class ParagraphNode(HeadingNode):
16
    """
17
    SDoc2 node for paragraphs.
18
    """
19
20
    # ------------------------------------------------------------------------------------------------------------------
21
    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
        super().__init__('paragraph', options, argument)
29
30
    # ------------------------------------------------------------------------------------------------------------------
31
    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
    def is_block_command(self):
41
        """
42
        Returns False.
43
44
        :rtype: bool
45
        """
46
        return False
47
48
    # ------------------------------------------------------------------------------------------------------------------
49
    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
        Node.number(self, numbers)
56
57
    # ------------------------------------------------------------------------------------------------------------------
58
    def is_inline_command(self):
59
        """
60
        Returns False.
61
62
        :rtype: bool
63
        """
64
        return False
65
66
    # ------------------------------------------------------------------------------------------------------------------
67
    def prune_whitespace(self):
68
        """
69
        Removes spaces from end of a paragraph.
70
        """
71
        first = self.child_nodes[0]
72
        last = self.child_nodes[-1]
73
74
        for node_id in self.child_nodes:
75
            node = in_scope(node_id)
76
77
            if isinstance(node, TextNode):
78
                if node.id == first:
79
                    node.prune_whitespace(leading=True)
80
                if node.id == last:
81
                    node.prune_whitespace(trailing=True)
82
                if node.id != last and node.id != first:
83
                    node.prune_whitespace()
84
85
            out_scope(node)
86
87
88
# ----------------------------------------------------------------------------------------------------------------------
89
node_store.register_inline_command('paragraph', ParagraphNode)
90