@@ -20,9 +20,6 @@ module Text.Pandoc.App.OutputSettings
2020 ) where
2121import Prelude
2222import qualified Control.Exception as E
23−import qualified Data.Text as T
24−import qualified Data.Map as M
25−import Text.DocTemplates (Context(..), ToContext(toVal))
2623import Control.Monad
2724import Control.Monad.Except (catchError, throwError)
2825import Control.Monad.Trans
@@ -38,7 +35,8 @@ import System.IO (stdout)
3835import Text.Pandoc
3936import Text.Pandoc.App.FormatHeuristics (formatFromFilePaths)
4037import Text.Pandoc.App.Opt (Opt (..))
41−import Text.Pandoc.App.CommandLineOptions (engines, lookupHighlightStyle)
38+import Text.Pandoc.App.CommandLineOptions (engines, lookupHighlightStyle,
39+ setVariable)
4240import Text.Pandoc.BCP47 (Lang (..), parseBCP47)
4341import qualified Text.Pandoc.UTF8 as UTF8
4442
@@ -97,8 +95,6 @@ optToOutputSettings opts = do
9795
9896 let standalone = optStandalone opts || not (isTextFormat format) || pdfOutput
9997
100− let addStringAsVariable varname s vars = return $ (varname, s) : vars
101−
10298 let addSyntaxMap existingmap f = do
10399 res <- liftIO (parseSyntaxDefinition f)
104100 case res of
@@ -117,21 +113,24 @@ optToOutputSettings opts = do
117113 let withList _ [] vars = return vars
118114 withList f (x:xs) vars = f x vars >>= withList f xs
119115
116+ let setVariableM k v = return . setVariable k v
117+
120118 let addContentsAsVariable varname fp vars = do
121119 s <- UTF8.toString . fst <$> fetchItem fp
122− return $ (varname, s) : vars
120+ setVariableM varname s vars
123121
124122 curdir <- liftIO getCurrentDirectory
125123
126124 variables <-
127− withList (addStringAsVariable "sourcefile")
128− (reverse $ optInputFiles opts)
129− (("outputfile", fromMaybe "-" (optOutputFile opts))
130− : optVariables opts)
125+ withList (setVariableM "sourcefile")
131126 -- we reverse this list because, unlike
132127 -- the other option lists here, it is
133128 -- not reversed when parsed from CLI arguments.
134129 -- See withList, above.
130+ (reverse $ optInputFiles opts)
131+ (optVariables opts)
132+ >>=
133+ setVariableM "outputfile" (fromMaybe "-" (optOutputFile opts))
135134 >>=
136135 withList (addContentsAsVariable "include-before")
137136 (optIncludeBeforeBody opts)
@@ -142,15 +141,15 @@ optToOutputSettings opts = do
142141 withList (addContentsAsVariable "header-includes")
143142 (optIncludeInHeader opts)
144143 >>=
145− withList (addStringAsVariable "css") (optCss opts)
144+ withList (setVariableM "css") (optCss opts)
146145 >>=
147− maybe return (addStringAsVariable "title-prefix")
146+ maybe return (setVariableM "title-prefix")
148147 (optTitlePrefix opts)
149148 >>=
150− maybe return (addStringAsVariable "epub-cover-image")
149+ maybe return (setVariableM "epub-cover-image")
151150 (optEpubCoverImage opts)
152151 >>=
153− addStringAsVariable "curdir" curdir
152+ setVariableM "curdir" curdir
154153 >>=
155154 (\vars -> if format == "dzslides"
156155 then do
@@ -160,10 +159,8 @@ optToOutputSettings opts = do
160159 let dzcore = unlines
161160 $ dropWhile (not . (dzline `isPrefixOf`))
162161 $ lines dztempl
163− return $ ("dzslides-core", dzcore) : vars
162+ setVariableM "dzslides-core" dzcore vars
164163 else return vars)
165− >>= fmap (Context . M.fromList) .
166− traverse (\(x,y) -> return (T.pack x, toVal (T.pack y)))
167164
168165 templStr <- case optTemplate opts of
169166 _ | not standalone -> return Nothing