mirror of
https://github.com/Ascyii/typstar.git
synced 2026-01-01 05:24:24 -05:00
fix(anki): handle typst compilation warnings
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
@@ -18,7 +20,7 @@ default_preamble = """
|
|||||||
|
|
||||||
|
|
||||||
class TypstCompilationError(ValueError):
|
class TypstCompilationError(ValueError):
|
||||||
pass
|
regex = re.compile(r"\nerror: ")
|
||||||
|
|
||||||
|
|
||||||
class TypstCompiler:
|
class TypstCompiler:
|
||||||
@@ -48,7 +50,11 @@ class TypstCompiler:
|
|||||||
stdout, stderr = await proc.communicate()
|
stdout, stderr = await proc.communicate()
|
||||||
os.remove(tmp_path)
|
os.remove(tmp_path)
|
||||||
if stderr:
|
if stderr:
|
||||||
raise TypstCompilationError(bytes.decode(stderr, encoding="utf-8"))
|
err = bytes.decode(stderr, encoding="utf-8")
|
||||||
|
if TypstCompilationError.regex.search("\n" + err):
|
||||||
|
raise TypstCompilationError(err)
|
||||||
|
else:
|
||||||
|
print(f"Typst compilation warning:\n{err}", file=sys.stderr, flush=True)
|
||||||
return stdout
|
return stdout
|
||||||
|
|
||||||
async def _compile_flashcard(self, card: Flashcard):
|
async def _compile_flashcard(self, card: Flashcard):
|
||||||
|
|||||||
Reference in New Issue
Block a user