X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/d04e61819290fc8d6d71b1932c55a774014c1f05..3a0c83394d5783715fab2be29fa1a9cfc3574e28:/src/librarian/elements/poetry/strofa.py diff --git a/src/librarian/elements/poetry/strofa.py b/src/librarian/elements/poetry/strofa.py index 7df549f..7ce3f3a 100644 --- a/src/librarian/elements/poetry/strofa.py +++ b/src/librarian/elements/poetry/strofa.py @@ -1,16 +1,33 @@ +# This file is part of Librarian, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. +# from copy import copy +import re from ..base import WLElement from .wers import Wers class Strofa(WLElement): + SHOULD_HAVE_ID = True + TXT_TOP_MARGIN = 2 TXT_BOTTOM_MARGIN = 2 TXT_LEGACY_TOP_MARGIN = 1 TXT_LEGACY_BOTTOM_MARGIN = 0 - HTML_TAG = 'div' - HTML_CLASS = 'stanza' + EPUB_TAG = HTML_TAG = 'div' + EPUB_CLASS = HTML_CLASS = 'stanza' + + def epub_build(self, builder): + super().epub_build(builder) + builder.start_element( + 'div', + { + 'class': 'stanza-spacer' + } + ) + builder.push_text('\u00a0'); + builder.end_element() def get_verses(self): from librarian.parser import parser @@ -20,7 +37,7 @@ class Strofa(WLElement): ] if self.text: # Before any tags. These are text-only verses. - pieces = self.text.split('/') + pieces = re.split(r"/\s+", self.text) for piece in pieces[:-1]: verses[-1].text = piece verses.append(parser.makeelement('wers')) @@ -28,7 +45,7 @@ class Strofa(WLElement): for child in self: if child.tail: - pieces = child.tail.split('/') + pieces = re.split(r"/\s+", child.tail) child_copy = copy(child) child_copy.tail = pieces[0] verses[-1].append(child_copy)