fix
[librarian.git] / src / librarian / elements / poetry / wers.py
1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 from ..base import WLElement
5
6
7 class Wers(WLElement):
8     STRIP = True
9
10     TXT_TOP_MARGIN = 1
11     TXT_BOTTOM_MARGIN = 1
12
13     EPUB_TAG = HTML_TAG = 'div'
14     EPUB_CLASS = 'verse'
15     HTML_CLASS = 'wl verse'
16
17     NUMBERING = 'main'
18
19     @property
20     def meta(self):
21         if hasattr(self, 'stanza'):
22             return self.stanza.meta
23         return super(Wers, self).meta
24
25     def _epub_build_inner(self, builder):
26         super()._epub_build_inner(builder)
27         builder.push_text('''\u00a0''')
28
29     @property
30     def has_visible_numbering(self):
31         try:
32             number = int(self.attrib['_visible_numbering'])
33         except:
34             return False
35         return number == 1 or not(number % 5)
36
37     @property
38     def is_stretched(self):
39         return self.find('.//tab[@szer="*"]') is not None
40
41     def get_html_attr(self, builder):
42         attr = super().get_html_attr(builder)
43         if self.is_stretched:
44             attr['class'] += ' verse-stretched'
45         return attr
46
47     def _html_build_inner(self, builder):
48         if self.is_stretched:
49             builder.start_element('span')
50         super()._html_build_inner(builder)
51         if self.is_stretched:
52             builder.end_element()