Skip to content

Commit 52ee4f1

Browse files
authored
SelfContained: merge 'class' attr when both img and svg specify it (#9653)
Closes #9652.
1 parent dafa7a2 commit 52ee4f1

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/Text/Pandoc/SelfContained.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,13 @@ combineSvgAttrs svgAttrs imgAttrs =
258258
dropPointZero t = case T.stripSuffix ".0" t of
259259
Nothing -> t
260260
Just t' -> t'
261-
combinedAttrs = imgAttrs ++
261+
combinedAttrs =
262+
[(k, v) | (k, v) <- imgAttrs
263+
, k /= "class"] ++
262264
[(k, v) | (k, v) <- svgAttrs
263265
, isNothing (lookup k imgAttrs)
264-
, k `notElem` ["xmlns", "xmlns:xlink", "version"]]
266+
, k `notElem` ["xmlns", "xmlns:xlink", "version", "class"]] ++
267+
mergedClasses
265268
parseViewBox t =
266269
case map (safeRead . addZero) $ T.words t of
267270
[Just llx, Just lly, Just urx, Just ury] -> Just (llx, lly, urx, ury)
@@ -274,6 +277,9 @@ combineSvgAttrs svgAttrs imgAttrs =
274277
lookup "viewBox" svgAttrs >>= parseViewBox
275278
(mbHeight :: Maybe Int) = lookup "height" combinedAttrs >>= safeRead
276279
(mbWidth :: Maybe Int) = lookup "width" combinedAttrs >>= safeRead
280+
mergedClasses = case (lookup "class" imgAttrs, lookup "class" svgAttrs) of
281+
(Just c1, Just c2) -> [("class", c1 <> " " <> c2)]
282+
_ -> []
277283

278284
cssURLs :: PandocMonad m
279285
=> FilePath -> ByteString -> m ByteString

test/command/9652.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
````
2+
% pandoc -f markdown -t html --embed-resources
3+
```{=html}
4+
<img class="something" src="9652.svg" />
5+
```
6+
^D
7+
<svg id="svg_b627f92299158b36552b" role="img" class="something please-do-not-delete-me" width="504.00pt" height="360.00pt" viewBox="0 0 504.00 360.00">
8+
</svg>
9+
````

test/command/9652.svg

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)