ParagraphNode.is_block_command()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

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