ReferenceHtmlFormatter.get_html()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 6
dl 12
loc 12
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nop 1
crap 1
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.ReferenceNode import ReferenceNode
6 1
from sdoc.sdoc2.NodeStore import NodeStore
7
8
9 1 View Code Duplication
class ReferenceHtmlFormatter(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 references.
12
    """
13
14
    # ------------------------------------------------------------------------------------------------------------------
15 1
    def generate(self, node: ReferenceNode, file: Any) -> None:
16
        """
17
        Generates the HTML code for a reference node.
18
19
        :param ReferenceNode node: The reference node.
20
        :param any file: The output file.
21
        """
22 1
        self.write_into_file(node, file)
23
24 1
        HtmlFormatter.generate(self, node, file)
25
26
    # ------------------------------------------------------------------------------------------------------------------
27 1
    @staticmethod
28 1
    def write_into_file(node: ReferenceNode, file: Any) -> None:
29
        """
30
        Writes data into opened file.
31
32
        :param ReferenceNode node: The reference node.
33
        :param any file: The output file.
34
        """
35 1
        file.write(ReferenceHtmlFormatter.get_html(node))
36
37
    # ------------------------------------------------------------------------------------------------------------------
38 1
    @staticmethod
39 1
    def get_html(node: ReferenceNode) -> str:
40
        """
41
        Returns string with generated HTML tag.
42
43
        :param ReferenceNode node: The reference node.
44
        """
45 1
        attributes = {'class': node.get_option_value('class'),
46
                      'href':  node.get_option_value('href'),
47
                      'title': node.get_option_value('title')}
48
49 1
        return Html.generate_element('a', attributes, str(node.text))
50
51
52
# ----------------------------------------------------------------------------------------------------------------------
53
NodeStore.register_formatter('ref', 'html', ReferenceHtmlFormatter)
54