diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs
index c20492d9e14f..4aa32ca0069b 100644
--- a/src/Text/Pandoc/SelfContained.hs
+++ b/src/Text/Pandoc/SelfContained.hs
@@ -258,10 +258,13 @@ combineSvgAttrs svgAttrs imgAttrs =
dropPointZero t = case T.stripSuffix ".0" t of
Nothing -> t
Just t' -> t'
- combinedAttrs = imgAttrs ++
+ combinedAttrs =
+ [(k, v) | (k, v) <- imgAttrs
+ , k /= "class"] ++
[(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)
@@ -274,6 +277,9 @@ combineSvgAttrs svgAttrs imgAttrs =
lookup "viewBox" svgAttrs >>= parseViewBox
(mbHeight :: Maybe Int) = lookup "height" combinedAttrs >>= safeRead
(mbWidth :: Maybe Int) = lookup "width" combinedAttrs >>= safeRead
+ mergedClasses = case (lookup "class" imgAttrs, lookup "class" svgAttrs) of
+ (Just c1, Just c2) -> [("class", c1 <> " " <> c2)]
+ _ -> []
cssURLs :: PandocMonad m
=> FilePath -> ByteString -> m ByteString
diff --git a/test/command/9652.md b/test/command/9652.md
new file mode 100644
index 000000000000..e3f586d7fa84
--- /dev/null
+++ b/test/command/9652.md
@@ -0,0 +1,9 @@
+````
+% pandoc -f markdown -t html --embed-resources
+```{=html}
+
+```
+^D
+
+````
diff --git a/test/command/9652.svg b/test/command/9652.svg
new file mode 100644
index 000000000000..70063b873389
--- /dev/null
+++ b/test/command/9652.svg
@@ -0,0 +1,3 @@
+
+