git.iko.soy/typeable/pandoc
on master help sign in
Fix regression with --metadata.
fef5770John MacFarlane
src/Text/Pandoc/App.hs+10−4
@@ -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
723 }
723 }
724
724
725−addMetadata :: (String, String) -> Pandoc -> Pandoc
725+addMetadata :: [(String, String)] -> Pandoc -> Pandoc
726+addMetadata kvs pdc = foldr addMeta (removeMetaKeys kvs pdc) kvs
727+
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
733
736
737+removeMetaKeys :: [(String,String)] -> Pandoc -> Pandoc
738+removeMetaKeys kvs pdc = foldr (deleteMeta . fst) pdc kvs
739+
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
test/command/4054.mdnew file+14
@@ -0,0 +1,14 @@
1+```
2+% pandoc -t native -s -M title=New
3+% Old
4+^D
5+Pandoc (Meta {unMeta = fromList [("title",MetaString "New")]})
6+[]
7+```
8+
9+```
10+% pandoc -t native -s -M foo=1 -M foo=2
11+^D
12+Pandoc (Meta {unMeta = fromList [("foo",MetaList [MetaString "1",MetaString "2"])]})
13+[]
14+```