|
|
@ -11,11 +11,12 @@ from a file generated by the latex compilation of the songbook (.sxd). |
|
|
|
from unidecode import unidecode |
|
|
|
import locale |
|
|
|
import re |
|
|
|
import codecs |
|
|
|
|
|
|
|
from songbook_core.authors import processauthors |
|
|
|
from songbook_core.plastex import simpleparse |
|
|
|
|
|
|
|
EOL = "\n" |
|
|
|
EOL = u"\n" |
|
|
|
|
|
|
|
# Pattern set to ignore latex command in title prefix |
|
|
|
KEYWORD_PATTERN = re.compile(r"^%(\w+)\s?(.*)$") |
|
|
@ -37,11 +38,10 @@ def process_sxd(filename): |
|
|
|
|
|
|
|
Return an Index object. |
|
|
|
""" |
|
|
|
index_file = open(filename) |
|
|
|
data = [] |
|
|
|
with codecs.open(filename, 'r', 'utf-8') as index_file: |
|
|
|
for line in index_file: |
|
|
|
data.append(line.strip()) |
|
|
|
index_file.close() |
|
|
|
|
|
|
|
i = 1 |
|
|
|
idx = Index(data[0]) |
|
|
@ -124,7 +124,7 @@ class Index(object): |
|
|
|
def _raw_add(self, key, number, link): |
|
|
|
"""Add a song to the list. |
|
|
|
|
|
|
|
No processing is done one data. It is added raw. See add() for a |
|
|
|
No processing is done on data. It is added raw. See add() for a |
|
|
|
similar method with processing. |
|
|
|
""" |
|
|
|
first = self.get_first_letter(key) |
|
|
@ -142,13 +142,16 @@ class Index(object): |
|
|
|
if self.indextype == "TITLE": |
|
|
|
# Removing prefixes before titles |
|
|
|
for pattern in self.prefix_patterns: |
|
|
|
match = pattern.match(key) |
|
|
|
match = pattern.match(key.encode('utf-8')) |
|
|
|
if match: |
|
|
|
self._raw_add( |
|
|
|
"{} ({})".format( |
|
|
|
match.group(2) + match.group(3), |
|
|
|
match.group(1)), |
|
|
|
number, link) |
|
|
|
match.group(1) |
|
|
|
), |
|
|
|
number, |
|
|
|
link |
|
|
|
) |
|
|
|
return |
|
|
|
self._raw_add(key, number, link) |
|
|
|
|
|
|
@ -166,9 +169,11 @@ class Index(object): |
|
|
|
|
|
|
|
def entry_to_str(self, key, entry): |
|
|
|
"""Return the LaTeX code corresponding to the entry.""" |
|
|
|
return unicode(r'\idxentry{{{0}}}{{{1}}}' + EOL).format( |
|
|
|
if not isinstance(key, unicode): |
|
|
|
key = unicode(key, "UTF-8") |
|
|
|
return unicode(ur'\idxentry{{{0}}}{{{1}}}' + EOL).format( |
|
|
|
key, |
|
|
|
r'\\'.join([self.ref_to_str(ref) for ref in entry]), |
|
|
|
ur'\\'.join([self.ref_to_str(ref) for ref in entry]), |
|
|
|
) |
|
|
|
|
|
|
|
def idxblock_to_str(self, letter, entries): |
|
|
|