|
@ -8,19 +8,19 @@ will work on simple cases, but not on complex ones. |
|
|
import os |
|
|
import os |
|
|
|
|
|
|
|
|
from patacrep import files, encoding |
|
|
from patacrep import files, encoding |
|
|
from patacrep.latex import parse_song |
|
|
from patacrep.latex import parse_song, BABEL_LANGUAGES |
|
|
from patacrep.songs import Song |
|
|
from patacrep.songs import Song |
|
|
|
|
|
|
|
|
class LatexSong(Song): |
|
|
class LatexSong(Song): |
|
|
"""LaTeX song parser.""" |
|
|
"""LaTeX song parser.""" |
|
|
|
|
|
|
|
|
def _parse(self, __config): |
|
|
def _parse(self, __config): |
|
|
"""Parse content, and return the dictinory of song data.""" |
|
|
"""Parse content, and return the dictionary of song data.""" |
|
|
with encoding.open_read(self.fullpath, encoding=self.encoding) as song: |
|
|
with encoding.open_read(self.fullpath, encoding=self.encoding) as song: |
|
|
self.data = parse_song(song.read(), self.fullpath) |
|
|
self.data = parse_song(song.read(), self.fullpath) |
|
|
self.titles = self.data['@titles'] |
|
|
self.titles = self.data['@titles'] |
|
|
del self.data['@titles'] |
|
|
del self.data['@titles'] |
|
|
self.language = self.data['@language'] |
|
|
self.set_lang(self.data['@language']) |
|
|
del self.data['@language'] |
|
|
del self.data['@language'] |
|
|
if "by" in self.data: |
|
|
if "by" in self.data: |
|
|
self.authors = [self.data['by']] |
|
|
self.authors = [self.data['by']] |
|
@ -38,6 +38,18 @@ class LatexSong(Song): |
|
|
)) |
|
|
)) |
|
|
return r'\import{{{}/}}{{{}}}'.format(os.path.dirname(path), os.path.basename(path)) |
|
|
return r'\import{{{}/}}{{{}}}'.format(os.path.dirname(path), os.path.basename(path)) |
|
|
|
|
|
|
|
|
|
|
|
def set_lang(self, language): |
|
|
|
|
|
"""Set the language code""" |
|
|
|
|
|
for lang, babel_language in BABEL_LANGUAGES.items(): |
|
|
|
|
|
if language == babel_language: |
|
|
|
|
|
self.lang = lang |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
# Add a custom language to the babel dictionary (language is not officially supported) |
|
|
|
|
|
custom_lang = '_' + language |
|
|
|
|
|
BABEL_LANGUAGES[custom_lang] = language |
|
|
|
|
|
self.lang = custom_lang |
|
|
|
|
|
|
|
|
SONG_PARSERS = { |
|
|
SONG_PARSERS = { |
|
|
'is': LatexSong, |
|
|
'is': LatexSong, |
|
|
'sg': LatexSong, |
|
|
'sg': LatexSong, |
|
|