Skip to content

Commit e096e06

Browse files
committed
Typst writer: properly handle data: URIs in images.
We need to produce an svg tag and parse it using `image.decode`. This is slightly roundabout but doesn't require any external libraries. Closes #10460.
1 parent 7a66c94 commit e096e06

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Text/Pandoc/Writers/Typst.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,11 @@ mkImage useBox src kvs
450450
Just v -> ", " <> literal k <> ": " <> literal v
451451
Nothing -> mempty
452452
dimAttrs = mconcat $ map toDimAttr ["height", "width"]
453-
coreImage = "image" <> parens (doubleQuoted src' <> dimAttrs)
453+
isData = "data:" `T.isPrefixOf` src'
454+
dataSvg = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><image xlink:href=\"" <> src' <> "\" /></svg>"
455+
coreImage
456+
| isData = "image.decode" <> parens(doubleQuoted dataSvg <> dimAttrs)
457+
| otherwise = "image" <> parens (doubleQuoted src' <> dimAttrs)
454458

455459
textstyle :: PandocMonad m => Doc Text -> [Inline] -> TW m (Doc Text)
456460
textstyle s inlines =

0 commit comments

Comments
 (0)