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

HyperlinkHtmlFormatter.generate()   A

Complexity

Conditions 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 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