Skip to content

Commit

Permalink
Typst writer: properly handle data: URIs in images.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jgm committed Dec 18, 2024
1 parent 7a66c94 commit e096e06
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Text/Pandoc/Writers/Typst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,11 @@ mkImage useBox src kvs
Just v -> ", " <> literal k <> ": " <> literal v
Nothing -> mempty
dimAttrs = mconcat $ map toDimAttr ["height", "width"]
coreImage = "image" <> parens (doubleQuoted src' <> dimAttrs)
isData = "data:" `T.isPrefixOf` src'
dataSvg = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><image xlink:href=\"" <> src' <> "\" /></svg>"
coreImage
| isData = "image.decode" <> parens(doubleQuoted dataSvg <> dimAttrs)
| otherwise = "image" <> parens (doubleQuoted src' <> dimAttrs)

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

0 comments on commit e096e06

Please sign in to comment.