git.iko.soy/typeable/pandoc
on master help sign in
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.

commita1f010de7830777b86f88743785560a04fab62fd authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 29 Jun 2013, 22:14 (13 years ago) parent5cb0f0b
16 files changed+41−37
src/Text/Pandoc/Shared.hs+9−2 src/Text/Pandoc/Writers/AsciiDoc.hs+2−2 src/Text/Pandoc/Writers/ConTeXt.hs+2−2 src/Text/Pandoc/Writers/Docbook.hs+2−2 src/Text/Pandoc/Writers/HTML.hs+2−2 src/Text/Pandoc/Writers/LaTeX.hs+2−2 src/Text/Pandoc/Writers/Man.hs+2−2 src/Text/Pandoc/Writers/Markdown.hs+2−2 src/Text/Pandoc/Writers/MediaWiki.hs+2−2 src/Text/Pandoc/Writers/OPML.hs+2−3 src/Text/Pandoc/Writers/OpenDocument.hs+3−3 src/Text/Pandoc/Writers/Org.hs+2−2 src/Text/Pandoc/Writers/RST.hs+2−2 src/Text/Pandoc/Writers/RTF.hs+2−2 src/Text/Pandoc/Writers/Texinfo.hs+2−3 src/Text/Pandoc/Writers/Textile.hs+3−4
src/Text/Pandoc/Shared.hs+9−2
@@ -526,13 +526,20 @@ makeMeta title authors date =
526526-- | Create JSON value for template from a 'Meta' and an association list
527527-- of variables, specified at the command line or in the writer.
528528-- Variables overwrite metadata fields with the same names.
529+-- If multiple variables are set with the same name, a list is
530+-- assigned.
529531metaToJSON :: Monad m
530532 => ([Block] -> m String) -- ^ Writer for output format
531533 -> ([Inline] -> m String) -- ^ Writer for output format
534+ -> [(String, String)] -- ^ Variables
532535 -> Meta -- ^ Metadata
533536 -> m Value
534−metaToJSON blockWriter inlineWriter (Meta metamap) = liftM toJSON $
535− Traversable.mapM (metaValueToJSON blockWriter inlineWriter) metamap
537+metaToJSON blockWriter inlineWriter vars (Meta metamap) = do
538+ let baseContext = foldl (\acc (x,y) -> setField x y acc) (Object H.empty) vars
539+ renderedMap <- Traversable.mapM (metaValueToJSON blockWriter inlineWriter)
540+ metamap
541+ return $ M.foldWithKey (\key val obj -> defField key val obj)
542+ baseContext renderedMap
536543
537544metaValueToJSON :: Monad m
538545 => ([Block] -> m String)
src/Text/Pandoc/Writers/AsciiDoc.hs+2−2
@@ -74,6 +74,7 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do
7474 metadata <- metaToJSON
7575 (fmap (render colwidth) . blockListToAsciiDoc opts)
7676 (fmap (render colwidth) . inlineListToAsciiDoc opts)
77+ (writerVariables opts)
7778 meta
7879 let addTitleLine (String t) = String $
7980 t <> "\n" <> T.replicate (T.length t) "="
@@ -88,8 +89,7 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do
8889 $ defField "toc"
8990 (writerTableOfContents opts && writerStandalone opts)
9091 $ defField "titleblock" titleblock
91− $ foldl (\acc (x,y) -> setField x y acc)
92− metadata' (writerVariables opts)
92+ $ metadata'
9393 if writerStandalone opts
9494 then return $ renderTemplate' (writerTemplate opts) context
9595 else return main
src/Text/Pandoc/Writers/ConTeXt.hs+2−2
@@ -66,6 +66,7 @@ pandocToConTeXt options (Pandoc meta blocks) = do
6666 metadata <- metaToJSON
6767 (fmap (render colwidth) . blockListToConTeXt)
6868 (fmap (render colwidth) . inlineListToConTeXt)
69+ (writerVariables options)
6970 meta
7071 body <- mapM (elementToConTeXt options) $ hierarchicalize blocks
7172 let main = (render colwidth . vcat) body
@@ -81,8 +82,7 @@ pandocToConTeXt options (Pandoc meta blocks) = do
8182 $ defField "mainlang" (maybe ""
8283 (reverse . takeWhile (/=',') . reverse)
8384 (lookup "lang" $ writerVariables options))
84− $ foldl (\acc (x,y) -> setField x y acc)
85− metadata (writerVariables options)
85+ $ metadata
8686 return $ if writerStandalone options
8787 then renderTemplate' (writerTemplate options) context
8888 else main
src/Text/Pandoc/Writers/Docbook.hs+2−2
@@ -85,14 +85,14 @@ writeDocbook opts (Pandoc meta blocks) =
8585 Just metadata = metaToJSON
8686 (Just . render colwidth . blocksToDocbook opts)
8787 (Just . render colwidth . inlinesToDocbook opts)
88+ (writerVariables opts)
8889 meta'
8990 main = render' $ vcat (map (elementToDocbook opts' startLvl) elements)
9091 context = defField "body" main
9192 $ defField "mathml" (case writerHTMLMathMethod opts of
9293 MathML _ -> True
9394 _ -> False)
94− $ foldl (\acc (x,y) -> setField x y acc)
95− metadata (writerVariables opts)
95+ $ metadata
9696 in if writerStandalone opts
9797 then renderTemplate' (writerTemplate opts) context
9898 else main
src/Text/Pandoc/Writers/HTML.hs+2−2
@@ -113,6 +113,7 @@ pandocToHtml opts (Pandoc meta blocks) = do
113113 metadata <- metaToJSON
114114 (fmap renderHtml . blockListToHtml opts)
115115 (fmap renderHtml . inlineListToHtml opts)
116+ (writerVariables opts)
116117 meta
117118 let authsMeta = map stringify $ docAuthors meta
118119 let dateMeta = stringify $ docDate meta
@@ -175,8 +176,7 @@ pandocToHtml opts (Pandoc meta blocks) = do
175176 defField "revealjs-url" ("reveal.js" :: String) $
176177 defField "s5-url" ("s5/default" :: String) $
177178 defField "html5" (writerHtml5 opts) $
178− foldl (\acc (x,y) -> setField x y acc)
179− metadata (writerVariables opts)
179+ metadata
180180 return (thebody, context)
181181
182182inTemplate :: TemplateTarget a
src/Text/Pandoc/Writers/LaTeX.hs+2−2
@@ -106,6 +106,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
106106 metadata <- metaToJSON
107107 (fmap (render colwidth) . blockListToLaTeX)
108108 (fmap (render colwidth) . inlineListToLaTeX)
109+ (writerVariables options)
109110 meta
110111 let (blocks', lastHeader) = if writerCiteMethod options == Citeproc then
111112 (blocks, [])
@@ -158,8 +159,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
158159 defField "biblio-title" biblioTitle .
159160 defField "biblatex" True
160161 _ -> id) $
161− foldl (\acc (x,y) -> setField x y acc)
162− metadata (writerVariables options)
162+ metadata
163163 return $ if writerStandalone options
164164 then renderTemplate' template context
165165 else main
src/Text/Pandoc/Writers/Man.hs+2−2
@@ -74,6 +74,7 @@ pandocToMan opts (Pandoc meta blocks) = do
7474 metadata <- metaToJSON
7575 (fmap (render colwidth) . blockListToMan opts)
7676 (fmap (render colwidth) . inlineListToMan opts)
77+ (writerVariables opts)
7778 $ deleteMeta "title" meta
7879 body <- blockListToMan opts blocks
7980 notes <- liftM stNotes get
@@ -83,8 +84,7 @@ pandocToMan opts (Pandoc meta blocks) = do
8384 let context = defField "body" main
8485 $ setFieldsFromTitle
8586 $ defField "has-tables" hasTables
86− $ foldl (\acc (x,y) -> setField x y acc)
87− metadata (writerVariables opts)
87+ $ metadata
8888 if writerStandalone opts
8989 then return $ renderTemplate' (writerTemplate opts) context
9090 else return main
src/Text/Pandoc/Writers/Markdown.hs+2−2
@@ -134,6 +134,7 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
134134 metadata <- metaToJSON
135135 (fmap (render colwidth) . blockListToMarkdown opts)
136136 (fmap (render colwidth) . inlineListToMarkdown opts)
137+ (writerVariables opts)
137138 meta
138139 body <- blockListToMarkdown opts blocks
139140 st <- get
@@ -151,8 +152,7 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
151152 && null (docDate meta))
152153 then defField "titleblock" (render' titleblock)
153154 else id)
154− $ foldl (\acc (x,y) -> setField x y acc)
155− metadata (writerVariables opts)
155+ $ metadata
156156 if writerStandalone opts
157157 then return $ renderTemplate' (writerTemplate opts) context
158158 else return main
src/Text/Pandoc/Writers/MediaWiki.hs+2−2
@@ -57,6 +57,7 @@ pandocToMediaWiki opts (Pandoc meta blocks) = do
5757 metadata <- metaToJSON
5858 (fmap trimr . blockListToMediaWiki opts)
5959 (inlineListToMediaWiki opts)
60+ (writerVariables opts)
6061 meta
6162 body <- blockListToMediaWiki opts blocks
6263 notesExist <- get >>= return . stNotes
@@ -66,8 +67,7 @@ pandocToMediaWiki opts (Pandoc meta blocks) = do
6667 let main = body ++ notes
6768 let context = defField "body" main
6869 $ defField "toc" (writerTableOfContents opts)
69− $ foldl (\acc (x,y) -> setField x y acc)
70− metadata (writerVariables opts)
70+ $ metadata
7171 if writerStandalone opts
7272 then return $ renderTemplate' (writerTemplate opts) context
7373 else return main
src/Text/Pandoc/Writers/OPML.hs+2−3
@@ -52,11 +52,10 @@ writeOPML opts (Pandoc meta blocks) =
5252 (Just . writeMarkdown def . Pandoc nullMeta)
5353 (Just . trimr . writeMarkdown def . Pandoc nullMeta .
5454 (\ils -> [Plain ils]))
55+ (writerVariables opts)
5556 meta'
5657 main = render colwidth $ vcat (map (elementToOPML opts) elements)
57− context = defField "body" main
58− $ foldl (\acc (x,y) -> setField x y acc)
59− metadata (writerVariables opts)
58+ context = defField "body" main metadata
6059 in if writerStandalone opts
6160 then renderTemplate' (writerTemplate opts) context
6261 else main
src/Text/Pandoc/Writers/OpenDocument.hs+3−3
@@ -42,7 +42,7 @@ import Control.Arrow ( (***), (>>>) )
4242import Control.Monad.State hiding ( when )
4343import Data.Char (chr, isDigit)
4444import qualified Data.Map as Map
45−import Text.Pandoc.Shared (metaToJSON, defField, setField)
45+import Text.Pandoc.Shared (metaToJSON, defField)
4646
4747-- | Auxiliary function to convert Plain block to Para.
4848plainToPara :: Block -> Block
@@ -183,6 +183,7 @@ writeOpenDocument opts (Pandoc meta blocks) =
183183 m <- metaToJSON
184184 (fmap (render colwidth) . blocksToOpenDocument opts)
185185 (fmap (render colwidth) . inlinesToOpenDocument opts)
186+ (writerVariables opts)
186187 meta
187188 b <- render' `fmap` blocksToOpenDocument opts blocks
188189 return (b, m)
@@ -194,8 +195,7 @@ writeOpenDocument opts (Pandoc meta blocks) =
194195 reverse $ styles ++ listStyles
195196 context = defField "body" body
196197 $ defField "automatic-styles" (render' automaticStyles)
197− $ foldl (\acc (x,y) -> setField x y acc)
198− metadata (writerVariables opts)
198+ $ metadata
199199 in if writerStandalone opts
200200 then renderTemplate' (writerTemplate opts) context
201201 else body
src/Text/Pandoc/Writers/Org.hs+2−2
@@ -66,6 +66,7 @@ pandocToOrg (Pandoc meta blocks) = do
6666 metadata <- metaToJSON
6767 (fmap (render colwidth) . blockListToOrg)
6868 (fmap (render colwidth) . inlineListToOrg)
69+ (writerVariables opts)
6970 meta
7071 body <- blockListToOrg blocks
7172 notes <- liftM (reverse . stNotes) get >>= notesToOrg
@@ -74,8 +75,7 @@ pandocToOrg (Pandoc meta blocks) = do
7475 let main = render colwidth $ foldl ($+$) empty $ [body, notes]
7576 let context = defField "body" main
7677 $ defField "math" hasMath
77− $ foldl (\acc (x,y) -> setField x y acc)
78− metadata (writerVariables opts)
78+ $ metadata
7979 if writerStandalone opts
8080 then return $ renderTemplate' (writerTemplate opts) context
8181 else return main
src/Text/Pandoc/Writers/RST.hs+2−2
@@ -74,6 +74,7 @@ pandocToRST (Pandoc meta blocks) = do
7474 title <- titleToRST (docTitle meta) subtit
7575 metadata <- metaToJSON (fmap (render colwidth) . blockListToRST)
7676 (fmap (trimr . render colwidth) . inlineListToRST)
77+ (writerVariables opts)
7778 $ deleteMeta "title" $ deleteMeta "subtitle" meta
7879 body <- blockListToRST blocks
7980 notes <- liftM (reverse . stNotes) get >>= notesToRST
@@ -88,8 +89,7 @@ pandocToRST (Pandoc meta blocks) = do
8889 $ defField "math" hasMath
8990 $ defField "title" (render Nothing title :: String)
9091 $ defField "math" hasMath
91− $ foldl (\acc (x,y) -> setField x y acc)
92− metadata (writerVariables opts)
92+ $ metadata
9393 if writerStandalone opts
9494 then return $ renderTemplate' (writerTemplate opts) context
9595 else return main
src/Text/Pandoc/Writers/RTF.hs+2−2
@@ -78,6 +78,7 @@ writeRTF options (Pandoc meta blocks) =
7878 Just metadata = metaToJSON
7979 (Just . concatMap (blockToRTF 0 AlignDefault))
8080 (Just . inlineListToRTF)
81+ (writerVariables options)
8182 meta
8283 body = concatMap (blockToRTF 0 AlignDefault) blocks
8384 isTOCHeader (Header lev _ _) = lev <= writerTOCDepth options
@@ -88,8 +89,7 @@ writeRTF options (Pandoc meta blocks) =
8889 then defField "toc"
8990 (tableOfContents $ filter isTOCHeader blocks)
9091 else id)
91− $ foldl (\acc (x,y) -> setField x y acc)
92− metadata (writerVariables options)
92+ $ metadata
9393 in if writerStandalone options
9494 then renderTemplate' (writerTemplate options) context
9595 else body
src/Text/Pandoc/Writers/Texinfo.hs+2−3
@@ -76,7 +76,7 @@ pandocToTexinfo options (Pandoc meta blocks) = do
7676 metadata <- metaToJSON
7777 (fmap (render colwidth) . blockListToTexinfo)
7878 (fmap (render colwidth) . inlineListToTexinfo)
79− meta
79+ (writerVariables options) meta
8080 main <- blockListToTexinfo blocks
8181 st <- get
8282 let body = render colwidth main
@@ -86,8 +86,7 @@ pandocToTexinfo options (Pandoc meta blocks) = do
8686 $ defField "subscript" (stSubscript st)
8787 $ defField "superscript" (stSuperscript st)
8888 $ defField "strikeout" (stStrikeout st)
89− $ foldl (\acc (x,y) -> setField x y acc)
90− metadata (writerVariables options)
89+ $ metadata
9190 if writerStandalone options
9291 then return $ renderTemplate' (writerTemplate options) context
9392 else return body
src/Text/Pandoc/Writers/Textile.hs+3−4
@@ -55,13 +55,12 @@ writeTextile opts document =
5555pandocToTextile :: WriterOptions -> Pandoc -> State WriterState String
5656pandocToTextile opts (Pandoc meta blocks) = do
5757 metadata <- metaToJSON
58− (blockListToTextile opts) (inlineListToTextile opts) meta
58+ (blockListToTextile opts) (inlineListToTextile opts)
59+ (writerVariables opts) meta
5960 body <- blockListToTextile opts blocks
6061 notes <- liftM (unlines . reverse . stNotes) get
6162 let main = body ++ if null notes then "" else ("\n\n" ++ notes)
62− let context = defField "body" main
63− $ foldl (\acc (x,y) -> setField x y acc)
64− metadata (writerVariables opts)
63+ let context = defField "body" main metadata
6564 if writerStandalone opts
6665 then return $ renderTemplate' (writerTemplate opts) context
6766 else return main