@@ -665,11 +665,13 @@ directive' = do
665665 optional blanklines
666666 let body' = body ++ "\n\n"
667667 name = trim $ fromMaybe "" (lookup "name" fields)
668− imgAttr cl = ("", classes, widthAttr ++ heightAttr)
668+ classes = words $ maybe "" trim (lookup "class" fields)
669+ keyvals = [(k, trim v) | (k, v) <- fields, k /= "name", k /= "class"]
670+ imgAttr cl = ("", classes ++ alignClasses, widthAttr ++ heightAttr)
669671 where
670− classes = words $ maybe "" trim (lookup cl fields) ++
671− maybe "" (\x -> "align-" ++ trim x)
672− (lookup "align" fields)
672+ alignClasses = words $ maybe "" trim (lookup cl fields) ++
673+ maybe "" (\x -> "align-" ++ trim x)
674+ (lookup "align" fields)
673675 scale = case trim <$> lookup "scale" fields of
674676 Just v -> case reverse v of
675677 '%':vv ->
@@ -698,8 +700,9 @@ directive' = do
698700 "line-block" -> lineBlockDirective body'
699701 "raw" -> return $ B.rawBlock (trim top) (stripTrailingNewlines body)
700702 "role" -> addNewRole top $ map (second trim) fields
701− "container" -> B.divWith (name, "container" : words top, []) <$>
702− parseFromString' parseBlocks body'
703+ "container" -> B.divWith
704+ (name, "container" : words top ++ classes, []) <$>
705+ parseFromString' parseBlocks body'
703706 "replace" -> B.para <$> -- consumed by substKey
704707 parseInlineFromString (trim top)
705708 "unicode" -> B.para <$> -- consumed by substKey
@@ -717,7 +720,7 @@ directive' = do
717720 (l:ls) -> B.divWith ("",["admonition-title"],[])
718721 (B.para (B.str (toUpper l : ls)))
719722 [] -> mempty
720− return $ B.divWith ("",[label],[]) (lab <> bod)
723+ return $ B.divWith (name,label:classes,keyvals) (lab <> bod)
721724 "sidebar" ->
722725 do let subtit = maybe "" trim $ lookup "subtitle" fields
723726 tit <- B.para . B.strong <$> parseInlineFromString
@@ -725,21 +728,21 @@ directive' = do
725728 then ""
726729 else (": " ++ subtit))
727730 bod <- parseFromString' parseBlocks body'
728− return $ B.divWith ("",["sidebar"],[]) $ tit <> bod
731+ return $ B.divWith (name,"sidebar":classes,keyvals) $ tit <> bod
729732 "topic" ->
730733 do tit <- B.para . B.strong <$> parseInlineFromString top
731734 bod <- parseFromString' parseBlocks body'
732− return $ B.divWith ("",["topic"],[]) $ tit <> bod
735+ return $ B.divWith (name,"topic":classes,keyvals) $ tit <> bod
733736 "default-role" -> mempty <$ updateState (\s ->
734737 s { stateRstDefaultRole =
735738 case trim top of
736739 "" -> stateRstDefaultRole def
737740 role -> role })
738741 x | x == "code" || x == "code-block" ->
739− codeblock (words $ fromMaybe [] $ lookup "class" fields)
742+ codeblock name classes
740743 (lookup "number-lines" fields) (trim top) body
741744 "aafig" -> do
742− let attribs = ("", ["aafig"], map (second trimr) fields)
745+ let attribs = (name, ["aafig"], map (second trimr) fields)
743746 return $ B.codeBlockWith attribs $ stripTrailingNewlines body
744747 "math" -> return $ B.para $ mconcat $ map B.displayMath
745748 $ toChunks $ top ++ "\n\n" ++ body
@@ -758,8 +761,7 @@ directive' = do
758761 $ B.imageWith attr src "" alt
759762 Nothing -> B.imageWith attr src "" alt
760763 "class" -> do
761− let attrs = ("", splitBy isSpace $ trim top,
762− map (second trimr) fields)
764+ let attrs = (name, words (trim top), map (second trimr) fields)
763765 -- directive content or the first immediately following element
764766 children <- case body of
765767 "" -> block
@@ -769,7 +771,7 @@ directive' = do
769771 pos <- getPosition
770772 logMessage $ SkippedContent (".. " ++ other) pos
771773 bod <- parseFromString' parseBlocks $ top ++ "\n\n" ++ body'
772− return $ B.divWith ("",[other],[]) bod
774+ return $ B.divWith (name, other:classes, keyvals) bod
773775
774776tableDirective :: PandocMonad m
775777 => String -> [(String, String)] -> String -> RSTParser m Blocks
@@ -989,10 +991,11 @@ toChunks = dropWhile null
989991 then "\\begin{aligned}\n" ++ s ++ "\n\\end{aligned}"
990992 else s
991993
992−codeblock :: [String] -> Maybe String -> String -> String -> RSTParser m Blocks
993−codeblock classes numberLines lang body =
994+codeblock :: String -> [String] -> Maybe String -> String -> String
995+ -> RSTParser m Blocks
996+codeblock ident classes numberLines lang body =
994997 return $ B.codeBlockWith attribs $ stripTrailingNewlines body
995− where attribs = ("", classes', kvs)
998+ where attribs = (ident, classes', kvs)
996999 classes' = "sourceCode" : lang
9971000 : maybe [] (const ["numberLines"]) numberLines
9981001 ++ classes