summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-04-28 15:49:20 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2022-04-28 15:49:20 -0700
commitc1105e6b06d7436f43236191e32156a863de0e13 (patch)
tree0c511b4ae700900fe49a69c8c3ed0f0a546357c0 /src/Text
parentc05f95773d21061f67494511652fe76a4f2708c1 (diff)
HTML writer: avoid doubled style attribute...
when height and width are added to style because of an image, but the image already has a style attribute. Closes #8047.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 418155f77..59196a27a 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -686,19 +686,13 @@ attrsToHtml opts (id',classes',keyvals) = do
imgAttrsToHtml :: PandocMonad m
=> WriterOptions -> Attr -> StateT WriterState m [Attribute]
imgAttrsToHtml opts attr = do
- attrs <- attrsToHtml opts (ident,cls,kvs')
- dimattrs <- toAttrs (dimensionsToAttrList attr)
- return $ attrs ++ dimattrs
+ attrsToHtml opts (ident,cls, consolidateStyles (kvs' ++ dimensionsToAttrList attr))
where
(ident,cls,kvs) = attr
kvs' = filter isNotDim kvs
isNotDim ("width", _) = False
isNotDim ("height", _) = False
isNotDim _ = True
-
-dimensionsToAttrList :: Attr -> [(Text, Text)]
-dimensionsToAttrList attr = consolidateStyles $ go Width ++ go Height
- where
consolidateStyles :: [(Text, Text)] -> [(Text, Text)]
consolidateStyles xs =
case partition isStyle xs of
@@ -706,6 +700,10 @@ dimensionsToAttrList attr = consolidateStyles $ go Width ++ go Height
(ss, rest) -> ("style", T.intercalate ";" $ map snd ss) : rest
isStyle ("style", _) = True
isStyle _ = False
+
+dimensionsToAttrList :: Attr -> [(Text, Text)]
+dimensionsToAttrList attr = go Width ++ go Height
+ where
go dir = case dimension dir attr of
(Just (Pixel a)) -> [(tshow dir, tshow a)]
(Just x) -> [("style", tshow dir <> ":" <> tshow x)]