mirror of
https://git.freetards.xyz/array.in.a.matrix/TexLiLy.git
synced 2025-04-02 13:21:42 -04:00
27 lines
744 B
Python
27 lines
744 B
Python
template = r"""
|
|
\header {{
|
|
tagline = ""
|
|
}}
|
|
{content}
|
|
"""
|
|
|
|
def render(user: str, source: str, png: bool = True) -> str:
|
|
import tempfile
|
|
import subprocess
|
|
import utils
|
|
import os
|
|
|
|
fmt = template.format(content=source)
|
|
|
|
tmp = tempfile.NamedTemporaryFile(delete=False)
|
|
tmp.write(bytes(fmt, encoding="utf8"))
|
|
tmp.close()
|
|
if png:
|
|
ret = subprocess.run(["lilypond", "-d", "preview", "--png", "-dresolution=500", tmp.name], cwd="/tmp", capture_output=True)
|
|
if ret.returncode != 0:
|
|
raise FileNotFoundError(ret.stderr.decode())
|
|
|
|
return tmp.name + ".preview.png"
|
|
|
|
subprocess.run(["lilypond", "-d", "preview", "--svg", tmp.name], cwd="/tmp")
|
|
return tmp.name + "preview.svg"
|