Fix issues with ignoring comments and chords

This commit is contained in:
Martin Zibricky 2011-09-23 02:12:55 +02:00
parent 354bec8b33
commit 1ef223b4a3

View File

@ -589,14 +589,16 @@ class OpenLyrics(object):
text = u'' text = u''
use_endtag = True use_endtag = True
# Skip <comment> elements - not yet supported. # Skip <comment> elements - not yet supported.
if element.tag == NSMAP % u'comment' and element.tail: if element.tag == NSMAP % u'comment':
# Append tail text at chord element. if element.tail:
text += element.tail # Append tail text at chord element.
text += element.tail
return text return text
# Skip <chord> element - not yet supported. # Skip <chord> element - not yet supported.
elif element.tag == NSMAP % u'chord' and element.tail: elif element.tag == NSMAP % u'chord':
# Append tail text at chord element. if element.tail:
text += element.tail # Append tail text at chord element.
text += element.tail
return text return text
# Convert line breaks <br/> to \n. # Convert line breaks <br/> to \n.
elif newlines and element.tag == NSMAP % u'br': elif newlines and element.tag == NSMAP % u'br':
@ -626,7 +628,7 @@ class OpenLyrics(object):
text += element.tail text += element.tail
return text return text
def _process_verse_lines(self, lines): def _process_verse_lines(self, lines, version):
""" """
Converts lyrics lines to OpenLP representation. Converts lyrics lines to OpenLP representation.
@ -637,18 +639,22 @@ class OpenLyrics(object):
# Convert lxml.objectify to lxml.etree representation. # Convert lxml.objectify to lxml.etree representation.
lines = etree.tostring(lines) lines = etree.tostring(lines)
element = etree.XML(lines) element = etree.XML(lines)
# OpenLyrics 0.8 uses <br/> for new lines.
# Append text from "lines" element to verse text.
if version > '0.7':
text = self._process_lines_mixed_content(element)
# OpenLyrics version <= 0.7 contais <line> elements to represent lines. # OpenLyrics version <= 0.7 contais <line> elements to represent lines.
# First child element is tested. # First child element is tested.
if element[0].tag == NSMAP % 'line': else:
# Loop over the "line" elements removing comments and chords. # Loop over the "line" elements removing comments and chords.
for line in element: for line in element:
# Skip comment lines.
if line.tag == NSMAP % u'comment':
continue
if text: if text:
text += u'\n' text += u'\n'
text += self._process_lines_mixed_content(line, newlines=False) text += self._process_lines_mixed_content(line, newlines=False)
# OpenLyrics 0.8 uses <br/> for new lines.
# Append text from "lines" element to verse text.
else:
text = self._process_lines_mixed_content(element)
return text return text
def _process_lyrics(self, properties, song_xml, song_obj): def _process_lyrics(self, properties, song_xml, song_obj):
@ -676,7 +682,8 @@ class OpenLyrics(object):
if text: if text:
text += u'\n' text += u'\n'
# Append text from "lines" element to verse text. # Append text from "lines" element to verse text.
text += self._process_verse_lines(lines) text += self._process_verse_lines(lines,
version=song_xml.get(u'version'))
# Add a virtual split to the verse text. # Add a virtual split to the verse text.
if lines.get(u'break') is not None: if lines.get(u'break') is not None:
text += u'\n[---]' text += u'\n[---]'