'
+ active_formatting_tags = []
+ if re.search(r'\[.*?\]', line):
+ words = line.split(' ')
+ in_chord = False
+ for word in words:
+ chords = []
+ lyrics = []
+ new_line += ''
+ # If the word contains a chord, we need to handle it.
+ if re.search(r'\[.*?\]', word):
+ chord = ''
+ lyric = ''
+ # Loop over each character of the word
+ for char in word:
+ if char == '[':
+ in_chord = True
+ if lyric != '':
+ if chord == '':
+ chord = ' '
+ chords.append(chord)
+ lyrics.append(lyric)
+ chord = ''
+ lyric = ''
+ elif char == ']' and in_chord:
+ in_chord = False
+ elif in_chord:
+ chord += char
+ else:
+ lyric += char
+ if lyric != '' or chord != '':
+ if chord == '':
+ chord = ' '
+ if lyric == '':
+ lyric = ' '
+ chords.append(chord)
+ lyrics.append(lyric)
+ new_chord_line = ''
+ new_lyric_line = ' '
+ for i in range(len(lyrics)):
+ spacer = compare_chord_lyric(chords[i], lyrics[i])
+ # Handle formatting tags
+ start_formatting_tags = ''
+ if active_formatting_tags:
+ start_formatting_tags = '{' + '}{'.join(active_formatting_tags) + '}'
+ # Update list of active formatting tags
+ active_formatting_tags = find_formatting_tags(lyrics[i], active_formatting_tags)
+ end_formatting_tags = ''
+ if active_formatting_tags:
+ end_formatting_tags = '{/' + '}{/'.join(active_formatting_tags) + '}'
+ new_chord_line += '%s | ' % chords[i]
+ # Check if this is the last column, if so skip spacing calc and instead insert a single space
+ if i + 1 == len(lyrics):
+ new_lyric_line += '{starttags}{lyrics} {endtags} | '.format(
+ starttags=start_formatting_tags, lyrics=lyrics[i], endtags=end_formatting_tags)
+ else:
+ spacing = ''
+ if spacer > 0:
+ space = ' ' * int(math.ceil(spacer / 2))
+ spacing = '%s-%s' % (space, space)
+ new_lyric_line += '{starttags}{lyrics}{spacing}{endtags} | '.format(
+ starttags=start_formatting_tags, lyrics=lyrics[i], spacing=spacing,
+ endtags=end_formatting_tags)
+ new_line += new_chord_line + new_lyric_line + ' '
+ else:
+ start_formatting_tags = ''
+ if active_formatting_tags:
+ start_formatting_tags = '{' + '}{'.join(active_formatting_tags) + '}'
+ active_formatting_tags = find_formatting_tags(word, active_formatting_tags)
+ end_formatting_tags = ''
+ if active_formatting_tags:
+ end_formatting_tags = '{/' + '}{/'.join(active_formatting_tags) + '}'
+ new_line += ' | ' \
+ '{starttags}{lyrics} {endtags} | '.format(
+ starttags=start_formatting_tags, lyrics=word, endtags=end_formatting_tags)
+ new_line += ' '
+ else:
+ new_line += line
+ new_line += ' |