diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2022-04-28 15:49:20 -0700 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2022-04-28 15:49:20 -0700 |
| commit | c1105e6b06d7436f43236191e32156a863de0e13 (patch) | |
| tree | 0c511b4ae700900fe49a69c8c3ed0f0a546357c0 /src/Text | |
| parent | c05f95773d21061f67494511652fe76a4f2708c1 (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.hs | 12 |
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)] |
