summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Shared.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-06-29 22:14:01 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-06-29 22:14:01 -0700
commita1f010de7830777b86f88743785560a04fab62fd (patch)
tree1ab1d0cb2045ec51e890c9e1a636b888334a7391 /src/Text/Pandoc/Shared.hs
parent5cb0f0bbf1da61b7ce276a39055a51b6166500cc (diff)
Metadata changes: Variables now completely shadow metadata.
Previously if you set a value both in metadata and with a variable, they'd be combined into a list. Now the variable replaces the value in document metadata. If many variables with the same name are set, a list is created. Shared: metaToJSON now has an argument for a variable list.
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r--src/Text/Pandoc/Shared.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index d6663f193..9ee6b0f15 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -526,13 +526,20 @@ makeMeta title authors date =
-- | Create JSON value for template from a 'Meta' and an association list
-- of variables, specified at the command line or in the writer.
-- Variables overwrite metadata fields with the same names.
+-- If multiple variables are set with the same name, a list is
+-- assigned.
metaToJSON :: Monad m
=> ([Block] -> m String) -- ^ Writer for output format
-> ([Inline] -> m String) -- ^ Writer for output format
+ -> [(String, String)] -- ^ Variables
-> Meta -- ^ Metadata
-> m Value
-metaToJSON blockWriter inlineWriter (Meta metamap) = liftM toJSON $
- Traversable.mapM (metaValueToJSON blockWriter inlineWriter) metamap
+metaToJSON blockWriter inlineWriter vars (Meta metamap) = do
+ let baseContext = foldl (\acc (x,y) -> setField x y acc) (Object H.empty) vars
+ renderedMap <- Traversable.mapM (metaValueToJSON blockWriter inlineWriter)
+ metamap
+ return $ M.foldWithKey (\key val obj -> defField key val obj)
+ baseContext renderedMap
metaValueToJSON :: Monad m
=> ([Block] -> m String)