-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
from django.utils.encoding import smart_text | ||
from django.conf.global_settings import LANGUAGES | ||
|
||
from songbook_core.plastex import parsetex | ||
from songbook_core.plastex import parsetex, SongParser | ||
|
||
from generator.models import Song, Artist | ||
|
||
|
@@ -30,55 +30,33 @@ | |
import sys | ||
import pprint | ||
|
||
_BLOCKS_PATTERNS = [(r"\beginverse", '<p class="verse" >'), | ||
(r"\begin{verse}", '<p class="verse" >'), | ||
(r"\beginverse*", '<p class="verse_star" >'), | ||
(r"\begin{verse*}", '<p class="verse_star" >'), | ||
(r"\beginchorus", '<p class="chorus" >'), | ||
(r"\begin{chorus}", '<p class="chorus" >'), | ||
] | ||
|
||
_BLOCKS_PATTERNS += [(r"\endverse", '</p>'), | ||
(r"\end{verse}", '</p>'), | ||
(r"\end{verse*}", '</p>'), | ||
(r"\end{chorus}", '</p>'), | ||
] | ||
|
||
|
||
def parse_chords(content): | ||
content = re.sub('\\\\\\[(.*?)\]({[^\\\\\s\n]*}|[^\\\\\s\n]*)', | ||
'<span class="chord"><span class="chord-name">\g<1></span>' | ||
'<span class="chord-text">\g<2></span></span>', | ||
content) | ||
content = content.replace('&', "♭") | ||
content = content.replace('#', "♯ ") | ||
return content | ||
|
||
|
||
def parse_blocks(content): | ||
for TeX, HTML in _BLOCKS_PATTERNS: | ||
content = content.replace(TeX, HTML) | ||
return content | ||
|
||
|
||
def parse_unsuported(content): | ||
# remove the beggining of the song | ||
content = re.sub('^(.*?)<p', '<p', content, flags=re.DOTALL) | ||
|
||
# remove all other commands | ||
content = re.sub(r'\\(\w*)[(.*)]{(.*)}', '', content) | ||
content = re.sub(r'\\(\w*){(.*)}', '', content) | ||
content = re.sub(r'\\(\w*)', '', content) | ||
|
||
content = re.sub(r'{|}', '', content) | ||
return content | ||
|
||
|
||
def parse_song(content): | ||
content = parse_blocks(content) | ||
content = parse_chords(content) | ||
content = parse_unsuported(content) | ||
return content | ||
def parse_song(filename): | ||
tex = SongParser.parse(filename) | ||
in_song = False | ||
res = "" | ||
|
||
for node in tex.allChildNodes: | ||
if node.nodeName in ["chorus", "verse", "verse*", "bridge"]: | ||
if not in_song: | ||
in_song = True | ||
part_name = node.nodeName | ||
part_name.replace("*", "_star") | ||
res += '<p class="{node}">\n'.format(node=node.nodeName) | ||
elif node.nodeName == "par" and in_song: | ||
res += '\n</p>\n' | ||
elif node.nodeName == "chord" and in_song: | ||
res += '<span class="chord"><span class="chord-name">' | ||
for subnode in node.allChildNodes: | ||
res += subnode | ||
res += '</span><span class="chord-text">' | ||
# TODO: get chord text | ||
res += '</span></span>' | ||
# TODO: advance in the loop | ||
elif node.nodeName == "#text" and in_song: | ||
res += node | ||
res = res.replace('&', "♭") | ||
res = res.replace('#', "♯ ") | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Luthaf
Author
Contributor
|
||
return res | ||
|
||
# TODO: Write all the output to a log file | ||
def import_song(repo, filepath): | ||
|
5 comments
on commit c8d8013
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pour le rendu, tu as regardé du côté des renderers, plutôt que de tout refaire à la main ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oui, mais les renderers ne semblait pas pratique a intégrer dans le processus de rendu des templates Django, sauf a écrire des fichiers temporaires.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oui, mais les renderers ne semblait pas pratique a intégrer dans le processus de rendu des templates Django, sauf a écrire des fichiers temporaires.
J'ai l'impression qu'avec ce système, vous vous limitez à rendre uniquement les caractères, et interdisez les commandes LaTeX (à moins de faire un cas spécifique pour chaque commande gérée). Ça n'est pas mauvais en soi (ça ne me gêne pas qu'on limite à des caractères ce qui peut être inclus dans une chanson), mais c'est bien d'en être conscient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'ai l'impression qu'avec ce système, vous vous limitez à rendre uniquement les caractères, et interdisez les commandes LaTeX
Tu as un exemple ? On ignore en effet les commandes comme \emph
et compagnie, mais plasTeX est la pour nous permettre d’accéder au texte, non ?
Pour info, j'ai des problèmes d'encodage de caractères ici : j'ai du modifier ces caractères pour pouvoir lancer le serveur.