← Back to team overview

openlp-core team mailing list archive

[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/104837

Hello,

- fixed bug 885874 (Song with mis matched formatting tags abends on render)
- fixed one extra new lines added before and after an optional break
1. Export a song containing [---]
2. Import the song again.
Result: A newline before and after [---] have been added.

Note: I am aware of the fact, that a similar function like the one I have added already exists in the renderer (in fact I copied it and modified it). But they still do different things.
-- 
https://code.launchpad.net/~googol/openlp/bug-885874/+merge/104837
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:39:20 +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,14 +247,18 @@
                     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)
                             except:
                                 text_to_render = text.split(u'\n[---]\n')[0]
                                 text = u''
+                            text_to_render, raw_tags, html_tags = \
+                                self._get_start_tags(text_to_render)
+                            if text:
+                                text = raw_tags + text
                         else:
                             text_to_render = text
                             text = u''
@@ -263,7 +267,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 +496,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:39:20 +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'\n[---]\n')
+            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_missing_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_missing_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