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