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