From cf3927ebe152269b62947af31eea9e69f43bb4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sat, 27 Jun 2026 15:55:25 +0200 Subject: [PATCH] fix(filters): fix include-dark with {{< meta >}}-resolved image paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quarto adds a spurious extension when an image src is resolved via {{< meta >}}, turning foo.png into foo.png.png. The include-dark.lua filter then produced foo.png-dark.png (dark) and foo.png.png (light), neither of which exists on disk. Detect the double-extension case by checking whether the stem returned by split_extension itself carries the same extension (e.g. foo.png has stem foo and ext .png, then split_extension(foo) has no extension, so no double; but foo.png.png has stem foo.png and ext .png, then split_extension(foo.png) also returns .png — same extension twice). Strip the outer spurious extension before generating the dark/light pair. Closes quarto-dev/quarto-cli#14583 --- filters/include-dark.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/filters/include-dark.lua b/filters/include-dark.lua index 9158098981..4804d8b749 100644 --- a/filters/include-dark.lua +++ b/filters/include-dark.lua @@ -3,7 +3,7 @@ local function dark_path(src) return path[1] .. "-dark" .. path[2] end -local function new_image(img, src, class) +local function new_image(img, src, class) local new_classes = pandoc.List.filter(img.classes, function(c) return c ~= "include-dark" end) @@ -15,10 +15,14 @@ end function Image(img) if img.classes:includes("include-dark") then - local dark_img = new_image(img, dark_path(img.src), "dark-content") - local light_img = new_image(img, img.src, "light-content") + local stem, ext = pandoc.path.split_extension(img.src) + local _, inner_ext = pandoc.path.split_extension(stem) + -- Quarto adds a spurious extension when src is resolved via {{< meta >}}; + -- strip it when the same extension appears twice (e.g. foo.png.png). + local src = (inner_ext == ext) and stem or img.src + local dark_img = new_image(img, dark_path(src), "dark-content") + local light_img = new_image(img, src, "light-content") return {dark_img, light_img} end return img end -