diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-11-08 21:54:23 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-11-08 21:54:23 -0800 |
commit | fef5770591e7d3a185dc8d7dc2b70594732b0367 (patch) | |
tree | 2d1da31b5b88bd64af5a8ec4bd8be0d9c0efebe1 /src/Text/Pandoc | |
parent | c6338fa88340c76271934e90d96fa9ff606ae78a (diff) | |
download | pandoc-fef5770591e7d3a185dc8d7dc2b70594732b0367.tar.gz |
Fix regression with --metadata.
It should replace a metadata value set in the document
itself, rather than creating a list including a new value.
Closes #4054.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/App.hs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index d9924d3a1..b2394e142 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -76,7 +76,7 @@ import qualified System.IO as IO (Newline (..)) import System.IO.Error (isDoesNotExistError) import Text.Pandoc import Text.Pandoc.BCP47 (Lang (..), parseBCP47) -import Text.Pandoc.Builder (setMeta) +import Text.Pandoc.Builder (setMeta, deleteMeta) import Text.Pandoc.Highlighting (highlightingStyles) import Text.Pandoc.Lua (LuaException (..), runLuaFilter) import Text.Pandoc.PDF (makePDF) @@ -494,7 +494,7 @@ convertWithOpts opts = do ( (if isJust (optExtractMedia opts) then fillMediaBag else return) - >=> return . flip (foldr addMetadata) metadata + >=> return . addMetadata metadata >=> applyLuaFilters datadir (optLuaFilters opts) format >=> maybe return extractMedia (optExtractMedia opts) >=> applyTransforms transforms @@ -722,8 +722,11 @@ defaultOpts = Opt , optStripComments = False } -addMetadata :: (String, String) -> Pandoc -> Pandoc -addMetadata (k, v) (Pandoc meta bs) = Pandoc meta' bs +addMetadata :: [(String, String)] -> Pandoc -> Pandoc +addMetadata kvs pdc = foldr addMeta (removeMetaKeys kvs pdc) kvs + +addMeta :: (String, String) -> Pandoc -> Pandoc +addMeta (k, v) (Pandoc meta bs) = Pandoc meta' bs where meta' = case lookupMeta k meta of Nothing -> setMeta k v' meta Just (MetaList xs) -> @@ -731,6 +734,9 @@ addMetadata (k, v) (Pandoc meta bs) = Pandoc meta' bs Just x -> setMeta k (MetaList [x, v']) meta v' = readMetaValue v +removeMetaKeys :: [(String,String)] -> Pandoc -> Pandoc +removeMetaKeys kvs pdc = foldr (deleteMeta . fst) pdc kvs + readMetaValue :: String -> MetaValue readMetaValue s = case decode (UTF8.fromString s) of Just (Yaml.String t) -> MetaString $ T.unpack t |