diff --git a/lua/typstar/snippets/math.lua b/lua/typstar/snippets/math.lua index 4da1b59..f3c578d 100644 --- a/lua/typstar/snippets/math.lua +++ b/lua/typstar/snippets/math.lua @@ -61,9 +61,9 @@ return { snip('sb', 'subset ', {}, math), snip('sep', 'supset.eq ', {}, math), snip('seb', 'subset.eq ', {}, math), - snip('nn', 'sect ', {}, math, 900), + snip('nn', 'inter ', {}, math, 900), snip('uu', 'union ', {}, math, 900), - snip('bnn', 'sect.big ', {}, math), + snip('bnn', 'inter.big ', {}, math), snip('buu', 'union.big ', {}, math), snip('swo', 'without ', {}, math), diff --git a/pyproject.toml b/pyproject.toml index b79757c..ba51394 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "pdm.backend" [project] name = "typstar" -version = "1.3.0" +version = "1.3.1" description = "Neovim plugin for efficient note taking in Typst" authors = [ { name = "arne314" } diff --git a/src/anki/config_parser.py b/src/anki/config_parser.py index af14679..90f2aa9 100644 --- a/src/anki/config_parser.py +++ b/src/anki/config_parser.py @@ -9,20 +9,20 @@ class RecursiveConfigParser: targets: set[str] results: dict[str, dict[Path, str]] - def __init__(self, dir, targets): + def __init__(self, dir, targets, recursive=True): self.dir = dir self.targets = set(targets) self.results = defaultdict(dict) - self._parse_recursive() + self._parse_dirs(recursive) - def _parse_recursive(self): + def _parse_dirs(self, recursive=True): files = [] for target in self.targets: - files.extend( - glob( - f"{self.dir}/**/{target}", include_hidden=target.startswith("."), recursive=True - ) - ) + if recursive: + dir = f"{self.dir}/**/{target}" + else: + dir = f"{self.dir}/{target}" + files.extend(glob(dir, include_hidden=target.startswith("."), recursive=recursive)) for file in files: file = Path(file) if file.name in self.targets: diff --git a/src/anki/parser.py b/src/anki/parser.py index 4ccc43b..cf3048a 100644 --- a/src/anki/parser.py +++ b/src/anki/parser.py @@ -126,7 +126,9 @@ class FlashcardParser: f"Parsing flashcards in {scan_dir if single_file is None else single_file} ...", flush=True, ) - configs = RecursiveConfigParser(root_dir, {".anki", ".anki.typ"}) + configs = RecursiveConfigParser( + root_dir, {".anki", ".anki.typ"}, recursive=single_file is None + ) for file in glob(f"{scan_dir}/**/**.typ", recursive=True): file = Path(file) diff --git a/src/anki/typst_compiler.py b/src/anki/typst_compiler.py index 3aaa504..83cfbad 100644 --- a/src/anki/typst_compiler.py +++ b/src/anki/typst_compiler.py @@ -1,6 +1,8 @@ import asyncio import os import random +import re +import sys from pathlib import Path from typing import List @@ -18,7 +20,7 @@ default_preamble = """ class TypstCompilationError(ValueError): - pass + regex = re.compile(r"\nerror: ") class TypstCompiler: @@ -48,7 +50,11 @@ class TypstCompiler: stdout, stderr = await proc.communicate() os.remove(tmp_path) 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 async def _compile_flashcard(self, card: Flashcard): diff --git a/uv.lock b/uv.lock index 8aed491..78a1ca7 100644 --- a/uv.lock +++ b/uv.lock @@ -437,7 +437,7 @@ wheels = [ [[package]] name = "typstar" -version = "1.2.0" +version = "1.3.1" source = { editable = "." } dependencies = [ { name = "aiohttp" },