|
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 FigureHtmlFormatter(HtmlFormatter): |
|
15
|
|
|
""" |
|
16
|
|
|
HtmlFormatter for generating HTML code for figures. |
|
17
|
|
|
""" |
|
18
|
|
|
|
|
19
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
20
|
1 |
|
def generate(self, node, file): |
|
21
|
|
|
""" |
|
22
|
|
|
Generates the HTML code for a figure node. |
|
23
|
|
|
|
|
24
|
|
|
:param sdoc.sdoc2.node.FigureNode.FigureNode node: The figure node. |
|
25
|
|
|
:param file file: The output file. |
|
26
|
|
|
""" |
|
27
|
|
|
self.write_into_file(node, file) |
|
28
|
|
|
|
|
29
|
|
|
HtmlFormatter.generate(self, node, file) |
|
30
|
|
|
|
|
31
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
32
|
1 |
|
@staticmethod |
|
33
|
|
|
def _write_caption(node, file): |
|
34
|
|
|
""" |
|
35
|
|
|
Generates the caption for the table in HTML representation. |
|
36
|
|
|
|
|
37
|
|
|
:param sdoc.sdoc2.node.FigureNode.FigureNode node: The figure node. |
|
38
|
|
|
:param file file: The output file. |
|
39
|
|
|
""" |
|
40
|
|
|
if node.caption: |
|
41
|
|
|
figure_number = node.get_option_value('number') |
|
42
|
|
|
|
|
43
|
|
|
if figure_number: |
|
44
|
|
|
inner_text = 'Figuur {}: {}'.format(figure_number, node.caption) # TODO Internationalization |
|
|
|
|
|
|
45
|
|
|
else: |
|
46
|
|
|
inner_text = node.caption |
|
47
|
|
|
|
|
48
|
|
|
file.write(Html.generate_element('figcaption', {}, inner_text)) |
|
49
|
|
|
|
|
50
|
|
|
# ------------------------------------------------------------------------------------------------------------------ |
|
51
|
1 |
|
@staticmethod |
|
52
|
|
|
def write_into_file(node, file): |
|
53
|
|
|
""" |
|
54
|
|
|
Writes data into opened HTML file. |
|
55
|
|
|
|
|
56
|
|
|
:param sdoc.sdoc2.node.FigureNode.FigureNode node: The figure node. |
|
57
|
|
|
:param file file: The output file. |
|
58
|
|
|
""" |
|
59
|
|
|
# Creating dicts with attributes for each type of element. |
|
60
|
|
|
figure_attributes = {'id': node.get_option_value('id')} |
|
61
|
|
|
|
|
62
|
|
|
img_attributes = {'src': node.get_option_value('src'), |
|
63
|
|
|
'width': node.get_option_value('width'), |
|
64
|
|
|
'height': node.get_option_value('height'), |
|
65
|
|
|
'alt': node.caption} |
|
66
|
|
|
|
|
67
|
|
|
# Creating elements. |
|
68
|
|
|
file.write(Html.generate_tag('figure', figure_attributes)) |
|
69
|
|
|
|
|
70
|
|
|
file.write(Html.generate_element('img', img_attributes)) |
|
71
|
|
|
|
|
72
|
|
|
FigureHtmlFormatter._write_caption(node, file) |
|
73
|
|
|
|
|
74
|
|
|
file.write('</figure>') |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
|
78
|
|
|
NodeStore.register_formatter('figure', 'html', FigureHtmlFormatter) |
|
79
|
|
|
|