openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #15520
[Merge] lp:~googol/openlp/bug-885874 into lp:openlp
Andreas Preikschat has proposed merging lp:~googol/openlp/bug-885874 into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
Related bugs:
Bug #885874 in OpenLP: "Song with mis matched formatting tags abends on render"
https://bugs.launchpad.net/openlp/+bug/885874
For more details, see:
https://code.launchpad.net/~googol/openlp/bug-885874/+merge/104835
Hello,
- fixed bug 885874 (Song with mis matched formatting tags abends on render)
--
https://code.launchpad.net/~googol/openlp/bug-885874/+merge/104835
Your team OpenLP Core is requested to review the proposed merge of lp:~googol/openlp/bug-885874 into lp:openlp.
=== modified file 'openlp/core/lib/renderer.py'
--- openlp/core/lib/renderer.py 2012-05-02 18:25:37 +0000
+++ openlp/core/lib/renderer.py 2012-05-05 14:10:24 +0000
@@ -235,8 +235,8 @@
# the first two slides (and neglect the last for now).
if len(slides) == 3:
html_text = expand_tags(u'\n'.join(slides[:2]))
- # We check both slides to determine if the optional break is
- # needed (there is only one optional break).
+ # We check both slides to determine if the optional split is
+ # needed (there is only one optional split).
else:
html_text = expand_tags(u'\n'.join(slides))
html_text = html_text.replace(u'\n', u'<br>')
@@ -247,8 +247,8 @@
else:
# The first optional slide fits, which means we have to
# render the first optional slide.
- text_contains_break = u'[---]' in text
- if text_contains_break:
+ text_contains_split = u'[---]' in text
+ if text_contains_split:
try:
text_to_render, text = \
text.split(u'\n[---]\n', 1)
@@ -263,7 +263,7 @@
if len(slides) > 1 and text:
# Add all slides apart from the last one the list.
pages.extend(slides[:-1])
- if text_contains_break:
+ if text_contains_split:
text = slides[-1] + u'\n[---]\n' + text
else:
text = slides[-1] + u'\n'+ text
@@ -492,7 +492,7 @@
(raw_text.find(tag[u'start tag']), tag[u'start tag'],
tag[u'end tag']))
html_tags.append(
- (raw_text.find(tag[u'start tag']), tag[u'start html']))
+ (raw_text.find(tag[u'start tag']), tag[u'start html']))
# Sort the lists, so that the tags which were opened first on the first
# slide (the text we are checking) will be opened first on the next
# slide as well.
=== modified file 'openlp/plugins/songs/lib/xml.py'
--- openlp/plugins/songs/lib/xml.py 2012-04-29 15:31:56 +0000
+++ openlp/plugins/songs/lib/xml.py 2012-05-05 14:10:24 +0000
@@ -33,7 +33,7 @@
<song version="1.0">
<lyrics>
<verse type="c" label="1" lang="en">
- <![CDATA[Chorus virtual slide 1[---]Chorus virtual slide 2]]>
+ <![CDATA[Chorus optional split 1[---]Chorus optional split 2]]>
</verse>
</lyrics>
</song>
@@ -135,7 +135,7 @@
The returned list has the following format::
[[{'type': 'v', 'label': '1'},
- u"virtual slide 1[---]virtual slide 2"],
+ u"optional slide split 1[---]optional slide split 2"],
[{'lang': 'en', 'type': 'c', 'label': '1'}, u"English chorus"]]
"""
self.song_xml = None
@@ -334,18 +334,59 @@
self._add_text_to_element(u'verse', lyrics, None, verse_def)
if u'lang' in verse[0]:
verse_element.set(u'lang', verse[0][u'lang'])
- # Create a list with all "virtual" verses.
- virtual_verses = cgi.escape(verse[1])
- virtual_verses = virtual_verses.split(u'[---]')
- for index, virtual_verse in enumerate(virtual_verses):
+ # Create a list with all "optional" verses.
+ optional_verses = cgi.escape(verse[1])
+ optional_verses = optional_verses.split(u'[---]')
+ start_tags = u''
+ end_tags = u''
+ for index, optional_verse in enumerate(optional_verses):
+ # Fix up missing end and start tags such as {r} or {/r}.
+ optional_verse = start_tags + optional_verse
+ start_tags, end_tags = self._get_start_tags(optional_verse)
+ optional_verse += end_tags
# Add formatting tags to text
lines_element = self._add_text_with_tags_to_lines(verse_element,
- virtual_verse, tags_element)
+ optional_verse, tags_element)
# Do not add the break attribute to the last lines element.
- if index < len(virtual_verses) - 1:
+ if index < len(optional_verses) - 1:
lines_element.set(u'break', u'optional')
return self._extract_xml(song_xml)
+ def _get_start_tags(self, text):
+ """
+ Tests the given text for not closed formatting tags and returns a tuple
+ consisting of two unicode strings::
+
+ (u'{st}{r}', u'{/r}{/st}')
+
+ The first unicode string are the start tags (for the next slide). The
+ second unicode string are the end tags.
+
+ ``text``
+ The text to test. The text must **not** contain html tags, only
+ OpenLP formatting tags are allowed::
+
+ {st}{r}Text text text
+ """
+ tags = []
+ for tag in FormattingTags.get_html_tags():
+ if tag[u'start tag'] == u'{br}':
+ continue
+ if text.count(tag[u'start tag']) != text.count(tag[u'end tag']):
+ tags.append((text.find(tag[u'start tag']),
+ tag[u'start tag'], tag[u'end tag']))
+ # Sort the lists, so that the tags which were opened first on the first
+ # slide (the text we are checking) will be opened first on the next
+ # slide as well.
+ tags.sort(key=lambda tag: tag[0])
+ end_tags = []
+ start_tags = []
+ for tag in tags:
+ start_tags.append(tag[1])
+ end_tags.append(tag[2])
+ end_tags.reverse()
+ return u''.join(start_tags), u''.join(end_tags)
+
def xml_to_song(self, xml, parse_and_temporary_save=False):
"""
Create and save a song from OpenLyrics format xml to the database. Since
Follow ups