wip change fb2 api
[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     FB2_TAG = 'v'
17
18     NUMBERING = 'main'
19
20     @property
21     def meta(self):
22         if hasattr(self, 'stanza'):
23             return self.stanza.meta
24         return super(Wers, self).meta
25
26     def epub_build_inner(self, builder):
27         super().epub_build_inner(builder)
28         builder.push_text('''\u00a0''')
29
30     @property
31     def has_visible_numbering(self):
32         try:
33             number = int(self.attrib['_visible_numbering'])
34         except:
35             return False
36         return number == 1 or not(number % 5)
37
38     @property
39     def is_stretched(self):
40         return self.find('.//tab[@szer="*"]') is not None
41
42     def get_html_attr(self, builder):
43         attr = super().get_html_attr(builder)
44         if self.is_stretched:
45             attr['class'] += ' verse-stretched'
46         return attr
47
48     def html_build_inner(self, builder):
49         if self.is_stretched:
50             builder.start_element('span')
51         super().html_build_inner(builder)
52         if self.is_stretched:
53             builder.end_element()