Browse Source

[WIP] Special characters: Song generation works. Songbook generation remains to implement

pull/213/head
Louis 9 years ago
parent
commit
dfc7762931
  1. 2
      patacrep/data/templates/songs/chordpro/latex/content_word
  2. 8
      patacrep/data/templates/songs/chordpro/latex/song
  3. 12
      patacrep/songs/chordpro/__init__.py
  4. 2
      test/test_song/special.csg.source
  5. 14
      test/test_songbook/special_datadir/songs/special.csg

2
patacrep/data/templates/songs/chordpro/latex/content_word

@ -1 +1 @@
(( content.value )) (( content.value|escape_specials('{}&#_^%~$\\') ))

8
patacrep/data/templates/songs/chordpro/latex/song

@ -8,7 +8,7 @@
\beginsong{ \beginsong{
(*- for title in titles -*) (*- for title in titles -*)
(( title )) (( title|escape_specials('{}&#_^%~$\\') ))
(*- if not loop.last -*) (*- if not loop.last -*)
\\ \\
(* endif *) (* endif *)
@ -16,7 +16,7 @@
}[ }[
by={ by={
(* for author in authors *) (* for author in authors *)
(( author[1] )) (( author[0] )) (( author[1]|escape_specials('{}&#_^%~$\\') )) (( author[0]|escape_specials('{}&#_^%~$\\') ))
(*- if not loop.last -*) (*- if not loop.last -*)
, ,
(* endif *) (* endif *)
@ -24,7 +24,7 @@
}, },
(* for key in ['album', 'copyright'] *) (* for key in ['album', 'copyright'] *)
(* if key in metadata *) (* if key in metadata *)
(( key ))={(( metadata[key] ))}, (( key ))={(( metadata[key]|escape_specials('{}&#_^%~$\\') ))},
(* endif *) (* endif *)
(* endfor *) (* endfor *)
(* if 'cover' in metadata *) (* if 'cover' in metadata *)
@ -36,7 +36,7 @@
(* endblock *) (* endblock *)
(* endif *) (* endif *)
(* for key in metadata.morekeys *) (* for key in metadata.morekeys *)
(( key.keyword ))={(( key.argument ))}, (( key.keyword ))={(( key.argument|escape_specials('{}&#_^%~$\\') ))},
(* endfor *) (* endfor *)
] ]

12
patacrep/songs/chordpro/__init__.py

@ -113,6 +113,18 @@ class Chordpro2LatexSong(ChordproSong):
"""Render chordpro song to latex code""" """Render chordpro song to latex code"""
output_language = "latex" output_language = "latex"
_translation_map = {
'{': r'\{',
'}': r'\}',
'\\': r'\textbackslash{}',
'^': r'\textasciicircum{}',
'~': r'\textasciitilde{}',
'#': r'\#',
'&': r'\&',
'$': r'\$',
'%': r'\%',
'_': r'\_',
}
def search_file(self, filename, extensions=None, *, datadirs=None): def search_file(self, filename, extensions=None, *, datadirs=None):
_datadir, filename, _extension = self.search_datadir_file( _datadir, filename, _extension = self.search_datadir_file(

2
test/test_song/special.csg.source

@ -1,7 +1,7 @@
TODO url ?
{title: & $ % # _ \} \{ ~ ^ \\} {title: & $ % # _ \} \{ ~ ^ \\}
{artist: & $ % # _ \} \{ ~ ^ \\} {artist: & $ % # _ \} \{ ~ ^ \\}
{album: & $ % # _ \} \{ ~ ^ \\} {album: & $ % # _ \} \{ ~ ^ \\}
{url: & $ % # _ \} \{ ~ ^ \\}
& $ % \# _ \} \{ ~ ^ \\ & $ % \# _ \} \{ ~ ^ \\

14
test/test_songbook/special_datadir/songs/special.csg

@ -1,8 +1,10 @@
{title : & % $ \# _ \} \{ ~ ^ \\ } {title: & $ % # _ \} \{ ~ ^ \\}
{by: & % $ \# _ }\ \{ ~ ^ \\ } {artist: & $ % # _ \} \{ ~ ^ \\}
{album: & $ % # _ \} \{ ~ ^ \\}
{url: & $ % # _ \} \{ ~ ^ \\}
& % $ \# _ }\ \{ ~ ^ \\ & $ % \# _ \} \{ ~ ^ \\
{soc} {start_of_chorus}
& % $ \# _ }\ \{ ~ ^ \\ & $ % \# _ \} \{ ~ ^ \\
{eoc} {end_of_chorus}

Loading…
Cancel
Save