HeadingHtmlFormatter.generate_heading_node()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 18
Code Lines 8

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 0
Metric Value
eloc 8
dl 18
loc 18
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0
cc 3
nop 2
crap 3.0175
1 1
from typing import Any
2
3 1
from sdoc.helper.Html import Html
4 1
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
5 1
from sdoc.sdoc2.node.HeadingNode import HeadingNode
6 1
from sdoc.sdoc2.NodeStore import NodeStore
7
8
9 1 View Code Duplication
class HeadingHtmlFormatter(HtmlFormatter):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
10
    """
11
    HtmlFormatter for generating HTML code for headings.
12
    """
13
14
    # ------------------------------------------------------------------------------------------------------------------
15 1
    def generate(self, node: HeadingNode, file: Any) -> None:
16
        """
17
        Generates the HTML code for a heading node.
18
19
        :param HeadingNode node: The heading node.
20
        :param any file: The output file.
21
        """
22 1
        self.generate_heading_node(node, file)
23 1
        HtmlFormatter.generate(self, node, file)
24
25
    # ------------------------------------------------------------------------------------------------------------------
26 1
    @staticmethod
27 1
    def generate_heading_node(node: HeadingNode, file: Any) -> None:
28
        """
29
        Generates the HTML code for heading node.
30
31
        :param HeadingNode node: The heading node.
32
        :param any file: The output file.
33
        """
34
        # Set id attribute to heading node.
35 1
        attributes = {'id': node.get_option_value('id')}
36
37 1
        if node.numbering:
38 1
            number = node.get_option_value('number')
39 1
            text_in_tag = '{0} {1}'.format('' if not number else number, node.argument)
40
        else:
41
            text_in_tag = '{0}'.format(node.argument)
42
43 1
        file.write(Html.generate_element('h{0:d}'.format(node.get_hierarchy_level() + 2), attributes, text_in_tag))
44
45
46
# ----------------------------------------------------------------------------------------------------------------------
47 1
NodeStore.register_formatter('part', 'html', HeadingHtmlFormatter)
48 1
NodeStore.register_formatter('chapter', 'html', HeadingHtmlFormatter)
49 1
NodeStore.register_formatter('section', 'html', HeadingHtmlFormatter)
50 1
NodeStore.register_formatter('subsection', 'html', HeadingHtmlFormatter)
51 1
NodeStore.register_formatter('sub2section', 'html', HeadingHtmlFormatter)
52
NodeStore.register_formatter('sub3section', 'html', HeadingHtmlFormatter)
53