diff options
| author | John MacFarlane <[email protected]> | 2024-06-10 10:59:16 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-06-10 10:59:16 -0700 |
| commit | f2092f82ff1741a3b2a34f9fc53dc39fc6dccda6 (patch) | |
| tree | ea57118c6d8b7ebe41417fffdd9bb2c36fab7a11 /src/Text | |
| parent | 71e17b83b9c384e466d0a67753350280841557db (diff) | |
SelfContained: only create svg elements for SVG images when...
...the image has the class `inline-svg`. Otherwise just use a
`data` URI as we do with other images.
Closes #9787.
Diffstat (limited to 'src/Text')
| -rw-r--r-- | src/Text/Pandoc/SelfContained.hs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs index c4e97c953..b36d0df98 100644 --- a/src/Text/Pandoc/SelfContained.hs +++ b/src/Text/Pandoc/SelfContained.hs @@ -145,7 +145,11 @@ convertTags (t@(TagOpen "link" as):ts) = convertTags (t@(TagOpen tagname as):ts) | any (isSourceAttribute tagname) as = do - as' <- mapM processAttribute as + let inlineSvgs = tagname == "img" && + case T.words <$> lookup "class" as of + Nothing -> False + Just cs -> "inline-svg" `elem` cs + as' <- mapM (processAttribute inlineSvgs) as let attrs = addRole "img" $ addAriaLabel $ rights as' let svgContents = lefts as' rest <- convertTags ts @@ -200,13 +204,13 @@ convertTags (t@(TagOpen tagname as):ts) return $ TagOpen "svg" attrs'' : map ensureUniqueId tags' ++ rest' _ -> return $ TagOpen tagname attrs : rest - where processAttribute (x,y) = + where processAttribute inlineSvgs (x,y) = if isSourceAttribute tagname (x,y) then do res <- getData (fromAttrib "type" t) y case res of AlreadyDataURI enc -> return $ Right (x, enc) - Fetched ("image/svg+xml", bs) -> do + Fetched ("image/svg+xml", bs) | inlineSvgs -> do -- we filter CR in the hash to ensure that Windows -- and non-Windows tests agree: let hash = T.pack $ take 20 $ showDigest $ |
