Completed
Push — master ( 793cf7...172351 )
by P.R.
04:33
created

HeadingHtmlFormatter.generate()   A

Complexity

Conditions 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.2963

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
ccs 1
cts 3
cp 0.3333
rs 9.6666
c 1
b 0
f 0
cc 1
crap 1.2963
1
"""
2
SDoc
3
4
Copyright 2016 Set Based IT Consultancy
5
6
Licence MIT
7
"""
8
# ----------------------------------------------------------------------------------------------------------------------
9 1
from sdoc.helper.Html import Html
10 1
from sdoc.sdoc2 import node_store
11 1
from sdoc.sdoc2.formatter.html.HtmlFormatter import HtmlFormatter
12
13
14 1
class HeadingHtmlFormatter(HtmlFormatter):
15
    """
16
    HtmlFormatter for generating HTML code for headings.
17
    """
18
    # ------------------------------------------------------------------------------------------------------------------
19 1
    def generate(self, node, file):
20
        """
21
        Generates the HTML code for a heading node.
22
23
        :param sdoc.sdoc2.node.HeadingNode.HeadingNode node: The heading node.
24
        :param file file: The output file.
25
        """
26
        self.generate_heading_node(node, file)
27
        HtmlFormatter.generate(self, node, file)
28
29
    # ------------------------------------------------------------------------------------------------------------------
30 1
    @staticmethod
31
    def generate_heading_node(node, file):
32
        """
33
        Generates the HTML code for heading node.
34
35
        :param sdoc.sdoc2.node.HeadingNode.HeadingNode node: The heading node.
36
        :param file file: The output file.
37
        """
38
        # Set id attribute to heading node.
39
        attributes = {'id': node.get_option_value('id')}
40
41
        number = node.get_option_value('number')
42
        text_in_tag = '{0} {1!s}'.format('' if not number else number, node.argument)
43
        file.write(Html.generate_element('h{0:d}'.format(node.get_hierarchy_level()), attributes, text_in_tag))
44
45
# ----------------------------------------------------------------------------------------------------------------------
46 1
node_store.register_formatter('chapter', 'html', HeadingHtmlFormatter)
47 1
node_store.register_formatter('section', 'html', HeadingHtmlFormatter)
48 1
node_store.register_formatter('subsection', 'html', HeadingHtmlFormatter)
49 1
node_store.register_formatter('sub2section', 'html', HeadingHtmlFormatter)
50 1
node_store.register_formatter('sub3section', 'html', HeadingHtmlFormatter)
51 1
node_store.register_formatter('sub4section', 'html', HeadingHtmlFormatter)
52
node_store.register_formatter('sub5section', 'html', HeadingHtmlFormatter)
53