Completed
Push — master ( 4c8e7d...ffbd85 )
by P.R.
01:53
created

HyperlinkHtmlFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
dl 0
loc 36
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 8 1
A generate_chapter() 0 9 2
A get_html() 0 10 1
1
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
# ----------------------------------------------------------------------------------------------------------------------
9
from sdoc.helper.Html import Html
10
from sdoc.sdoc2 import node_store
11
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
12
13
14
class HyperlinkHtmlFormatter(HtmlFormatter):
15
    """
16
    HtmlFormatter for generating HTML code for hyperlinks.
17
    """
18
    # ------------------------------------------------------------------------------------------------------------------
19
    def generate(self, node, file):
20
        """
21
        Generates the HTML code for a hyperlink node.
22
23
        :param sdoc.sdoc2.node.HyperlinkNode.HyperlinkNode node: The hyperlink node.
24
        :param file file: The output file.
25
        """
26
        file.write(HyperlinkHtmlFormatter.get_html(node))
27
28
    # ------------------------------------------------------------------------------------------------------------------
29
    def generate_chapter(self, node, file):
30
        """
31
        Generates the HTML code for a hyperlink node.
32
33
        :param sdoc.sdoc2.node.HyperlinkNode.HyperlinkNode node: The hyperlink node.
34
        :param file file: The output file.
35
        """
36
        if file:
37
            file.write(HyperlinkHtmlFormatter.get_html(node))
38
39
    # ------------------------------------------------------------------------------------------------------------------
40
    @staticmethod
41
    def get_html(node):
42
        """
43
        Returns string with generated HTML tag.
44
45
        :param sdoc.sdoc2.node.HyperlinkNode.HyperlinkNode node: The hyperlink node.
46
47
        :rtype: str
48
        """
49
        return Html.generate_element('a', node.get_html_attributes(), node.argument)
50
51
# ----------------------------------------------------------------------------------------------------------------------
52
node_store.register_formatter('hyperlink', 'html', HyperlinkHtmlFormatter)
53