From 766ae2d5ea714be2aa7d5d2895319c3070d2403c Mon Sep 17 00:00:00 2001 From: arne314 <73391160+arne314@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:51:26 +0100 Subject: [PATCH 1/4] fix(anki): handle typst compilation warnings --- src/anki/typst_compiler.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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): From f204b74eae19c45c7ca00dffac141b4ece182bdc Mon Sep 17 00:00:00 2001 From: arne314 <73391160+arne314@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:59:20 +0100 Subject: [PATCH 2/4] minor(snip)!: `sect` -> `inter` as in typst `0.13` --- lua/typstar/snippets/math.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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), From f56e84331c7a6b6662dfda77a0c3d1d7a0b5ff59 Mon Sep 17 00:00:00 2001 From: arne314 <73391160+arne314@users.noreply.github.com> Date: Sun, 9 Mar 2025 12:09:59 +0100 Subject: [PATCH 3/4] fix(anki): no recursive config dir for single file --- src/anki/config_parser.py | 16 ++++++++-------- src/anki/parser.py | 4 +++- 2 files changed, 11 insertions(+), 9 deletions(-) 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) From 89226e576f0c19624e6e09de045e4b75dc1ae446 Mon Sep 17 00:00:00 2001 From: arne314 <73391160+arne314@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:23:10 +0100 Subject: [PATCH 4/4] chore: bump version to `1.3.0` --- pyproject.toml | 2 +- uv.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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" },