1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
6 from ..base import WLElement
10 class Strofa(WLElement):
15 TXT_LEGACY_TOP_MARGIN = 1
16 TXT_LEGACY_BOTTOM_MARGIN = 0
18 EPUB_TAG = HTML_TAG = 'div'
19 EPUB_CLASS = HTML_CLASS = 'stanza'
21 def epub_build(self, builder):
22 super().epub_build(builder)
23 builder.start_element(
26 'class': 'stanza-spacer'
29 builder.push_text('\u00a0');
33 from librarian.parser import parser
36 parser.makeelement('wers')
39 # Before any tags. These are text-only verses.
40 pieces = re.split(r"/\s+", self.text)
41 for piece in pieces[:-1]:
42 verses[-1].text = piece
43 verses.append(parser.makeelement('wers'))
44 verses[-1].text = pieces[-1]
48 pieces = re.split(r"/\s+", child.tail)
49 child_copy = copy(child)
50 child_copy.tail = pieces[0]
51 verses[-1].append(child_copy)
53 for piece in pieces[1:]:
54 verses.append(parser.makeelement('wers'))
55 verses[-1].text = piece
58 verses[-1].append(child)
62 if len(verse) == 1 and isinstance(verse[0], Wers):
63 assert not (verse.text or '').strip()
64 assert not (verse[0].tail or '').strip()
69 def _build_inner(self, builder, build_method):
70 for child in self.get_verses():
71 getattr(child, build_method)(builder)