From 5489cf885455efc2406d7022eabafdd44f3bbdb0 Mon Sep 17 00:00:00 2001 From: Rowan Cockett Date: Sat, 12 Aug 2023 15:43:13 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Catch=20errors=20with=20typst=20?= =?UTF-8?q?conversion=20(#218)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/gorgeous-socks-sort.md | 5 +++++ packages/myst-demo/src/index.tsx | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 .changeset/gorgeous-socks-sort.md diff --git a/.changeset/gorgeous-socks-sort.md b/.changeset/gorgeous-socks-sort.md new file mode 100644 index 000000000..d7d0a66da --- /dev/null +++ b/.changeset/gorgeous-socks-sort.md @@ -0,0 +1,5 @@ +--- +'myst-demo': patch +--- + +Catch errors with typst conversion diff --git a/packages/myst-demo/src/index.tsx b/packages/myst-demo/src/index.tsx index 40493a574..fbc2f104c 100644 --- a/packages/myst-demo/src/index.tsx +++ b/packages/myst-demo/src/index.tsx @@ -137,9 +137,19 @@ async function parse( .use(mystToTex, { references }) .stringify(mdast as any, texFile).result as LatexResult; const typstFile = new VFile(); - const typst = unified() - .use(mystToTypst) - .stringify(mdast as any, typstFile).result as TypstResult; + let typst: TypstResult; + try { + typst = unified() + .use(mystToTypst) + .stringify(mdast as any, typstFile).result as TypstResult; + } catch (error) { + console.error(error); + typst = { + value: `Problem with typst conversion: ${(error as Error).message || 'Unknown Error'}`, + macros: [], + commands: {}, + }; + } const jatsFile = new VFile(); const jats: any = mystToJats ? unified()