@@ -76,7 +76,7 @@ import qualified System.IO as IO (Newline (..))
76import System.IO.Error (isDoesNotExistError)
76import System.IO.Error (isDoesNotExistError)
77import Text.Pandoc
77import Text.Pandoc
78import Text.Pandoc.BCP47 (Lang (..), parseBCP47)
78import Text.Pandoc.BCP47 (Lang (..), parseBCP47)
79−import Text.Pandoc.Builder (setMeta)
79+import Text.Pandoc.Builder (setMeta, deleteMeta)
80import Text.Pandoc.Highlighting (highlightingStyles)
80import Text.Pandoc.Highlighting (highlightingStyles)
81import Text.Pandoc.Lua (LuaException (..), runLuaFilter)
81import Text.Pandoc.Lua (LuaException (..), runLuaFilter)
82import Text.Pandoc.PDF (makePDF)
82import Text.Pandoc.PDF (makePDF)
@@ -494,7 +494,7 @@ convertWithOpts opts = do
494 ( (if isJust (optExtractMedia opts)
494 ( (if isJust (optExtractMedia opts)
495 then fillMediaBag
495 then fillMediaBag
496 else return)
496 else return)
497− >=> return . flip (foldr addMetadata) metadata
497+ >=> return . addMetadata metadata
498 >=> applyLuaFilters datadir (optLuaFilters opts) format
498 >=> applyLuaFilters datadir (optLuaFilters opts) format
499 >=> maybe return extractMedia (optExtractMedia opts)
499 >=> maybe return extractMedia (optExtractMedia opts)
500 >=> applyTransforms transforms
500 >=> applyTransforms transforms
@@ -722,8 +722,11 @@ defaultOpts = Opt
722 , optStripComments = False
722 , optStripComments = False
725−addMetadata :: (String, String) -> Pandoc -> Pandoc
725+addMetadata :: [(String, String)] -> Pandoc -> Pandoc
726+addMetadata kvs pdc = foldr addMeta (removeMetaKeys kvs pdc) kvs
728+addMeta :: (String, String) -> Pandoc -> Pandoc
726−addMetadata (k, v) (Pandoc meta bs) = Pandoc meta' bs
729+addMeta (k, v) (Pandoc meta bs) = Pandoc meta' bs
727 where meta' = case lookupMeta k meta of
730 where meta' = case lookupMeta k meta of
728 Nothing -> setMeta k v' meta
731 Nothing -> setMeta k v' meta
729 Just (MetaList xs) ->
732 Just (MetaList xs) ->
@@ -731,6 +734,9 @@ addMetadata (k, v) (Pandoc meta bs) = Pandoc meta' bs
731 Just x -> setMeta k (MetaList [x, v']) meta
734 Just x -> setMeta k (MetaList [x, v']) meta
732 v' = readMetaValue v
735 v' = readMetaValue v
737+removeMetaKeys :: [(String,String)] -> Pandoc -> Pandoc
738+removeMetaKeys kvs pdc = foldr (deleteMeta . fst) pdc kvs
734readMetaValue :: String -> MetaValue
740readMetaValue :: String -> MetaValue
735readMetaValue s = case decode (UTF8.fromString s) of
741readMetaValue s = case decode (UTF8.fromString s) of
736 Just (Yaml.String t) -> MetaString $ T.unpack t
742 Just (Yaml.String t) -> MetaString $ T.unpack t