Images: image@src is a URL, and image sizes are limited.
[librarian.git] / src / librarian / elements / footnotes / __init__.py
1 # -*- coding: utf-8
2 from __future__ import unicode_literals
3
4 from ..base import WLElement
5
6
7 class Footnote(WLElement):
8     def txt_build(self, builder):
9         pass
10
11     def html_build(self, builder):
12         if not builder.with_footnotes:
13             return
14
15         builder.footnote_counter += 1
16         fn_no = builder.footnote_counter
17         footnote_id = 'footnote-idm{}'.format(self.attrib['_compat_ordered_id'])
18         anchor_id = 'anchor-idm{}'.format(self.attrib['_compat_ordered_id'])
19
20         # Add anchor.
21         builder.start_element(
22             'a',
23             {
24                 "href": '#{}'.format(footnote_id),
25                 "class": "annotation-anchor",
26                 "id": anchor_id,
27             }
28         )
29         builder.push_text('[{}]'.format(fn_no))
30         builder.end_element()
31         
32         # Add actual footnote.
33         builder.enter_fragment('footnotes')
34         builder.start_element('div', {'class': 'fn-{}'.format(self.tag)})
35         builder.push_text('\n') # Compat
36         builder.start_element('a', {'name': footnote_id})
37         builder.end_element()
38         builder.start_element('a', {
39             'href': '#{}'.format(anchor_id), 'class': 'annotation'
40         })
41         builder.push_text('[{}]'.format(fn_no))
42         builder.end_element()
43
44         builder.start_element('p')
45         super(Footnote, self).html_build(builder)
46
47         builder.push_text(' [{}]'.format(self.qualifier))
48         builder.end_element()
49         builder.end_element()
50         builder.exit_fragment()
51
52
53 class PA(Footnote):
54     """Przypis autorski."""
55     @property
56     def qualifier(self):
57         _ = self.gettext
58         return _("author's footnote")
59
60
61 class PT(Footnote):
62     """Przypis tłumacza."""
63     @property
64     def qualifier(self):
65         _ = self.gettext
66         return _("translator's footnote")
67
68
69 class PR(Footnote):
70     """Przypis redakcyjny."""
71     @property
72     def qualifier(self):
73         _ = self.gettext
74         return _("editor's footnote")
75
76
77 class PE(Footnote):
78     """Przypis redakcji źródła."""
79     @property
80     def qualifier(self):
81         _ = self.gettext
82         return _("source editor's footnote")