git.iko.soy/typeable/pandoc
on master help sign in
Metadata changes: Variables now completely shadow metadata.
a1f010dJohn MacFarlane
src/Text/Pandoc/Shared.hs+9−2
@@ -526,13 +526,20 @@ makeMeta title authors date =
526-- | Create JSON value for template from a 'Meta' and an association list
526-- | Create JSON value for template from a 'Meta' and an association list
527-- of variables, specified at the command line or in the writer.
527-- of variables, specified at the command line or in the writer.
528-- Variables overwrite metadata fields with the same names.
528-- Variables overwrite metadata fields with the same names.
529+-- If multiple variables are set with the same name, a list is
530+-- assigned.
529metaToJSON :: Monad m
531metaToJSON :: Monad m
530 => ([Block] -> m String) -- ^ Writer for output format
532 => ([Block] -> m String) -- ^ Writer for output format
531 -> ([Inline] -> m String) -- ^ Writer for output format
533 -> ([Inline] -> m String) -- ^ Writer for output format
534+ -> [(String, String)] -- ^ Variables
532 -> Meta -- ^ Metadata
535 -> Meta -- ^ Metadata
533 -> m Value
536 -> m Value
534−metaToJSON blockWriter inlineWriter (Meta metamap) = liftM toJSON $
537+metaToJSON blockWriter inlineWriter vars (Meta metamap) = do
538+ let baseContext = foldl (\acc (x,y) -> setField x y acc) (Object H.empty) vars
535− Traversable.mapM (metaValueToJSON blockWriter inlineWriter) metamap
539+ renderedMap <- Traversable.mapM (metaValueToJSON blockWriter inlineWriter)
540+ metamap
541+ return $ M.foldWithKey (\key val obj -> defField key val obj)
542+ baseContext renderedMap
536
543
537metaValueToJSON :: Monad m
544metaValueToJSON :: Monad m
538 => ([Block] -> m String)
545 => ([Block] -> m String)
src/Text/Pandoc/Writers/AsciiDoc.hs+2−2
@@ -74,6 +74,7 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do
74 metadata <- metaToJSON
74 metadata <- metaToJSON
75 (fmap (render colwidth) . blockListToAsciiDoc opts)
75 (fmap (render colwidth) . blockListToAsciiDoc opts)
76 (fmap (render colwidth) . inlineListToAsciiDoc opts)
76 (fmap (render colwidth) . inlineListToAsciiDoc opts)
77+ (writerVariables opts)
77 meta
78 meta
78 let addTitleLine (String t) = String $
79 let addTitleLine (String t) = String $
79 t <> "\n" <> T.replicate (T.length t) "="
80 t <> "\n" <> T.replicate (T.length t) "="
@@ -88,8 +89,7 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do
88 $ defField "toc"
89 $ defField "toc"
89 (writerTableOfContents opts && writerStandalone opts)
90 (writerTableOfContents opts && writerStandalone opts)
90 $ defField "titleblock" titleblock
91 $ defField "titleblock" titleblock
91− $ foldl (\acc (x,y) -> setField x y acc)
92− metadata' (writerVariables opts)
92+ $ metadata'
93 if writerStandalone opts
93 if writerStandalone opts
94 then return $ renderTemplate' (writerTemplate opts) context
94 then return $ renderTemplate' (writerTemplate opts) context
95 else return main
95 else return main
src/Text/Pandoc/Writers/ConTeXt.hs+2−2
@@ -66,6 +66,7 @@ pandocToConTeXt options (Pandoc meta blocks) = do
66 metadata <- metaToJSON
66 metadata <- metaToJSON
67 (fmap (render colwidth) . blockListToConTeXt)
67 (fmap (render colwidth) . blockListToConTeXt)
68 (fmap (render colwidth) . inlineListToConTeXt)
68 (fmap (render colwidth) . inlineListToConTeXt)
69+ (writerVariables options)
69 meta
70 meta
70 body <- mapM (elementToConTeXt options) $ hierarchicalize blocks
71 body <- mapM (elementToConTeXt options) $ hierarchicalize blocks
71 let main = (render colwidth . vcat) body
72 let main = (render colwidth . vcat) body
@@ -81,8 +82,7 @@ pandocToConTeXt options (Pandoc meta blocks) = do
81 $ defField "mainlang" (maybe ""
82 $ defField "mainlang" (maybe ""
82 (reverse . takeWhile (/=',') . reverse)
83 (reverse . takeWhile (/=',') . reverse)
83 (lookup "lang" $ writerVariables options))
84 (lookup "lang" $ writerVariables options))
84− $ foldl (\acc (x,y) -> setField x y acc)
85− metadata (writerVariables options)
85+ $ metadata
86 return $ if writerStandalone options
86 return $ if writerStandalone options
87 then renderTemplate' (writerTemplate options) context
87 then renderTemplate' (writerTemplate options) context
88 else main
88 else main
src/Text/Pandoc/Writers/Docbook.hs+2−2
@@ -85,14 +85,14 @@ writeDocbook opts (Pandoc meta blocks) =
85 Just metadata = metaToJSON
85 Just metadata = metaToJSON
86 (Just . render colwidth . blocksToDocbook opts)
86 (Just . render colwidth . blocksToDocbook opts)
87 (Just . render colwidth . inlinesToDocbook opts)
87 (Just . render colwidth . inlinesToDocbook opts)
88+ (writerVariables opts)
88 meta'
89 meta'
89 main = render' $ vcat (map (elementToDocbook opts' startLvl) elements)
90 main = render' $ vcat (map (elementToDocbook opts' startLvl) elements)
90 context = defField "body" main
91 context = defField "body" main
91 $ defField "mathml" (case writerHTMLMathMethod opts of
92 $ defField "mathml" (case writerHTMLMathMethod opts of
92 MathML _ -> True
93 MathML _ -> True
93 _ -> False)
94 _ -> False)
94− $ foldl (\acc (x,y) -> setField x y acc)
95− metadata (writerVariables opts)
95+ $ metadata
96 in if writerStandalone opts
96 in if writerStandalone opts
97 then renderTemplate' (writerTemplate opts) context
97 then renderTemplate' (writerTemplate opts) context
98 else main
98 else main
src/Text/Pandoc/Writers/HTML.hs+2−2
@@ -113,6 +113,7 @@ pandocToHtml opts (Pandoc meta blocks) = do
113 metadata <- metaToJSON
113 metadata <- metaToJSON
114 (fmap renderHtml . blockListToHtml opts)
114 (fmap renderHtml . blockListToHtml opts)
115 (fmap renderHtml . inlineListToHtml opts)
115 (fmap renderHtml . inlineListToHtml opts)
116+ (writerVariables opts)
116 meta
117 meta
117 let authsMeta = map stringify $ docAuthors meta
118 let authsMeta = map stringify $ docAuthors meta
118 let dateMeta = stringify $ docDate meta
119 let dateMeta = stringify $ docDate meta
@@ -175,8 +176,7 @@ pandocToHtml opts (Pandoc meta blocks) = do
175 defField "revealjs-url" ("reveal.js" :: String) $
176 defField "revealjs-url" ("reveal.js" :: String) $
176 defField "s5-url" ("s5/default" :: String) $
177 defField "s5-url" ("s5/default" :: String) $
177 defField "html5" (writerHtml5 opts) $
178 defField "html5" (writerHtml5 opts) $
178− foldl (\acc (x,y) -> setField x y acc)
179− metadata (writerVariables opts)
179+ metadata
180 return (thebody, context)
180 return (thebody, context)
181
181
182inTemplate :: TemplateTarget a
182inTemplate :: TemplateTarget a
src/Text/Pandoc/Writers/LaTeX.hs+2−2
@@ -106,6 +106,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
106 metadata <- metaToJSON
106 metadata <- metaToJSON
107 (fmap (render colwidth) . blockListToLaTeX)
107 (fmap (render colwidth) . blockListToLaTeX)
108 (fmap (render colwidth) . inlineListToLaTeX)
108 (fmap (render colwidth) . inlineListToLaTeX)
109+ (writerVariables options)
109 meta
110 meta
110 let (blocks', lastHeader) = if writerCiteMethod options == Citeproc then
111 let (blocks', lastHeader) = if writerCiteMethod options == Citeproc then
111 (blocks, [])
112 (blocks, [])
@@ -158,8 +159,7 @@ pandocToLaTeX options (Pandoc meta blocks) = do
158 defField "biblio-title" biblioTitle .
159 defField "biblio-title" biblioTitle .
159 defField "biblatex" True
160 defField "biblatex" True
160 _ -> id) $
161 _ -> id) $
161− foldl (\acc (x,y) -> setField x y acc)
162− metadata (writerVariables options)
162+ metadata
163 return $ if writerStandalone options
163 return $ if writerStandalone options
164 then renderTemplate' template context
164 then renderTemplate' template context
165 else main
165 else main
src/Text/Pandoc/Writers/Man.hs+2−2
@@ -74,6 +74,7 @@ pandocToMan opts (Pandoc meta blocks) = do
74 metadata <- metaToJSON
74 metadata <- metaToJSON
75 (fmap (render colwidth) . blockListToMan opts)
75 (fmap (render colwidth) . blockListToMan opts)
76 (fmap (render colwidth) . inlineListToMan opts)
76 (fmap (render colwidth) . inlineListToMan opts)
77+ (writerVariables opts)
77 $ deleteMeta "title" meta
78 $ deleteMeta "title" meta
78 body <- blockListToMan opts blocks
79 body <- blockListToMan opts blocks
79 notes <- liftM stNotes get
80 notes <- liftM stNotes get
@@ -83,8 +84,7 @@ pandocToMan opts (Pandoc meta blocks) = do
83 let context = defField "body" main
84 let context = defField "body" main
84 $ setFieldsFromTitle
85 $ setFieldsFromTitle
85 $ defField "has-tables" hasTables
86 $ defField "has-tables" hasTables
86− $ foldl (\acc (x,y) -> setField x y acc)
87− metadata (writerVariables opts)
87+ $ metadata
88 if writerStandalone opts
88 if writerStandalone opts
89 then return $ renderTemplate' (writerTemplate opts) context
89 then return $ renderTemplate' (writerTemplate opts) context
90 else return main
90 else return main
src/Text/Pandoc/Writers/Markdown.hs+2−2
@@ -134,6 +134,7 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
134 metadata <- metaToJSON
134 metadata <- metaToJSON
135 (fmap (render colwidth) . blockListToMarkdown opts)
135 (fmap (render colwidth) . blockListToMarkdown opts)
136 (fmap (render colwidth) . inlineListToMarkdown opts)
136 (fmap (render colwidth) . inlineListToMarkdown opts)
137+ (writerVariables opts)
137 meta
138 meta
138 body <- blockListToMarkdown opts blocks
139 body <- blockListToMarkdown opts blocks
139 st <- get
140 st <- get
@@ -151,8 +152,7 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
151 && null (docDate meta))
152 && null (docDate meta))
152 then defField "titleblock" (render' titleblock)
153 then defField "titleblock" (render' titleblock)
153 else id)
154 else id)
154− $ foldl (\acc (x,y) -> setField x y acc)
155− metadata (writerVariables opts)
155+ $ metadata
156 if writerStandalone opts
156 if writerStandalone opts
157 then return $ renderTemplate' (writerTemplate opts) context
157 then return $ renderTemplate' (writerTemplate opts) context
158 else return main
158 else return main
src/Text/Pandoc/Writers/MediaWiki.hs+2−2
@@ -57,6 +57,7 @@ pandocToMediaWiki opts (Pandoc meta blocks) = do
57 metadata <- metaToJSON
57 metadata <- metaToJSON
58 (fmap trimr . blockListToMediaWiki opts)
58 (fmap trimr . blockListToMediaWiki opts)
59 (inlineListToMediaWiki opts)
59 (inlineListToMediaWiki opts)
60+ (writerVariables opts)
60 meta
61 meta
61 body <- blockListToMediaWiki opts blocks
62 body <- blockListToMediaWiki opts blocks
62 notesExist <- get >>= return . stNotes
63 notesExist <- get >>= return . stNotes
@@ -66,8 +67,7 @@ pandocToMediaWiki opts (Pandoc meta blocks) = do
66 let main = body ++ notes
67 let main = body ++ notes
67 let context = defField "body" main
68 let context = defField "body" main
68 $ defField "toc" (writerTableOfContents opts)
69 $ defField "toc" (writerTableOfContents opts)
69− $ foldl (\acc (x,y) -> setField x y acc)
70− metadata (writerVariables opts)
70+ $ metadata
71 if writerStandalone opts
71 if writerStandalone opts
72 then return $ renderTemplate' (writerTemplate opts) context
72 then return $ renderTemplate' (writerTemplate opts) context
73 else return main
73 else return main
src/Text/Pandoc/Writers/OPML.hs+2−3
@@ -52,11 +52,10 @@ writeOPML opts (Pandoc meta blocks) =
52 (Just . writeMarkdown def . Pandoc nullMeta)
52 (Just . writeMarkdown def . Pandoc nullMeta)
53 (Just . trimr . writeMarkdown def . Pandoc nullMeta .
53 (Just . trimr . writeMarkdown def . Pandoc nullMeta .
54 (\ils -> [Plain ils]))
54 (\ils -> [Plain ils]))
55+ (writerVariables opts)
55 meta'
56 meta'
56 main = render colwidth $ vcat (map (elementToOPML opts) elements)
57 main = render colwidth $ vcat (map (elementToOPML opts) elements)
57− context = defField "body" main
58+ context = defField "body" main metadata
58− $ foldl (\acc (x,y) -> setField x y acc)
59− metadata (writerVariables opts)
60 in if writerStandalone opts
59 in if writerStandalone opts
61 then renderTemplate' (writerTemplate opts) context
60 then renderTemplate' (writerTemplate opts) context
62 else main
61 else main
src/Text/Pandoc/Writers/OpenDocument.hs+3−3
@@ -42,7 +42,7 @@ import Control.Arrow ( (***), (>>>) )
42import Control.Monad.State hiding ( when )
42import Control.Monad.State hiding ( when )
43import Data.Char (chr, isDigit)
43import Data.Char (chr, isDigit)
44import qualified Data.Map as Map
44import qualified Data.Map as Map
45−import Text.Pandoc.Shared (metaToJSON, defField, setField)
45+import Text.Pandoc.Shared (metaToJSON, defField)
46
46
47-- | Auxiliary function to convert Plain block to Para.
47-- | Auxiliary function to convert Plain block to Para.
48plainToPara :: Block -> Block
48plainToPara :: Block -> Block
@@ -183,6 +183,7 @@ writeOpenDocument opts (Pandoc meta blocks) =
183 m <- metaToJSON
183 m <- metaToJSON
184 (fmap (render colwidth) . blocksToOpenDocument opts)
184 (fmap (render colwidth) . blocksToOpenDocument opts)
185 (fmap (render colwidth) . inlinesToOpenDocument opts)
185 (fmap (render colwidth) . inlinesToOpenDocument opts)
186+ (writerVariables opts)
186 meta
187 meta
187 b <- render' `fmap` blocksToOpenDocument opts blocks
188 b <- render' `fmap` blocksToOpenDocument opts blocks
188 return (b, m)
189 return (b, m)
@@ -194,8 +195,7 @@ writeOpenDocument opts (Pandoc meta blocks) =
194 reverse $ styles ++ listStyles
195 reverse $ styles ++ listStyles
195 context = defField "body" body
196 context = defField "body" body
196 $ defField "automatic-styles" (render' automaticStyles)
197 $ defField "automatic-styles" (render' automaticStyles)
197− $ foldl (\acc (x,y) -> setField x y acc)
198− metadata (writerVariables opts)
198+ $ metadata
199 in if writerStandalone opts
199 in if writerStandalone opts
200 then renderTemplate' (writerTemplate opts) context
200 then renderTemplate' (writerTemplate opts) context
201 else body
201 else body
src/Text/Pandoc/Writers/Org.hs+2−2
@@ -66,6 +66,7 @@ pandocToOrg (Pandoc meta blocks) = do
66 metadata <- metaToJSON
66 metadata <- metaToJSON
67 (fmap (render colwidth) . blockListToOrg)
67 (fmap (render colwidth) . blockListToOrg)
68 (fmap (render colwidth) . inlineListToOrg)
68 (fmap (render colwidth) . inlineListToOrg)
69+ (writerVariables opts)
69 meta
70 meta
70 body <- blockListToOrg blocks
71 body <- blockListToOrg blocks
71 notes <- liftM (reverse . stNotes) get >>= notesToOrg
72 notes <- liftM (reverse . stNotes) get >>= notesToOrg
@@ -74,8 +75,7 @@ pandocToOrg (Pandoc meta blocks) = do
74 let main = render colwidth $ foldl ($+$) empty $ [body, notes]
75 let main = render colwidth $ foldl ($+$) empty $ [body, notes]
75 let context = defField "body" main
76 let context = defField "body" main
76 $ defField "math" hasMath
77 $ defField "math" hasMath
77− $ foldl (\acc (x,y) -> setField x y acc)
78− metadata (writerVariables opts)
78+ $ metadata
79 if writerStandalone opts
79 if writerStandalone opts
80 then return $ renderTemplate' (writerTemplate opts) context
80 then return $ renderTemplate' (writerTemplate opts) context
81 else return main
81 else return main
src/Text/Pandoc/Writers/RST.hs+2−2
@@ -74,6 +74,7 @@ pandocToRST (Pandoc meta blocks) = do
74 title <- titleToRST (docTitle meta) subtit
74 title <- titleToRST (docTitle meta) subtit
75 metadata <- metaToJSON (fmap (render colwidth) . blockListToRST)
75 metadata <- metaToJSON (fmap (render colwidth) . blockListToRST)
76 (fmap (trimr . render colwidth) . inlineListToRST)
76 (fmap (trimr . render colwidth) . inlineListToRST)
77+ (writerVariables opts)
77 $ deleteMeta "title" $ deleteMeta "subtitle" meta
78 $ deleteMeta "title" $ deleteMeta "subtitle" meta
78 body <- blockListToRST blocks
79 body <- blockListToRST blocks
79 notes <- liftM (reverse . stNotes) get >>= notesToRST
80 notes <- liftM (reverse . stNotes) get >>= notesToRST
@@ -88,8 +89,7 @@ pandocToRST (Pandoc meta blocks) = do
88 $ defField "math" hasMath
89 $ defField "math" hasMath
89 $ defField "title" (render Nothing title :: String)
90 $ defField "title" (render Nothing title :: String)
90 $ defField "math" hasMath
91 $ defField "math" hasMath
91− $ foldl (\acc (x,y) -> setField x y acc)
92− metadata (writerVariables opts)
92+ $ metadata
93 if writerStandalone opts
93 if writerStandalone opts
94 then return $ renderTemplate' (writerTemplate opts) context
94 then return $ renderTemplate' (writerTemplate opts) context
95 else return main
95 else return main
src/Text/Pandoc/Writers/RTF.hs+2−2
@@ -78,6 +78,7 @@ writeRTF options (Pandoc meta blocks) =
78 Just metadata = metaToJSON
78 Just metadata = metaToJSON
79 (Just . concatMap (blockToRTF 0 AlignDefault))
79 (Just . concatMap (blockToRTF 0 AlignDefault))
80 (Just . inlineListToRTF)
80 (Just . inlineListToRTF)
81+ (writerVariables options)
81 meta
82 meta
82 body = concatMap (blockToRTF 0 AlignDefault) blocks
83 body = concatMap (blockToRTF 0 AlignDefault) blocks
83 isTOCHeader (Header lev _ _) = lev <= writerTOCDepth options
84 isTOCHeader (Header lev _ _) = lev <= writerTOCDepth options
@@ -88,8 +89,7 @@ writeRTF options (Pandoc meta blocks) =
88 then defField "toc"
89 then defField "toc"
89 (tableOfContents $ filter isTOCHeader blocks)
90 (tableOfContents $ filter isTOCHeader blocks)
90 else id)
91 else id)
91− $ foldl (\acc (x,y) -> setField x y acc)
92− metadata (writerVariables options)
92+ $ metadata
93 in if writerStandalone options
93 in if writerStandalone options
94 then renderTemplate' (writerTemplate options) context
94 then renderTemplate' (writerTemplate options) context
95 else body
95 else body
src/Text/Pandoc/Writers/Texinfo.hs+2−3
@@ -76,7 +76,7 @@ pandocToTexinfo options (Pandoc meta blocks) = do
76 metadata <- metaToJSON
76 metadata <- metaToJSON
77 (fmap (render colwidth) . blockListToTexinfo)
77 (fmap (render colwidth) . blockListToTexinfo)
78 (fmap (render colwidth) . inlineListToTexinfo)
78 (fmap (render colwidth) . inlineListToTexinfo)
79− meta
79+ (writerVariables options) meta
80 main <- blockListToTexinfo blocks
80 main <- blockListToTexinfo blocks
81 st <- get
81 st <- get
82 let body = render colwidth main
82 let body = render colwidth main
@@ -86,8 +86,7 @@ pandocToTexinfo options (Pandoc meta blocks) = do
86 $ defField "subscript" (stSubscript st)
86 $ defField "subscript" (stSubscript st)
87 $ defField "superscript" (stSuperscript st)
87 $ defField "superscript" (stSuperscript st)
88 $ defField "strikeout" (stStrikeout st)
88 $ defField "strikeout" (stStrikeout st)
89− $ foldl (\acc (x,y) -> setField x y acc)
90− metadata (writerVariables options)
89+ $ metadata
91 if writerStandalone options
90 if writerStandalone options
92 then return $ renderTemplate' (writerTemplate options) context
91 then return $ renderTemplate' (writerTemplate options) context
93 else return body
92 else return body
src/Text/Pandoc/Writers/Textile.hs+3−4
@@ -55,13 +55,12 @@ writeTextile opts document =
55pandocToTextile :: WriterOptions -> Pandoc -> State WriterState String
55pandocToTextile :: WriterOptions -> Pandoc -> State WriterState String
56pandocToTextile opts (Pandoc meta blocks) = do
56pandocToTextile opts (Pandoc meta blocks) = do
57 metadata <- metaToJSON
57 metadata <- metaToJSON
58− (blockListToTextile opts) (inlineListToTextile opts) meta
58+ (blockListToTextile opts) (inlineListToTextile opts)
59+ (writerVariables opts) meta
59 body <- blockListToTextile opts blocks
60 body <- blockListToTextile opts blocks
60 notes <- liftM (unlines . reverse . stNotes) get
61 notes <- liftM (unlines . reverse . stNotes) get
61 let main = body ++ if null notes then "" else ("\n\n" ++ notes)
62 let main = body ++ if null notes then "" else ("\n\n" ++ notes)
62− let context = defField "body" main
63+ let context = defField "body" main metadata
63− $ foldl (\acc (x,y) -> setField x y acc)
64− metadata (writerVariables opts)
65 if writerStandalone opts
64 if writerStandalone opts
66 then return $ renderTemplate' (writerTemplate opts) context
65 then return $ renderTemplate' (writerTemplate opts) context
67 else return main
66 else return main