Skip to content

Commit e099990

Browse files
claude: Write mediabag entries to disk when bypassing Pandoc Image handling
When returning a RawInline instead of an Image element for Typst alt text support, Pandoc doesn't write mediabag entries to disk. This caused data URI images (like from the placeholder shortcode) and URL images to fail because the file was never extracted. Now explicitly call write_mediabag_entry() before returning RawInline to ensure the image file exists on disk. Adds test for URL image mediabag handling that verifies: - Image is extracted to mediabag directory - Raw URL is not present in output Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 84f9c60 commit e099990

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎src/resources/filters/quarto-post/typst.lua‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,19 @@ function render_typst_fixups()
103103
end
104104

105105
if alt_text and #alt_text > 0 then
106+
-- When returning RawInline instead of Image, Pandoc won't write mediabag
107+
-- entries to disk, so we must do it explicitly
108+
local src = image.src
109+
local mediabagPath = _quarto.modules.mediabag.write_mediabag_entry(src)
110+
if mediabagPath then
111+
src = mediabagPath
112+
end
113+
106114
-- Build image() parameters
107115
local params = {}
108116

109117
-- Source path (escape backslashes for Windows paths)
110-
local src = image.src:gsub('\\', '\\\\')
118+
src = src:gsub('\\', '\\\\')
111119
table.insert(params, '"' .. src .. '"')
112120

113121
-- Alt text second (escape backslashes and quotes)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: URL image mediabag handling
3+
format: typst
4+
keep-typ: true
5+
_quarto:
6+
tests:
7+
typst:
8+
ensureTypstFileRegexMatches:
9+
# Image should be extracted to mediabag, not remain as URL
10+
- ['image\("url-image-mediabag_files(/|\\\\)mediabag(/|\\\\)400']
11+
# Should NOT contain the raw URL - it must be extracted to mediabag
12+
- ['https://placehold\.co/400']
13+
---
14+
15+
# URL Image Test
16+
17+
This tests that URL images are correctly extracted to the mediabag
18+
when rendering to Typst format. The image below should be fetched
19+
from the URL and stored locally, not left as a raw URL.
20+
21+
![Placeholder image from URL](https://placehold.co/400){alt="A 400x400 placeholder image"}

0 commit comments

Comments
 (0)