|
@ -8,7 +8,7 @@ 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 Latex2LatexSong(Song): |
|
|
class Latex2LatexSong(Song): |
|
@ -16,13 +16,13 @@ class Latex2LatexSong(Song): |
|
|
# pylint: disable=abstract-method |
|
|
# pylint: disable=abstract-method |
|
|
|
|
|
|
|
|
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.languages = self.data['@languages'] |
|
|
self.set_lang(self.data['@language']) |
|
|
del self.data['@languages'] |
|
|
del self.data['@language'] |
|
|
if "by" in self.data: |
|
|
if "by" in self.data: |
|
|
self.authors = [self.data['by']] |
|
|
self.authors = [self.data['by']] |
|
|
del self.data['by'] |
|
|
del self.data['by'] |
|
@ -40,6 +40,18 @@ class Latex2LatexSong(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_RENDERERS = { |
|
|
SONG_RENDERERS = { |
|
|
"latex": { |
|
|
"latex": { |
|
|
'is': Latex2LatexSong, |
|
|
'is': Latex2LatexSong, |
|
|