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.NodeStore import NodeStore |
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
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
20
|
1 |
|
def generate(self, node, file): |
21
|
|
|
""" |
22
|
|
|
Generates the HTML code for a heading node. |
23
|
|
|
|
24
|
|
|
:param sdoc.sdoc2.node.HeadingNode.HeadingNode node: The heading node. |
25
|
|
|
:param file file: The output file. |
26
|
|
|
""" |
27
|
1 |
|
self.generate_heading_node(node, file) |
28
|
1 |
|
HtmlFormatter.generate(self, node, file) |
29
|
|
|
|
30
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
31
|
1 |
|
@staticmethod |
32
|
|
|
def generate_heading_node(node, file): |
33
|
|
|
""" |
34
|
|
|
Generates the HTML code for heading node. |
35
|
|
|
|
36
|
|
|
:param sdoc.sdoc2.node.HeadingNode.HeadingNode node: The heading node. |
37
|
|
|
:param file file: The output file. |
38
|
|
|
""" |
39
|
|
|
# Set id attribute to heading node. |
40
|
1 |
|
attributes = {'id': node.get_option_value('id')} |
41
|
|
|
|
42
|
1 |
|
if node.numbering: |
43
|
1 |
|
number = node.get_option_value('number') |
44
|
1 |
|
text_in_tag = '{0} {1}'.format('' if not number else number, node.argument) |
45
|
|
|
else: |
46
|
|
|
text_in_tag = '{0}'.format(node.argument) |
47
|
|
|
|
48
|
1 |
|
file.write(Html.generate_element('h{0:d}'.format(node.get_hierarchy_level()), attributes, text_in_tag)) |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
52
|
1 |
|
NodeStore.register_formatter('chapter', 'html', HeadingHtmlFormatter) |
53
|
1 |
|
NodeStore.register_formatter('section', 'html', HeadingHtmlFormatter) |
54
|
1 |
|
NodeStore.register_formatter('subsection', 'html', HeadingHtmlFormatter) |
55
|
1 |
|
NodeStore.register_formatter('sub2section', 'html', HeadingHtmlFormatter) |
56
|
1 |
|
NodeStore.register_formatter('sub3section', 'html', HeadingHtmlFormatter) |
57
|
1 |
|
NodeStore.register_formatter('sub4section', 'html', HeadingHtmlFormatter) |
58
|
|
|
NodeStore.register_formatter('sub5section', 'html', HeadingHtmlFormatter) |
59
|
|
|
|