mirror of
https://git.freetards.xyz/array.in.a.matrix/TexLiLy.git
synced 2025-04-02 13:21:42 -04:00
[ADD] Add custom version for inline .ly expressions
This commit is contained in:
parent
4d4aa7d5ab
commit
24182f3739
2 changed files with 12 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
||||||
template = r"""
|
template = r"""
|
||||||
|
{version]
|
||||||
\header {{
|
\header {{
|
||||||
tagline = ""
|
tagline = ""
|
||||||
}}
|
}}
|
||||||
|
@ -6,13 +7,16 @@ template = r"""
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def render(user: str, source: str, png: bool = True, template: bool = False) -> str:
|
def render(user: str, source: str, png: bool = True, version: str = None, template: bool = False) -> str:
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
import utils
|
import utils
|
||||||
import os
|
import os
|
||||||
|
versionstr = ""
|
||||||
|
if version is not None:
|
||||||
|
versionstr = r'\version "{version}"'.format(version=version)
|
||||||
|
|
||||||
fmt = template.format(content=source) if template else source
|
fmt = template.format(content=source, version=versionstr) if template else source
|
||||||
|
|
||||||
tmp = tempfile.NamedTemporaryFile(delete=False)
|
tmp = tempfile.NamedTemporaryFile(delete=False)
|
||||||
tmp.write(bytes(fmt, encoding="utf8"))
|
tmp.write(bytes(fmt, encoding="utf8"))
|
||||||
|
|
|
@ -34,9 +34,13 @@ async def route_delete(router: Router, client: Client, room: str, event: RoomMes
|
||||||
async def route_lshow(router: Router, client: Client, room: str, event: RoomMessageText, args: list) -> None:
|
async def route_lshow(router: Router, client: Client, room: str, event: RoomMessageText, args: list) -> None:
|
||||||
import lilypond
|
import lilypond
|
||||||
import utils
|
import utils
|
||||||
if len(args) == 1:
|
if len(args) >= 1:
|
||||||
try:
|
try:
|
||||||
file = lilypond.render("", args[0])
|
version = None
|
||||||
|
if len(args) == 2:
|
||||||
|
version = args[1]
|
||||||
|
|
||||||
|
file = lilypond.render("", args[0], version=version)
|
||||||
await utils.send_png(room, file)
|
await utils.send_png(room, file)
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
content = {
|
content = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue