From 3503882cf746cd1cfd403c5fe16a34d197bec9dd Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 26 Jun 2024 15:42:03 +0200 Subject: [PATCH 1/2] Fix windows quarto.cmd script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correctly check when QUARTO_DENO_ env var are set and only add flags to it if not present already. This is necessary for when we call quarto run from Lua inside quarto render as all the environment variables are passed to the child process and so they will be set. Soùe flags can't be duplicated like `--v8-flags` and create an error when running deno. --- package/scripts/windows/quarto.cmd | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/package/scripts/windows/quarto.cmd b/package/scripts/windows/quarto.cmd index ea57dab955f..dcc39a0742a 100644 --- a/package/scripts/windows/quarto.cmd +++ b/package/scripts/windows/quarto.cmd @@ -101,17 +101,31 @@ SET "DENO_TLS_CA_STORE=system,mozilla" SET "DENO_NO_UPDATE_CHECK=1" SET "QUARTO_DENO_OPTIONS=--unstable-ffi --no-config --cached-only --allow-read --allow-write --allow-run --allow-env --allow-net --allow-ffi" -REM --enable-experimental-regexp-engine is required for /regex/l, https://github.com/quarto-dev/quarto-cli/issues/9737 +REM Add expected V8 options to QUARTO_DENO_V8_OPTIONS IF DEFINED QUARTO_DENO_V8_OPTIONS ( - SET "QUARTO_DENO_V8_OPTIONS=--enable-experimental-regexp-engine,--max-old-space-size=8192,--max-heap-size=8192,!QUARTO_DENO_V8_OPTIONS!" + REM --enable-experimental-regexp-engine is required for /regex/l, https://github.com/quarto-dev/quarto-cli/issues/9737 + IF "!QUARTO_DENO_V8_OPTIONS!"=="!QUARTO_DENO_V8_OPTIONS:--enable-experimental-regexp-engine=!" ( + SET "QUARTO_DENO_V8_OPTIONS=--enable-experimental-regexp-engine,!QUARTO_DENO_V8_OPTIONS!" + ) + IF "!QUARTO_DENO_V8_OPTIONS!"=="!QUARTO_DENO_V8_OPTIONS:--max-old-space-size=!" ( + SET "QUARTO_DENO_V8_OPTIONS=--max-old-space-size=8192,!QUARTO_DENO_V8_OPTIONS!" + ) + IF "!QUARTO_DENO_V8_OPTIONS!"=="!QUARTO_DENO_V8_OPTIONS:--max-heap-size=!" ( + SET "QUARTO_DENO_V8_OPTIONS=--max-heap-size=8192,!QUARTO_DENO_V8_OPTIONS!" + ) ) ELSE ( SET "QUARTO_DENO_V8_OPTIONS=--enable-experimental-regexp-engine,--max-old-space-size=8192,--max-heap-size=8192" ) +REM Prepend v8-flags for deno run if necessary IF NOT DEFINED QUARTO_DENO_EXTRA_OPTIONS ( SET "QUARTO_DENO_EXTRA_OPTIONS=--v8-flags=!QUARTO_DENO_V8_OPTIONS!" ) ELSE ( - SET "QUARTO_DENO_EXTRA_OPTIONS=--v8-flags=!QUARTO_DENO_V8_OPTIONS! !QUARTO_DENO_EXTRA_OPTIONS!" + IF "!QUARTO_DENO_EXTRA_OPTIONS!"=="!QUARTO_DENO_EXTRA_OPTIONS:--v8-flags=!" ( + SET "QUARTO_DENO_EXTRA_OPTIONS=--v8-flags=!QUARTO_DENO_V8_OPTIONS! !QUARTO_DENO_EXTRA_OPTIONS!" + ) ELSE ( + ECHO WARN: QUARTO_DENO_EXTRA_OPTIONS already contains --v8-flags, skipping addition of QUARTO_DENO_V8_OPTIONS by quarto itself. This is unexpected and you should check your configuration. + ) ) !QUARTO_DENO! !QUARTO_ACTION! !QUARTO_DENO_OPTIONS! !QUARTO_DENO_EXTRA_OPTIONS! !QUARTO_IMPORT_MAP_ARG! !QUARTO_TARGET! %* From 0dbd854bb36af3b82c6e7273f7369cc359fb271e Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 26 Jun 2024 16:06:11 +0200 Subject: [PATCH 2/2] Protect against error in running juice - if io.popen failes to run program - if program fails to run somehow We return initial value in that case and log an error in Pandoc --- src/resources/filters/normalize/parsehtml.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/resources/filters/normalize/parsehtml.lua b/src/resources/filters/normalize/parsehtml.lua index 3e7c1cc0cd6..10a96065274 100644 --- a/src/resources/filters/normalize/parsehtml.lua +++ b/src/resources/filters/normalize/parsehtml.lua @@ -51,14 +51,21 @@ function parse_html_tables() jin:write(htmltext) jin:flush() local quarto_path = pandoc.path.join({os.getenv('QUARTO_BIN_PATH'), 'quarto'}) - local jout = io.popen(quarto_path .. ' run ' .. + local jout, jerr = io.popen(quarto_path .. ' run ' .. pandoc.path.join({os.getenv('QUARTO_SHARE_PATH'), 'scripts', 'juice.ts'}) .. ' ' .. juice_in, 'r') - if jout then - return jout:read('a') - else - quarto.log.error('failed to juice') + if not jout then + quarto.log.error('Running juice failed with message: ' .. (jerr or "Unknown error")) + return htmltext + end + local content = jout:read('a') + local success, _, exitCode = jout:close() + -- Check the exit status + if not success then + quarto.log.error("Running juice failed with exit code: " .. (exitCode or "unknown exit code")) return htmltext + else + return content end end) end