@@ -557,7 +557,18 @@ pFigure = try $ do
557pCodeBlock :: PandocMonad m => TagParser m Blocks
557pCodeBlock :: PandocMonad m => TagParser m Blocks
558pCodeBlock = try $ do
558pCodeBlock = try $ do
559 TagOpen _ attr' <- pSatisfy (matchTagOpen "pre" [])
559 TagOpen _ attr' <- pSatisfy (matchTagOpen "pre" [])
560− let attr = toAttr attr'
560+ -- if the `pre` has no attributes, try if it is followed by a `code`
561+ -- element and use those attributes if possible.
562+ attr <- case attr' of
563+ _:_ -> pure (toAttr attr')
564+ [] -> option nullAttr $ do
565+ TagOpen _ codeAttr <- pSatisfy (matchTagOpen "code" [])
567+ [ (k, v') | (k, v) <- codeAttr
568+ -- strip language from class
569+ , let v' = if k == "class"
570+ then fromMaybe v (T.stripPrefix "language-" v)
561 contents <- manyTill pAny (pCloses "pre" <|> eof)
572 contents <- manyTill pAny (pCloses "pre" <|> eof)
562 let rawText = T.concat $ map tagToText contents
573 let rawText = T.concat $ map tagToText contents
563 -- drop leading newline if any
574 -- drop leading newline if any