Skip to content

Commit

Permalink
use a second comprehension for imgAttrs
Browse files Browse the repository at this point in the history
  • Loading branch information
cscheid committed Apr 15, 2024
1 parent 7590aa9 commit 2fd0564
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/Text/Pandoc/SelfContained.hs
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,11 @@ combineSvgAttrs svgAttrs imgAttrs =
dropPointZero t = case T.stripSuffix ".0" t of
Nothing -> t
Just t' -> t'
combinedAttrs = replaceMaybe mergedClasses $ imgAttrs ++
combinedAttrs = imgAttrs ++
[(k, v) | (k, v) <- svgAttrs
, isNothing (lookup k imgAttrs)
, k `notElem` ["xmlns", "xmlns:xlink", "version"]]
, k `notElem` ["xmlns", "xmlns:xlink", "version", "class"]] ++
mergedClasses
parseViewBox t =
case map (safeRead . addZero) $ T.words t of
[Just llx, Just lly, Just urx, Just ury] -> Just (llx, lly, urx, ury)
Expand All @@ -276,11 +277,8 @@ combineSvgAttrs svgAttrs imgAttrs =
(mbWidth :: Maybe Int) = lookup "width" combinedAttrs >>= safeRead
-- https://github.com/jgm/pandoc/issues/9652
mergedClasses = case (lookup "class" imgAttrs, lookup "class" svgAttrs) of
(Just c1, Just c2) -> Just ("class", c1 <> " " <> c2)
_ -> Nothing
replaceMaybe :: Eq a => Maybe (a, b) -> [(a, b)] -> [(a, b)]
replaceMaybe Nothing = id
replaceMaybe (Just x) = map (\pair@(a, _) -> if a == fst x then x else pair)
(Just c1, Just c2) -> [("class", c1 <> " " <> c2)]
_ -> []

cssURLs :: PandocMonad m
=> FilePath -> ByteString -> m ByteString
Expand Down

0 comments on commit 2fd0564

Please sign in to comment.