127d5bd6762abd935e5ad60c684d77f421924caa
[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     TXT_LEGACY_TOP_MARGIN = 1
13     TXT_LEGACY_BOTTOM_MARGIN = 0
14
15     EPUB_TAG = HTML_TAG = 'div'
16     EPUB_CLASS = 'verse'
17     HTML_CLASS = 'wl verse'
18
19     NUMBERING = 'main'
20
21     @property
22     def meta(self):
23         if hasattr(self, 'stanza'):
24             return self.stanza.meta
25         return super(Wers, self).meta
26
27     def _epub_build_inner(self, builder):
28         super()._epub_build_inner(builder)
29         builder.push_text('''\u00a0''')
30
31     @property
32     def has_visible_numbering(self):
33         try:
34             number = int(self.attrib['_visible_numbering'])
35         except:
36             return False
37         return number == 1 or not(number % 5)
38
39     @property
40     def is_stretched(self):
41         return self.find('.//tab[@szer="*"]') is not None
42
43     def get_html_attr(self, builder):
44         attr = super().get_html_attr(builder)
45         if self.is_stretched:
46             attr['class'] += ' verse-stretched'
47         return attr
48
49     def _html_build_inner(self, builder):
50         if self.is_stretched:
51             builder.start_element('span')
52         super()._html_build_inner(builder)
53         if self.is_stretched:
54             builder.end_element()